VideoView SeekTo working smoothly or delay on different devices - Android - android

I'm developing a function that I click next button then the pause video will seekto next part and start.For example when video.getCurrentPosition is 8000, I click button to make video seekto(10000),because the video show same content between 8000 and 10000.
This function on some android devices runs smoothly,such as Samsung s6 edge,OnePlus,Xiaomi,Smartison...
But the issue is that on some devices,such as Huawei,Moto Nexus 6,
when video on 8000 and I click the button,it has some "delay time".It looks like about 1sec. later,the video finally starts.
By contrast,I specially change the seekto(10200),which is wrong parameter,and these "problem devices" runs smoothly likes "normal devices".However,the video on previous "normal devices" skip some frame and start at 10200.
Is anyone know why cause this issue?Hope your answer,thank you.

Was the video encoded using h264? Re-encoding as using the mpeg4 codec, as suggested in a comment to this SO question, has resolved for me a problem of very odd seekTo behaviour by an Android ViewView.
To check the encoding, and to re-encode, you might be able to use ffmpeg.
$ ffprobe <inputfile>
...
...
Stream #0:0(eng): Video: h264 ...
...
That showed the the file is encoded using h264, which is more recent and generally produces better quality for the same bitrate as mpeg4, but is (presumably as a consequence) harder to seek through, at least for the Android VideoView.
To encode as mpeg4 the following worked for me, but the ffmpeg wiki has more detail.
$ ffmpeg -i <inputfile> -c:v libxvid <outputfile>

Related

How to re-encode a 120fps (or higher) MP4 from my Samsung Galaxy to a 30fps (example) so it plays on Windows like it does on the Samsung

I have some high fps slow-motion videos (mp4) that I've recorded on my phone, but when I copy them to windows and play them back, they play at the normal speed (or they play really fast), unless I slow down playback but this isn't a good result.
What I'd like to do is re-encode (if that's the right word) the video to a standard fps (such as 30) to get a longer video (keeping all the frames), i.e. a 10 second 120fps would end up being a 40 second video at 30fps.
Try using -r such as:
ffmpeg -y -r 30 -i inputSlowMotion.mp4 outputSlowMotion.mp4

FFmpeg mp4 encoder for html-android

Hello I'm trying to put video .mp4 auto-captured by my webcam using ffmpeg into HTML (running ffmpeg in desktop-linux), and then activated my localhost so my android will able to see it.
the video.mp4 was able to run in linux, and in html-desktop.
the video in my android-browser(html-android) WAS ABLE to play too BUT it's all white and pixels error, so it's a fail.
I thought because android has difference surface because in my desktop it runs perfectly, then i keep searching and trying with ogv/webm.
In the end, I just use a downloaded another mp4 and it runs perfectly tho.
now I think the problem was coming from my mp4-webcam created by ffmpeg(run in cmd)
I compare a mp4-webcam vs mp4-downloaded
5sec vs 1min,
Data-rate: 16477kbps vs 613kbps
framerate: 30frm/s vs 23frm/s
size: 9MB vs 5 MB
even tho it's only 5sec video by webcam, it still has larger data than a 1min video-downloaded maybe it was because without conversion.
but the question, is that the reason of the problem ? android-html(google chrome) wasn't able to display and make a dead pixels since in desktop it runs. it shouldn't be the problem right ?
I really need to transfer webcam-record into android-surface (my web-app).
I have no idea to fix it, any advice ? I've been searching a lot. Maybe there was another problem I do not know yet.
EDIT: my cmd ffmpeg run : ffmpeg -y -f v4l2 -i /dev/video1 -codec:v libx264 -qp 0 -t 0:00:05 hss.mp4
EDIT 2: my 2nd thought because ffmpeg encoder that I used(libx264) isnot support for android. but i still no idea
I just converted mp4-ffmpeg to webm , webm is more friendly for video-browser

MediaController / VideoView can't play mp4 on certain phones

From within my app I create a video from images that the user has taken using Ffmpeg. I the play this using MediaController and a VideoView. When I run the app using the Genymotion emulator for a Google Nexus 4 the video file plays without issue. When I use the Genymotion emulator for a Samsung Galaxy S4 I get an error from the VideoView on error listener say "Can't play video".
Thanks for your help.
Converting the video using ffmpeg worked fine for my application. I hope this helps:
ffmpeg -i old.mp4 -c:v libx264 -profile:v baseline -level 1 -strict -2 new.mp4
I found this line of code somewhere else on Stack Overflow but I could not retrace where, unfortunately. So, in case someone comes across it, please link it here. The original one did not have the -strict -2 in the command.
Simply because the extension is .mp4 cannot guarantee it will be played by the MediaPlayer. If its not a supported encoding it wont play it. Please do have a look at all the supported media formats in Android here.
So introspect your code and find the type of encoding your video uses. Also if you are looking more an even powerful way to play video, you can also try out Google's Exoplayer, here.

AudioTrack playing with inconsistent speed on different devices

