Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ffmpeg to encode a high quality video [closed]

I have a set of video frames saved as images in a directory, and I'm trying to encode these to a good quality video, however every setting and every format I try produces very noticeable artifacts.

The basic command is this:

ffmpeg -r 25 -i %4d.png myvideo.mpg 

and I've tried the minrate and maxrate flags. Any of {mpg, avi, mov, flv} formats will do.

Any suggestions for settings? Final file size is not an issue.

like image 239
CakeMaster Avatar asked Aug 24 '10 23:08

CakeMaster


People also ask

How do I use FFmpeg without losing quality?

Instead of -sameq (removed by FFMpeg), use -qscale 0 : the file size will increase but it will preserve the quality.

How do I compress a video without losing quality using FFmpeg?

You can use FFmpeg to resize video to compress MP4/MOV/WebM etc. formatted videos without losing quality. For example, try the following command line: ffmpeg -i input. avi -vf scale=1280:720 output.

How do I use FFmpeg to encode a video?

Audio can be re-encoded from from its original format to another one by using the -vn option which tells FFmpeg to ignore the video stream if any. Encoding happens simply by using the desired format's file extension.


2 Answers

A couple of things:

  • You need to set the video bitrate. I have never used minrate and maxrate so I don't know how exactly they work, but by setting the bitrate using the -b switch, I am able to get high quality video. You need to come up with a bitrate that offers a good tradeoff between compression and video quality. You may have to experiment with this because it all depends on the frame size, frame rate and the amount of motion in the content of your video. Keep in mind that DVD tends to be around 4-5 Mbit/s on average for 720x480, so I usually start from there and decide whether I need more or less and then just experiment. For example, you could add -b 5000k to the command line to get more or less DVD video bitrate.

  • You need to specify a video codec. If you don't, ffmpeg will default to MPEG-1 which is quite old and does not provide near the amount of compression as MPEG-4 or H.264. If your ffmpeg version is built with libx264 support, you can specify -vcodec libx264 as part of the command line. Otherwise -vcodec mpeg4 will also do a better job than MPEG-1, but not as well as x264.

  • There are a lot of other advanced options that will help you squeeze out the best quality at the lowest bitrates. Take a look here for some examples.

like image 71
Jason B Avatar answered Sep 30 '22 13:09

Jason B


You need to specify the -vb option to increase the video bitrate, otherwise you get the default which produces smaller videos but with more artifacts.

Try something like this:

ffmpeg -r 25 -i %4d.png -vb 20M myvideo.mpg

like image 33
jeff7 Avatar answered Sep 30 '22 14:09

jeff7