Ubuntu: Convert “H264 MP4 AVC (part 10) (avc1)”/“MPEG AAC 48kHz” 1080p 23.976000fps videos to 720p, as complete quality as possible


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.


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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »