Using ffmpeg to encode high quality video

I have a set of video frames saved as images in a directory, and I try to encode them into good quality video, however, each setting and every format that I try to make creates very noticeable artifacts.

The main command is as follows:

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

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

Any suggestions for customization? The final file size is not a problem.

+73
ffmpeg video-encoding video
Aug 24 '10 at 23:09
source share
4 answers

A few things:

  • You need to set the video bitrate. I have never used minrate and maxrate, so I don’t know exactly how they work, but by setting the bitrate with the -b switch, I can get high-quality video. You need to come up with a bitrate that offers a good compromise between compression and video quality. You may need to experiment with this, because it all depends on the frame size, frame rate and the amount of movement in the contents of your video. Keep in mind that a DVD is usually around 4-5 Mbps on average for 720x480, so I usually start from there and decide if I need more or less, and then just experiment. For example, you can add -b 5000k to the command line to get more or less the bitrate of a DVD video.

  • You need to specify the video codec. If you do not, ffmpeg will use MPEG-1 by default, which is quite old and does not provide nearly compression volume, like MPEG-4 or H.264. If the version of ffmpeg is built with libx264 support, you can specify -vcodec libx264 as part of the command line. Otherwise, -vcodec mpeg4 will also work better than MPEG-1, but not as good as x264.

  • There are many other additional options that will help you squeeze the best quality at the lowest bitrates. Look here for some examples.

+50
Aug 25 '10 at 13:26
source share

You need to specify the -vb option to increase the video bitrate, otherwise you will get a default value that produces smaller videos, but with a lot of artifacts.

Try something like this:

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

+33
Aug 25 '10 at
source share

Before creating a video, make sure PNG is completely opaque.

eg. with imagemagick, give them a black background:

 convert 0.png -background black -flatten +matte 0_opaque.png 

In my tests, there is no bitrate or codec to make the video look good if you serve PNG with ffmpeg with transparency

+11
04 Oct '11 at 17:27
source share

If you do not do any post-processing, the video will never be better than the original frames. Just like a flip book, if you have a big β€œjump” between keyframes, this will look ridiculous. Usually you need enough tweens between keyframes to provide smooth animation. NTN

0
Aug 24 '10 at 23:21
source share



All Articles