I am currently working with AudioTrack. I am loading an mp3 file and playing it. However, depending on devices, the music plays either at half the rate or normal rate.
My code:
AudioTrack track= new AudioTrack( AudioManager.STREAM_MUSIC,
sampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
initBuffer,
AudioTrack.MODE_STREAM);
sampleRate is the sample rate return by AudioFormat and initBuffer the buffer size from AudioTrack.getMinBufferSize().
I have tried to change the sample rate but no difference. Buffer size also has no impact.
In fact, switching to CHANNEL_CONFIGURATION_STEREO does make the music play at normal rate on the devices that were slow, but it also makes the ones working fine playing at twice the normal speed. My problem is that I want all devices to play at the normal speed.
Any suggestions?
I have read this thread:Android AudioTrack slow playback, but it doesn't tell me how to find out which devices should play in mono or stereo.
Devices at normal speed: Urbano 4.2.2, Galaxy S4 4.3
Devices at half the speed, Galaxy S4 4.2.2, Experia Z 4.2.2
BTW, I cannot use MediaPlayer for playback. The AudioTrack is included in a custom player and I need to write audio data as I extract it. MediaPlayer won't do the trick.
Thanks.
I experienced it when trying to decode mono file using MediaCodec. On some devices,the codec would output stereo stream while mono on other. When setting up the audio track I used media format returned by MediaExtractor, which was mono. On devices where the codec would produce stereo stream, the audio track would be fed with twice as many samples. The solution is to listen for MediaFormatChanged event from MediaCodec and adjust the MediaFormat of the AudioTrack.
AudioTrack only allows PCM audio data, you cannot play mp3 wit AudioTrack directly, you have to convert your mp3 to PCM or use something else (e.g. MediaPlayer) than AudioTrack.
I finally solved my problem. Not the best fix but it works at least.
For those who are interested, I am reading the BufferInfo size and based on it, decide at which playback rate I should play. Basically when playback is slow the size is twice bigger than for normal speed playback. Just a guess, but the MediaCodec might duplicate data for stereo configuration.
This one is a little tricky but here is what you can do using adb and ALSA.
Android internally uses ALSA.
Your device should have ALSA, try :
root#user:/$ adb shell cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version 1.0.25.
Just take a look at Reading ALSA Device names.
Every device (subdivision of a card) has a capture and a playback component.
Like /proc/asound/card0/pcm1p and /proc/asound/card0/pcm1p where card is 0 device is 1
pcm1p is your playback and pcm1c is capture (for recording).
Access your device using adb:
root#user:/$ adb shell
shell#android:/$:
Identifying your device:
So you see /proc/asound/pcm will give you a long list.
shell#android:/$: cat /proc/asound/pcm
00-00: MultiMedia1 (*) : : playback 1 : capture 1
00-01: MultiMedia2 (*) : : playback 1 : capture 1
00-02: CS-Voice (*) : : playback 1 : capture 1
From the above I find 00-00: MultiMedia1 (*) as card0 and device0 is for Multimedia playback.
Getting Playback Parameter:
Play your loaded mp3 file using your standard music player Application.
While the song is playing.
Issue the following commands for card0, device0(p - playback), and subdevice0
shell#android:/$: cat /proc/asound/card0/pcm0p/sub0/hw_params
access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 1920
buffer_size: 3840
So try using the same values when you call AudioTrack track= new AudioTrack(...);
The above value will only be visible when the device is in open (Playing some audio).
If you issue this to a wrong device (like say pcm1p), you will see the following:
shell#android:/$: cat /proc/asound/card0/pcm1p/sub0/hw_params
closed
Note :
Step 1 doesn't require phone to be rooted, How to Setup ADB.
Alternatives:
Have you tried the AudioTrack APIs like getChannelConfiguration() or getChannelCount() from here - Just Asking.
Have you tried looking at the MP3 file properties, the metadata has information on the audio parameters.

FFMpeg Mobile video encoding stutter

I have been playing around with ffmpeg and video encoding and even though my mp4's work great on desktop, they are smooth etc they are terrible on mobile devices. They stutter and load very slowly and I am trying to figure out the problem.
As an example I made a page using the media element plugin: http://mediaelementjs.com/ and on it I first placed the video that comes with mediaelementjs and it worked well, it scaled to desktop and mobile and loaded quickly and played without any stutter.
However I loaded my video and it was slow and full of stutter, but only on mobile. So I thought it might be S3 (where it is hosted) but saved the file locally and same thing.
I am hoping someone who knows h.264 and/or ffmpeg can point me in the direction of why; here is the current command I am running on ffmpeg:
ffmpeg -i $input_file_name -vcodec libx264 -r 100 -bt 300k -ac 2 -ar 48000 -ab 192k -strict -2 -y $output_temp_file 2>&1
So what have I missed?
So what have I missed?
Mobile devices have a very limited computing power. You are trying to play 100fps video file - there aren't any mobile device i know that can handle such framerate.
First - change framerate to reasonable value, then adjust resolution, set encoding profile (baseline, for example), video bitrate (quality, rate-factor). After that you can try out your files.

Categories

Resources