FORUMS: list search recent posts

Ideal FFMPEG commands for web videos and audios

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Kip Hughes
Ideal FFMPEG commands for web videos and audios
on May 17, 2012 at 4:05:06 am

I'm not building the next YouTube or iTunes, but I do need to give my users the ability to upload their videos and audios -- then present it on the web at the highest possible quality with the lowest possible file size.

Questions:

1. What video and audio formats should I support? I'm guessing I should try to support the most common formats, but I'm not entirely sure what they are. Also, I'm not sure if I should support the most common formats. Maybe there is a reason not to support a certain format.

2. What video and audio output formats should I generate? I'd like to use HTML5's and tags, but know I should consider supporting non-HTML5 browsers. Should I do OGG, MP4 and FLV for videos? What about audios?

3. Given an unknown video and audio file uploaded by the user, what command should I use to generate the desired output formats. I'd like one command to convert to particular outputs -- and hopefully not have to do anything different to the commands depending on the input (it'll be a pain for me to know what the MIME type is of the file, etc. and can't really do an "if input is a WMV, then run this command" logic).

Suggestion FFMPEG experts?


Return to posts index

stephen dixon
Re: Ideal FFMPEG commands for web videos and audios
on May 17, 2012 at 9:05:35 am

1. depends on what you are using to play the video. The bad news is that you will probably have to export to at least two formats, possibly three. There's some good info at http://camendesign.com/code/video_for_everybody and http://diveintohtml5.info/detect.html#video among others.

2.
Don't bother with flv, Flash can play mp4 video. There are several good flash players that can be used with HTML as fallback and they'll all take an mp4 file. There are links on the Video For Everybody page I mentioned above. But the way things are, you'll need at least two of mp4, ogv and webm. Thanks to Google, Apple and Microsoft for making things so frikkin difficult.

Here's what I use to generate the above for web display:

h264/x264/mp4 whatever you want to call it
For h.264 I always use
-vcodec lbx264 -preset slow -profile main -crf 20 -acodec libfaac -ab 128k
Change the crf and ab settings to suit your idea of quality vs size (crf is inversely related to the quality 0 is best higher numbers mean worse quality / smaller file sizes). I use the main profile and slow preset because it seems to be most compatible with all the gadgets and gizmos that people play video on these days. It won't give you as much bang for your bit as using higher profiles and slower encodes but more people will actually be able to view it. And using the presets is way easier than hand rolling some arcane compression tweakage.

ogv
-vcodec libtheora -qscale 6 -acodec libvorbis -ab 128k
again adjust the quality till it suits you. Qscale is the quality setting in this case; low is bad / small high is good / large.

webm
-vcodec libvpx -qscale 6 -acodec libvorbis -ab 128k
just like ogv. There aren't anywhere near as many knobs and buttons to twiddle with webm and ogv as there are with libx264.


3.
ffmpeg is able to automatically recognise the format of the input video, so don't fret.
ffmpeg -i [your video] [encoding options as specified above] [your output video with appropriate extension - eg output.mp4, output.ogv or output.webm]
and that's all. Magick!

You might also want to add filters to do things like scale the video to an appropriate size, eg:
-vf scale="480:360" (scale to 480x360px)
or
-vf scale="480:-1" (scale to 480px wide and whatever height it needs to be to maintain the correct proportion).

HTH

Stephen Dixon
Editor, Animator, Motionographer
Museum Victoria


Return to posts index

Kip Hughes
Re: Ideal FFMPEG commands for web videos and audios
on May 17, 2012 at 9:20:13 am

Hi Stephen, thanks for this. I am going to read over this and try this on my local machine. I'm on Vista with the FFMPEG I got from http://www.videohelp.com/tools/ffmpeg#download. I hope I don't run into any problems. Thanks!


Return to posts index


stephen dixon
Re: Ideal FFMPEG commands for web videos and audios
on May 17, 2012 at 12:20:23 pm

