FORUMS: list search recent posts

Convert foreign videos to h.264

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Peter Zebke
Convert foreign videos to h.264
on Feb 4, 2012 at 12:06:33 pm

Hello

I convert some videos for displaying in a html5-video portal.
Currently I'm using the following commands for convert to h.264:

ffmpeg -i [source].any -s 960x720 -vb 2000k -vcodec libx264 -vpre normal -y [target].mp4
ffmpeg -i [source].any -s 480x360 -vb 2000k -vcodec libx264 -vpre normal -y [target].mp4

The size means the maximum side lengths, who I've calculated before.
With the most input videos there is no problem. But if I want to convert a special video (taken with an android smartphone), the process takes a very long time and the target video becomes a size of 42MB respectively 23MB (Input video 8,5MB).

Whats wrong? This video seems to be also problematic with other parameters...!?
Please aware, the users can upload any types of videos (In whitelist).

Input video download: http://176.9.85.198/problem.mp4 (8,5MB)


BTW: It doesn't make sense, if the output video becomes a higher bitrate / solution / whatever as the input video. Is it my job to prevent this? Or is it possible to tell ffmpeg the used parameters are maximum values and he has to use max the values from input video?
What are the best ffmpeg parameters to convert foreign / unknown videos to html5 formats?

--
WebM rulz :) It's very fast and easy. Why it's so hard to convert h.264? :(


Return to posts index

Reuben Martin
Re: Convert foreign videos to h.264
on Feb 5, 2012 at 3:17:53 am

With ffmpeg 0.10.0 I get 4.4MB and 4.3MB

This is with -acodec copy added. You have not specified anything for -acodec, so it will just use whatever is the default audio codec for your version of ffmpeg.

Without providing the terminal output, I can only guess that they problem might be with the audio codec, or a broken build of ffmpeg.

Also, be aware that if you update to a more recent version, the "-vpre" option for libx264 is no longer used and has been replaced by "-preset" which grabs the preset from libx264 directly, rather than using an ffpreset file.

With a more recent version of ffmpeg you might want to use something like this:

for compatibility with older devices:
ffmpeg -i [source.ext] -s [width]x[height] -vcodec libx264 -preset slow -vprofile baseline -crf 20 -pix_fmt yuv420p -acodec libaacplus -ar 44.1k -ab 32k -ac 1 -f mp4 -y [target].mp4

for newer devices that can support main/high profile:
ffmpeg -i [source.ext] -s [width]x[height] -vcodec libx264 -preset slow -vprofile high -trellis 2 -crf 20 -pix_fmt yuv420p -acodec libaacplus -ar 44.1k -ab 32k -ac 1 -f mp4 -y [target].mp4

for stereo rather than mono change "-ab" to 64 and "-ac" to 2.

The settings above assume ffmpeg is built with libaacplus support turned on which allows high quality audio at very low bitrates. (HE-AAC)


Return to posts index

Peter Zebke
Re: Convert foreign videos to h.264
on Feb 6, 2012 at 8:54:31 pm

I've installed ffmpeg from the default debian squeeze repository.
If I try your command it fails:

>ffmpeg -i test.mp4 -s 960x720 -vcodec libx264 -preset slow -vprofile baseline -crf 20 -pix_fmt yuv420p -acodec libaacplus -ar 44.1k -ab 32k -ac 1 -f mp4 -y target.mp4

[NULL @ 0x98aca60] [Eval @ 0xbf9de63c] Undefined constant or missing '(' in 'baseline'
[NULL @ 0x98aca60] Unable to parse option value "baseline"
Invalid value 'baseline' for option 'vprofile'


The complete output from my first command:

>ffmpeg -i test.mp4 -s 960x720 -vb 2000k -vcodec libx264 -vpre normal -y target.mp4

ffmpeg version 0.7.11, Copyright (c) 2000-2011 the FFmpeg developers
built on Jan 28 2012 01:15:36 with gcc 4.4.5
configuration: --enable-libdc1394 --prefix=/usr --extra-cflags='-Wall -g ' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-avfilter --enable-libdirac --disable-decoder=libdirac --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-libvpx --enable-librtmp --extra-libs=-lgcrypt --disable-altivec --disable-armv5te --disable-armv6 --disable-vis
libavutil 50. 43. 0 / 50. 43. 0
libavcodec 52.123. 0 / 52.123. 0
libavformat 52.111. 0 / 52.111. 0
libavdevice 52. 5. 0 / 52. 5. 0
libavfilter 1. 80. 0 / 1. 80. 0
libswscale 0. 14. 1 / 0. 14. 1
libpostproc 51. 2. 0 / 51. 2. 0

Seems stream 1 codec frame rate differs from container frame rate: 60000.00 (60000/1) -> 30000.00 (60000/2)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
Metadata:
major_brand : 3gp4
minor_version : 768
compatible_brands: 3gp43gp6
Duration: 00:00:16.76, start: 0.000000, bitrate: 4276 kb/s
Stream #0.0(eng): Audio: aac, 16000 Hz, mono, s16, 58 kb/s
Stream #0.1(eng): Video: h264 (Baseline), yuv420p, 720x480, 4213 kb/s, 29.65 fps, 30k tbr, 30k tbn, 60k tbc
[mp4 @ 0x86adc80] Frame rate very high for a muxer not effciciently supporting it.
Please consider specifiying a lower framerate, a different muxer or -vsync 2
[buffer @ 0x86b05e0] w:720 h:480 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[scale @ 0x86c14c0] w:720 h:480 fmt:yuv420p -> w:960 h:720 fmt:yuv420p flags:0x4
[libx264 @ 0x86a2ba0] MB rate (81000000) > level limit (983040)
[libx264 @ 0x86a2ba0] using cpu capabilities: MMX2 SSE2 FastShuffle Cache64
[libx264 @ 0x86a2ba0] profile High, level 5.1
[libx264 @ 0x86a2ba0] 264 - core 118 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=0 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=2000 ratetol=1.0 qcomp=0.60 qpmin=10 qpmax=51 qpstep=4 ip_ratio=1.41 aq=1:1.00
Output #0, mp4, to 'target.mp4':
Metadata:
major_brand : 3gp4
minor_version : 768
compatible_brands: 3gp43gp6
encoder : Lavf52.111.0
Stream #0.0(eng): Video: libx264, yuv420p, 960x720, q=10-51, 2000 kb/s, 60k tbn, 30k tbc
Stream #0.1(eng): Audio: libfaac, 16000 Hz, mono, s16, 64 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Stream #0.0 -> #0.1


Return to posts index


Peter Zebke
Re: Convert foreign videos to h.264
on Feb 6, 2012 at 8:59:51 pm

Sorry, you've written "With a more recent version".

Do you mean it's better to install ffmpeg from other source to get a newer version, so that I can use your command?


Return to posts index

Reuben Martin
Re: Convert foreign videos to h.264
on Feb 7, 2012 at 3:41:35 am

I'm not implying that it's necessarily better, just different. I don't use the 0.7.x series any more, so you should take what I say with a grain of salt and understand that what may work for me may not work for you and vice-versa.

One thing of interest from what you posted is this:

[mp4 @ 0x86adc80] Frame rate very high for a muxer not effciciently supporting it.
Please consider specifiying a lower framerate, a different muxer or -vsync 2

Your problem might be a sync issue. Try using the "vsync 2" option that it suggests.

It's more likely though that the problem is with libfaac not supporting the format of the input (16000 Hz, mono, s16) but that your version of ffmpeg does not check for it and tries to force it. My version fails saying libfaac does not support that format. You can try resampling the audio to a format libfaac supports.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]