0

file says all the files are ISO Media, MPEG v4 system, version 2 and the title's info is from VLC 2.0.9. IMO 1080p isn't necessary, especially since the other vids from earlier are 720p and are just fine; I don't know and aren't sure but I think all these vids are HD, which explains their size. The rest of the info given by VLC during playback, for completeness:

Decoded format: Planar 4:2:0 YUV

I've found not just one answer and they all use ffmpeg but avconv is the successor; I know, they're same thing, for most part at least. I know from experience avconv doesn't accept some options designed for ffmpeg. Not to mention that both have options which sound similar within same program but have totally different results.

4

1. Get ffmpeg

It is always a good idea to use a recent build when encoding with ffmpeg. Development is very active and using a recent build will allow you to avoid fixed bugs while giving you access to the latest features.

There are two main methods to get ffmpeg and neither will interfere with packages from the repository including the so-called "ffmpeg" package:

Using a static build

This is simply a binary that someone else compiled. All you do is download, extract, and run it (note the ./ before ffmpeg):

wget http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.$(date +"%F").tar.gz
tar xzvf ffmpeg.static.32bit.$(date +"%F").tar.gz
./ffmpeg -i input.mp4 <your options> output.mkv

Compiling ffmpeg

When compiling you control exactly how ffmpeg is configured and also allows you to use certain encoders, such as libfdk_aac, that are not available in the static builds.

Just follow a step-by-step guide: How to Compile FFmpeg on Ubuntu. If you can copy and paste you can compile ffmpeg.


2. Encode

ffmpeg -i in.avi -vf scale=-1:720 -c:v libx264 -crf 18 -preset fast -c:a copy out.mkv

In this example:

  • The scale filter to resize the video. With scale you can just declare one dimension, height in this case, and use -1 in the other. ffmpeg will then automatically calculate the correct value while maintaining the aspect ratio.

  • The encoder libx264 will produce H.264 video. Quality is controlled with -crf. The range is a log scale of 0 to 51. 0 is lossless (files will likely be huge), 18 is often considered to be "visually lossless", 23 is default, and 51 is worst quality. Generally you use the highest value that still gives you an acceptable quality.

  • Video encoding speed/compression efficiency for this encoder is controlled with the -preset. These are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow. Default is "medium". Generally you use the slowest preset that you have patience for.

  • For a set of videos use the same -crf and -preset for all of them.

  • The audio will be stream copied from the input to the output. Think of it like a copy and paste.

  • The Matroska output container will be used. It supports more formats not it is not as widely supported by players and devices as MP4 for example.

Encoding all videos

You can use a bash "for loop" to encode all videos in a directory:

mkdir encoded
for f in *.avi; do ./ffmpeg -i "$f" -vf scale=-1:720 -c:v libx264 -crf 18 -preset fast -c:a copy encoded/"${f%.avi}.mkv"; done

Also see

  • A nice answer. The speed presets sound like the program will slack more instead of working, but that's not the case, instead slower=better result ? – rautamiekka Dec 17 '13 at 13:53
  • @Rautamiekka A preset allows you to set the tradeoff for encoding efficiency vs encoding speed. A fast preset is less efficient, so it is faster. A slower preset has better compression (quality per file size). So a slower preset will give you better compression at a slower encoding speed. – llogan Dec 17 '13 at 20:12
  • [ERROR] for f in *.mp4 do; ffmpeg -i "$f" -vf scale=-1:720 -c:v libx264 -crf 0 -preset veryslow -c:a copy encoded/"${f%.mp4}.mp4"; done <new line> bash: syntax error near unexpected token ffmpeg'` – rautamiekka Dec 17 '13 at 20:46
  • I figured out that error: the semicolon should be before 'do'. However, there's another issue which is even easier: simply calling ffmpeg calls the installed version, so to call the separate version one needs ./ before the program name, so that's solved. I'll leave this laptop process the files over the night and will get back to you once I can watch them. – rautamiekka Dec 17 '13 at 20:49
  • @Rautamiekka Sorry for the typo. Fixed. – llogan Dec 17 '13 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.