Posts tagged ffmpeg

Web Video

I’ve been experimenting with video codecs and formats for uploading video to the web (Facebook, Youtube, etc.).

Encoding for the Web

To make a tiny file, you can encode files this way:

ffmpeg -i foo.dv foo.mp4

For better quality output, there are a number of variables you can control. I’m starting with two assumptions for the time being: I’m using the h264 codec and my target output format is mp4. For YouTube, flv would be better.

ffmpeg -i foo.dv -ab 128k -ar 44100 -b 1200k -vc h264 -qscale 1 -s 480×360 foo.mp4

“-i foo.dv” just identifies the input file, and the rest of the options apply to the output file.

For my own future benefit, I will break down the options I’ve used: “-ab 128k” is the audio bitrate, “-ar 44100″ is the audio sampling frequency (44100 is the default anyhow); “-b 1200k” is the video bitrate; “-vc h264″ is the video codec; “-qscale 1″ sets the video quantizer scale (lower is better quality, use “-sameq” for the same quality); “-s 480×360″ is the target width and height. All of these variables can be changed to create a higher/lower quality file which is smaller/larger in size. These settings create a decent output file for people to download, but it will be resampled on uploading to websites for streaming.

FFMPEG Tricks

If you just want to do a quick trim of the clip before uploading, I’ve found this is an easy way to do it. First play the video:

mplayer -osdlevel 3 -menu -loop 0 -dr -ni -framedrop -autosync 30 -msglevel all=0 -really-quiet -nolirc foo.dv

Note the start and end points you want, then run the ffmpeg command with “-ss NN” for the starting point in seconds and “-t NN” for the duration. That allows you to trim either the start or end of the clip without having to break out Cinelerra or Kino. By the way, I’ve got a pile of switches enabled on mplayer, but the only one that really matters is “-osdlevel 3″ so you can see the counter.

Some Youtube guidance on formats here: http://www.google.com/support/youtube/bin/answer.py?answer=132460&safe=off

Facebook format details are found here. You could use this command and vary the qscale and bitrate to get a reasonable file size:

ffmpeg -i foo.dv -acodec libfaac -ab 128k -b 1200k -vc h264 -qscale 6 foo.mp4

Vimeo format recommendations give specific values for bit rates and codecs as follows for high quality:

ffmpeg -i foo.dv -acodec libfaac -ab 320k -b 2000k -vc h264 -sameq foo.mp4

For HD video on Vimeo:

ffmpeg -i foo.m2t -acodec libfaac -ab 320k -b 3000k -vc h264 -sameq -s hd720 foo.mp4

“-s hd720″ tells ffmpeg to create 1280×720 output.

Sources of Information

This video is a good ffmpeg intro: http://www.linuxjournal.com/video/linux-howto-video-editing-magic-ffmpeg

For Youtube uploads, they use the following command. The presenter explains that these parameters are good for Youtube because they will not be re-encoded on upload:

ffmpeg -i foo.mov -ar 22050 -acodec libmp3lame -ab 32k -r 25 -s 320×240 -vcodec flv -qscale 9.5 foo.flv

He also shows how to crop and letterbox using ffmpeg and even creates a moving spotlight. He also uses the “-loop_input” ffmpeg switch in order to make a 10 second clip of a still frame. Very handy!

ffmpeg -loop_input -i still.png -t 10 -r 29.97 -qscale 2 extendedstill.mpg

Here is an explanation of how to use ffmpeg for screencasting.

Capturing from Canon Vixia HV40 in Ubuntu

I am very pleased to report that capturing from my new camera works like a charm.  I hardly had to do any tweaking to get it to work.

Here are some commands that worked for me to begin with:

  • grab video
    sudo dvgrab –autosplit –frames 0 –size 0 –format hdv –buffers 1000 –showstatus –timestamp /home/video/foo-
  • convert to avi format for facebook, etc.
    ffmpeg -i foo.m2t video.avi
  • convert to dv format for editing
    ffmpeg -i /home/video/foo.m2t -target ntsc-dv foo.dv

Convert Raw MiniDV Footage to Upload to Facebook

I just shot a bit of footage I wanted to upload to Facebook. According to this Facebook question, mpeg4 video is a good choice.

This command seems to do the trick to convert my rawdv footage to a Facebook friendly format:

cat foo.dv | ffmpeg -f dv -i pipe: -acodec libfaac -vcodec libx264 -s 640×360 -aspect 16:9 foo.mp4

Note that the names of the codecs in this command seem to vary according to your version of ffmpeg.  If this version doesn’t work, you might try faac and h264 instead of libfaac and libx264, respectively.