ffmpeg: Video duration confused for some players on Android - 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 :)

Related

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.

How to trim the video using FFMPEG library in android?

In My Project,uploading the video ( duration is 10 seconds only) to amazon .So when i choose video from library of 30 seconds then i want trim the video to 10 seconds or may be less.I am using Mp4 Parser for trimming the videos but when trim the portrait video,it is converting to landscape mode and the video rotation also changes.I done lot of research in google but no solution lastly I found one solution that FFMPEG library.In windows the ffmpeg library is not building.So what can I do now?I am new to the FFMPEG library.Please give the suggestions how to build the FFMPEG library in android.Thanks in advance

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.

How to play mp3+g on mediaplayer android

I know we can play mp3 file in MediaPlayer.
But can we play mp3+g on android??
I saw in the documentation on android, but i didn't see it.
http://developer.android.com/guide/appendix/media-formats.html
Is there any work around or library to do this?
Thanks
I don't "think" that Android is going to support mp3+g playback anytime soon. That being said an mp3+g "file" should either be one zipped file(with two files inside) or two separate files named the same with exception of the file extension. So other then playing the MP3 there is really nothing else that MediaPLayer can do, and changing MediaPlayer int the android framework to get this to work would not be portable from device to device.
Workaround 1
Use FFMPEG to transcode and mux these files to a different format that is supported such as mp4. Here is an example of someone using ffmpeg to mux mp3+g into FLV.
Workaround 2
Another option would be to use Android For VLC which is in pre-alpha found here. Now I'm not sure that VLC for android will support mp3+g, but libvlc does support decoding of the two files so I'm guessing it would work, or you could alter the code a bit to get it to work. I have checked out the VLC for Android code recently and I have to say its a cpu hog but since mp3 and cdg are generally smaller less cpu intensive files I think that android devices could handle the work load using VLC.
Workaround 3
Now as far as more complex options you could utilize the Android NDK and create a decoder yourself (This would take you a lot of time).
Hope some of this helps you.
I have found the solution..
http://code.google.com/p/cdg-toolkit/
It was written in java so we should porting it first to Android if you want to use it.

Categories

Resources