Transcoding video with ffmpeg

I asked on another question (http://stackoverflow.com/questions/8012494/sorry-this-video-cannot-be-played-streaming-mp4-to-android/8012874#8012874) about playing video in android using VideoView. Apparently, the problem is related to the way my video is encoded, since another video (512 KB mp4 from the Internet) plays my code correctly. Since the videos are uploaded by my end users to the website, I have no control over the videos themselves, however I have control over their re-encoding. I will recode them using ffmpeg to convert them to the standard MP4 format (H.264 + AAC) and scale them to the same size (320x240).

Here is the ffmpeg information of the video that is not playing:

 sh-3.2$ ffmpeg -i video.bad.mp4 FFmpeg version SVN-r25679-snapshot, Copyright (c) 2000-2010 the FFmpeg developers built on Nov 5 2010 09:34:37 with gcc 4.3.2 configuration: --prefix=/usr --enable-shared --enable-libmp3lame --enable-gpl --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-libgsm --enable-x11grab --enable-libx264 --enable-libtheora --extra-cflags=-Wall --enable-swscale --enable-libdc1394 --enable-nonfree --disable-mmx --disable-stripping --enable-avfilter --disable-altivec --disable-armv5te --disable-armv6 --disable-vis --enable-nonfree --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 libavutil 50.32. 6 / 50.32. 6 libavcore 0.12. 0 / 0.12. 0 libavcodec 52.94. 3 / 52.94. 3 libavformat 52.84. 0 / 52.84. 0 libavdevice 52. 2. 2 / 52. 2. 2 libavfilter 1.56. 0 / 1.56. 0 libswscale 0.12. 0 / 0.12. 0 libpostproc 51. 2. 0 / 51. 2. 0 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.bad.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf52.84.0 Duration: 00:00:45.93, start: 0.000000, bitrate: 591 kb/s Stream #0.0(und): Video: h264, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 535 kb/s, 15 fps, 15 tbr, 15 tbn, 30 tbc Stream #0.1(und): Audio: aac, 48000 Hz, stereo, s16, 51 kb/s 

And here is the ffmpeg information about the video that plays correctly:

 sh-3.2$ ffmpeg -i video.mp4 FFmpeg version SVN-r25679-snapshot, Copyright (c) 2000-2010 the FFmpeg developers built on Nov 5 2010 09:34:37 with gcc 4.3.2 configuration: --prefix=/usr --enable-shared --enable-libmp3lame --enable-gpl --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-libgsm --enable-x11grab --enable-libx264 --enable-libtheora --extra-cflags=-Wall --enable-swscale --enable-libdc1394 --enable-nonfree --disable-mmx --disable-stripping --enable-avfilter --disable-altivec --disable-armv5te --disable-armv6 --disable-vis --enable-nonfree --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 libavutil 50.32. 6 / 50.32. 6 libavcore 0.12. 0 / 0.12. 0 libavcodec 52.94. 3 / 52.94. 3 libavformat 52.84. 0 / 52.84. 0 libavdevice 52. 2. 2 / 52. 2. 2 libavfilter 1.56. 0 / 1.56. 0 libswscale 0.12. 0 / 0.12. 0 libpostproc 51. 2. 0 / 51. 2. 0 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: mp41 title : crazytown - http://www.archive.org/details/Cartoon-Crazytown encoder : Lavf51.10.0 Duration: 00:07:50.40, start: 0.000000, bitrate: 578 kb/s Stream #0.0(und): Video: h264, yuv420p, 320x240, 510 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc Stream #0.1(und): Audio: aac, 48000 Hz, stereo, s16, 63 kb/s 

Actually, I have two questions. First of all, which of the details in my "bad" video does the android not like? And secondly, what options should I use with ffmpeg to transcode my videos? I am currently using this:

 ffmpeg -i $input_video_file -y -s 320x240 -vcodec libx264 -vpre medium -acodec libfaac -b 510K -ar 48000 -aspect 4:3 $tmpfile.mp4 qt-faststart $tmpfile.mp4 $output_video_file.mp4 

But this creates a video that cannot be played on Android. Any help is appreciated.

+2
android ffmpeg video
source share
1 answer

Firstly, your version of ffmpeg is older than a year. Since last year, much has improved with ffmpeg and H.264. Try updating at least ffmpeg-0.7.

It’s a little difficult to tell exactly where the problem is, because ffmpeg does not display all the parameters passed to x264 for H.264 encoding. Try increasing the volume of the ffmpeg output (using -v 1 or -v 2 somewhere near the start of the ffmpeg command). But based on my experience using ffmpeg to transcode Android video, I assume that you are not using the H.264 baseline profile (see the W.2 article on H.264 if you are interested). Try adding -profile baseline if you have ffmpeg-0.7 or newer.

If you cannot update ffmpeg for one reason or another, you can specify the baseline profile using the -vpre baseline option after specifying -vpre medium . If for some reason you get an error while trying to use a basic preset, you can manually force the baseline to be set by specifying -coder 0 -bf 0 -flags2 -wpred-dct8x8 on the command line after -vpre medium .

+6
source share

All Articles