Sunday, 16 June 2013

Encoding camera video clips to small decent quality files

I like taking photographs, and I often cary a camera with me. I however rarely use my camera for filming video. Video clips doesn't mean that much to me, and I don't require a lot of quality from them. I just want clips that looks decent with a minimal file size. For that reason I always re-encode the few clips I do occasionally film to ensure I get some relatively small files with a quality I personally find acceptable. The best way to do that is in my opinion with FFmpeg. There is different ways to get FFmpeg installed depending on operating system, but on OS X, one of the easiest ways is probably to install in through MacPorts. The command line I most often use when re-encoding video is simply:

ffmpeg -i {input.ext} -c:v libx264 -b:v 3072k -vf "scale=trunc(oh*a/2)*2:720" -c:a aac -b:a 96k -ar 22050 -ac 1 -strict -2 {output}.mp4

-i input file to re-encode.
-c:v re-encoded video format. In this case libx264 will encode to h264
-b:v bit rate for encoded video. Higher value means better quality.
-vf scale the video to 720 horizontal lines. The width will be calculated to maintain aspect ratio*.
-c:a re-encoded audio format. In this case aac will encode to aac.
-b:a bit rate for encoded audio. Higher value means better quality.
-ar sample rate for audio. Higher value means better quality.
-ac number of channels. 1 means mono.
-strict -2 a parameter that for some reason is required as libx264 is exparimental.

(*)It takes output width (oh), multiplies it by aspect ratio (a), divides by 2, truncates digits after decimal point and multiplies by 2. It guarantees that resulting height is divisible by 2.

No comments:

Post a Comment