FFmpeg mp4 encoder for html-android - 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

Related

ffmpeg: Video duration confused for some players on Android

I am using ffmpeg to scale down and compress videos to be used in Android app.
The original files are played with no problem and have no metadata issues. When I re-encode them however, the Android player is able to play them, but displays wrong durations. My app is in production and it is using official player implementations, so I wonder if there is a way to fix the corruption using ffmpeg or adding some metadata to the generated files. Hopefully that's possible, but if not - any other possible fixes will be highly appreciated :)
My ffmpeg command is complex, including scaling and encoding but I can confirm this issue is reproducible on my end with the simplest ffmpeg -i video.mp4 -c:v libx264 videogen.mp4 command.
I'm leaving links to the two files if that's helpful for reference.
video.mp4
videogen.mp4
Any ideas what could be causing this and how to fix it?
Player issues showcase:
video.mp4 (original)
videogen.mp4 (re-encoded)
After some testing I found out that the player was playing fine files with the following metadata:
major_brand=mp42
encoder=Lavf58.24.101
So I used ffmpeg -movflags use_metadata_tags to set the working metadata :)

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.

Android and FFmpeg. Video is very slow

I have built ffmpeg library for my Android device from here: https://github.com/appunite/AndroidFFmpeg. But some video files playing very very slow (i find out that very slow are playing videos which my Android device can play by itself). Here is build.sh script
https://github.com/appunite/AndroidFFmpeg/blob/master/FFmpegLibrary/jni/build_android.sh
May be this is because of these lines:
--enable-hwaccel=h264_vaapi \
--enable-hwaccel=h264_vaapi \
--enable-hwaccel=h264_dxva2 \
--enable-hwaccel=mpeg4_vaapi \
As I have understood these lines are enabling hw acceleration (the author of that code says that this can raise some bugs). The basic idea of the player is to decode video and audio streams in native code, then render video frame into AndroidBitmap and render Audio into Android MediaPlayer.
Does anyone know how to solve problem of slow video decoding (maybe decrease video frame resolution or something else?) I will be pleased for any help and ideas.
Strange that --enable-hwaccel=h264_vaapi is specified twice in a row, but I see that it's in the original build script that you linked to.
DXVA2 refers to DirectX Video Acceleration, available on Windows desktop computers. So that won't help here. VAAPI refers to Video Acceleration API. I was about to say that it targets only Unix desktops, but the Wikipedia page states that it can also target Android.
The likely reason that the decode is slow is that a software decode path is being taken. What type of video data are you decoding, and at what profile and resolution? Generally, it's best to leverage the Android media facilities, such as MediaPlayer for playback, unless you're doing something special. You have probably already researched this option and perhaps you found that you can't obtain raw AndroidBitmaps (I am not too familiar with Android development).
I'm looking at the source for both FFmpeg's VAAPI interface and the VAAPI->Android code. If you have FFmpeg compiled for Android, how is it accessing VAAPI? Do you have VAAPI compiled for Android as well? I have a feeling that VAAPI is not a stock component of Android (but again, I'm not sure), so you may need to ensure that VAAPI is in place. Then, are you correctly asking FFmpeg to use VAAPI? I don't think FFmpeg will autodetect this.

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.

live stream desktop to android tablet and delay

I am trying to live stream the desktop to android tablet. Here is what I did
1) Capture the screen using the ffmpeg
ffmpeg -y -f x11grab -s 800x600 -r 20 -i :0 http://x.x.x.x:8090/feed1.ffm
2) Stream using ffserver
Here is partial ffserver.conf file
<Stream test>
Feed feed1.ffm
Format flv
NoAudio
VideoSize 800x600
</Stream>
3) Play the stream on the tablet (Android 4.3) using URL "http://x.x.x.x:8090/test"
I am able to see the desktop on tablet with few issues
1) There is around 6 to 8 secs delay in the video
2) player shows a warning "first frame is no keyframe"
When I changed the "Format flv" to "Format mpegts" in "ffserver.conf" file the warning is gone. But the delay is still there.
Is there a way to reduce the delay?
Am I using the correct format?
I want to achieve at max 2 sec delay for my desktop streaming.
What are you using at the android device to view the video? The question looks quite generic.
Are you just sending raw frames to the receiver? In that case, they might be quite a bit heavy and it take some time to process them. See if you can actually encode them and stream to network.
Secondly, It also depends in network latency, how good is your network? Give a try in a WLAN first and then try it between two public IP Numbers.
What is the size of your jitter-buffer at the receiver? If you have large jitter-buffer, players set some percentage limit to fill before it can actually kick playing. Apparently if you have large jitter-buffer it might take long time to fill it and so initial delay for your video. So, in test cases shutdown the jitter-buffer.
I could also blame the decoding capabilities of your receiver device.

Categories

Resources