Posts tagged ffmpeg
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:
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.
“-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.
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:
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:
Vimeo format recommendations give specific values for bit rates and codecs as follows for high quality:
For HD video on Vimeo:
“-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:
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!
Here is an explanation of how to use ffmpeg for screencasting.
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
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:
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.