I'm not sure how that version was compiled (I don't have a working windows box at the moment), but for x264 and webm you need to have a version of ffmpeg that was compiled with the libx264 and libvpx (? or something like that) libraries. ffmpeg.org is the best place to go for the source code and instructions on how to compile, if you can get past it being a bit gruff and nerdy.

To find out whether your version has x264 and vpx capabilities try ffmpeg -version that will tell you all the things it was compiled with.

Another thing worth checking out is ffmbc, a "professional" fork of the ffmpeg project, which is better for a production setting, and supports things like dnxhd and apple prores out of the box.

Stephen Dixon
Editor, Animator, Motionographer
Museum Victoria


Return to posts index

stephen dixon
Re: Ideal FFMPEG commands for web videos and audios
on May 17, 2012 at 12:25:21 pm

actually I downloaded it and had a look, it does have x264 and vpx, but I'm not sure if the presets are all there. See how you go.

the link for ffmbc is http://code.google.com/p/ffmbc/


Return to posts index

Kip Hughes
Re: Ideal FFMPEG commands for web videos and audios
on May 18, 2012 at 1:04:14 am

Stephen,

Any recommendations for audios? Also, what input formats (video and audio) do you think would be worthwhile supporting? Thanks.


Return to posts index


Kip Hughes
Re: Ideal FFMPEG commands for web videos and audios
on May 17, 2012 at 10:54:57 pm

Hi Stephen,

The command to create OGV seems to be working fine. When I try to create MP4 using the following command:

ffmpeg -i input.avi -vcodec lbx264 -preset slow -profile main -crf 20 -acodec libfaac -ab 128k -vf scale="480:-1" output.mp4

The command line tells me this:

Unknown encoder 'lbx264'

Doing a ffmpeg -version gives me this:


ffmpeg version N-37208-g01fcbdf
built on Jan 27 2012 18:34:52 with gcc 4.6.2
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runt
ime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libopenc
ore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enab
le-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --e
nable-libspeex --enable-libtheora --enable-libvo-aacenc --enable-libvo-amrwbenc
--enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-li
bxvid --enable-zlib
libavutil 51. 34.101 / 51. 34.101
libavcodec 53. 60.100 / 53. 60.100
libavformat 53. 31.100 / 53. 31.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 60.100 / 2. 60.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 6.100 / 0. 6.100
libpostproc 52. 0.100 / 52. 0.100


Was -vcodec lbx264 supposed to be -vcodec libx264? Because when I changed it, I got a new error:

Unknown encoder 'libfaac'

I'm going to try this on my server later. If it works there, I'm not going to worry about getting it to work on my Windows machine.

Also, does order of the arguments matter?


Return to posts index

stephen dixon
Re: Ideal FFMPEG commands for web videos and audios
on Jun 12, 2012 at 1:06:22 pm

Typo, sorry. Should have been "libx264". The "unknown encoder" means that ffmpeg wasn't compiled with that codec enabled. You can either install that codec and recompile or try using the ffmpeg default mp4 audio encoder (I'm not 100% sure what that is..?). Just don't specify an audio codec and see what you get in the output.

Arguments can be in any order, but there are restrictions on where they go with respect to the input and output part of the command. You'll ahve to read the manual for the ins and outs, but usually all the conversion type arguments can be anywhere as long as they're between the input and the output file specifiers.

Stephen Dixon
Editor, Animator, Motionographer
Museum Victoria


Return to posts index

Jeff Panasuik
Re: Ideal FFMPEG commands for web videos and audios
on May 11, 2014 at 1:33:03 pm

For those who found this post and still wonder about this:

You need to complie your own FFMPEG engine in order for you to have your own converter on your system/server. This is the guideline for your benefit.

Just “download” the app doesn’t usually work that way, so…if you have time; determination to have the converter yourself; and desire to see it working — then check this link and follow the guideline based on your system (Win/Linux/Mac/etc).

http://trac.ffmpeg.org/wiki/CompilationGuide

Good luck! :)


Return to posts index

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