From The World according to Vissie
Jump to navigation Jump to search

Install ffmpeg on Debian

For Jessie, we need to add backports:

vim: /etc/apt/sources.list
# Backports
deb http://ftp.debian.org/debian jessie-backports main

deb http://ftp.debian.org/debian jessie-backports main

apt-get install ffmpeg

Do I need gstreamer?

Some extra codecs

sudo apt-get install libavcodec-extra
  1. Type these commands for amd64 machines.
wget http://www.deb-multimedia.org/pool/non-free/w/w64codecs/w64codecs_20071007-dmo2_amd64.deb
dpkg -i w64codecs_20071007-dmo2_amd64.deb

I'm new at ffmpeg, but will try and make it my default tool

Convert video to Telegram format

Video dimensions must be set to 480x320 (320x480 for vertical videos). H.264 and MPEG-4 should be used as the codec and container.


If you need to simply resize your video to a specific size (e.g 320x240), you can use the scale filter in its most basic form:

ffmpeg -i input.avi -vf scale=320:240 output.avi

Same works for images too:

ffmpeg -i input.jpg -vf scale=320:240 output_320x240.png

As you can see, the aspect ratio is not the same as in the original image, so the image appears stretched. If we'd like to keep the aspect ratio, we need to specify only one component, either width or height, and set the other component to -1. For example, this command line:

ffmpeg -i input.jpg -vf scale=320:-1 output_320.png

will set the width of the output image to 320 pixels and will calculate the height of the output image according to the aspect ratio of the input image. The resulting image will have a dimension of 320x207 pixels.

My final solution:

ffmpeg -i myfile.avi -vf scale=480:-1 MyOutput.mp4

Batch convert a folder

for i in *.avi; do ffmpeg -i "$i" -qscale 0 `basename "$i" .avi`.mov ; done

Converting my movies

ffmpeg -i MyMovie.mkv -vf scale=-1:720 -c:v libx264 -crf 18 -preset veryslow -c:a copy MyMovie_720p.mkv

The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 18 to be visually lossless or nearly so: it should look the same or nearly the same as the input but it isn't technically lossless.

The range is exponential, so increasing the CRF value +6 is roughly half the bitrate while -6 is roughly twice the bitrate. General usage is to choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value and if it looks bad then choose a lower value.

You control the tradeoff between video encoding speed and compression efficiency with the -preset options. Those are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow. Default is medium. The veryslow option offers the best compression efficiency (resulting in a smaller file size for the same quality) but it is very slow – as the name says.

The audio will be stream copied directly from the input file to the output file without any changes.

This worked well for me:

ffmpeg -i Nerve_old.mkv -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv