B
B
barmaglod2015-04-22 14:55:16
Video
barmaglod, 2015-04-22 14:55:16

Ffmpeg - 2-pass video encoding, how to do it in the best quality?

There is a task to encode the source video ( sample01 , sample02 ) with a size reduction to 480x384 and a bit rate of 310. To be precise, the parameters of the resulting video should be as follows:

Видео
   Размер кадра:	480х384
   Кодек:		h264
   Профиль:		Baseline 3.0
   ReFrames:		3
   Битрейт:		310 Kbps, Переменный
Аудио
    Кодек:		АСС
    Битрейт:		128 к
    Частота:		48000

The profile, unfortunately, must be no more than Baseline 3.0. It is also not desirable to increase the bitrate.
ffmpeg version N-71608-ga924b83
After some experimentation with the ffmpeg parameters, this line encodes the video in one pass:
ffmpeg.exe -hide_banner -i sample01.ts -vf scale=480:384 -sws_flags lanczos -vcodec h264 -profile:v baseline -level 3.0 -g 25 -x264opts me=tesa -me_range 32 -subq 9 -deblock 3:2 -b:v 310k -minrate 300k -maxrate 350k -bufsize 4000k -acodec libvo_aacenc -ab 128k -ar 48000 -f mpegts sample01_lq_1p.ts

The result turned out to be acceptable ( sample01_lq_1p , sample02_lq_1p ), but there is no limit to perfection, and I would like to extract the best possible quality from such a low bitrate. There was an attempt to do this using 2-pass encoding with this line:
ffmpeg.exe -hide_banner -i sample01.ts -vf scale=480:384 -sws_flags lanczos -vcodec h264 -profile:v baseline -level 3.0 -g 25 -x264opts me=tesa -me_range 32 -subq 9 -deblock 3:2 -b:v 310k -minrate 300k -maxrate 350k -bufsize 4000k -pass 1 -fastfirstpass 0 -passlogfile stat01 -an -f mpegts -y NUL && ffmpeg.exe -hide_banner -i sample01.ts -vf scale=480:384 -sws_flags lanczos -vcodec h264 -profile:v baseline -level 3.0 -g 25 -x264opts me=tesa -me_range 32 -subq 9 -deblock 3:2 -b:v 310k -minrate 300k -maxrate 350k -bufsize 4000k -pass 2 -passlogfile stat01 -acodec libvo_aacenc -ab 128k -ar 48000 -f mpegts sample01_lq_2p.ts

The result was disappointing. ( sample01_lq_2p , sample02_lq_2p ) Image quality got worse, jpeg artifacts clearly got out. This is especially noticeable on the first frames of the video sample01_lq_2p, where the numbers are running.
Tell me what to fix in the ffmpeg encoding parameters, and how to improve the quality of the resulting video.
This line was obtained empirically, by reading the documentation and examples, maybe I missed something, or maybe, in this case, the second pass will not help?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question