Log in

View Full Version : Macroblocking problem in downconverted MPEG2, need ffmpeg help


mocham
16th December 2010, 08:02
I have a source AVC video as follows:

Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4.1
Format settings, CABAC : Yes
Format settings, ReFrames : 8 frames
Muxing mode : Container profile=Unknown@4.1
Codec ID : V_MPEG4/ISO/AVC
Duration : 1h 34mn
Bit rate : 2 460 Kbps
Width : 1 280 pixels
Height : 688 pixels
Display aspect ratio : 1.850
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.117

I want to convert this video to standard NTSC DVD using ffmpeg. I've done this many times before and the following is a fairly standard encoding line that I use:

ffmpeg -i INPUT.mp4 -f dvd -vcodec mpeg2video -s 720x462 -aspect 16:9 -vf "pad=720:480:0:9" -b 2800k -minrate 2800k -maxrate 3200k -bufsize 1835k -g 12 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -bf 2 -flags qprd -flags mv0 -flags2 skiprd OUTPUT.mpg

The above command produces a MPEG2 file with the following characteristics:

Format : MPEG Video
Format version : Version 2
Format profile : Main@Main
Format settings, BVOP : Yes
Format settings, Matrix : Default
Format settings, GOP : M=3, N=12
Duration : 1h 34mn
Bit rate mode : Variable
Bit rate : 3 200 Kbps
Width : 720 pixels
Height : 480 pixels
Display aspect ratio : 16:9
Frame rate : 23.976 fps
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.386

I'm having a problem in that the output has large blocky artifacts in some of the scenes with high motion. I could be wrong, but I believe (from experience) that this is happening because the input video is a much higher resolution than the output. Most of the time I upconvert to MPEG2/DVD rather than downconvert as in this case. Can anyone give me some pointers to get a better result? Thanks.

Dark Shikari
16th December 2010, 08:09
2800kbps CBR MPEG-2 is generally going to look pretty awful.

Blue_MiSfit
16th December 2010, 09:15
Looks like he's doing VBR to me, but not very smart VBR.

I'd set minrate to 500k, maxrate to 9000k, and avg to at least 4000k if possible... 2800 is very low for full resolution SD MPEG-2.

1h 34m should afford you at least 6mbps even on a DVD5. Why such a low bitrate?

Derek

mocham
18th December 2010, 11:17
Looks like he's doing VBR to me, but not very smart VBR.

I'd set minrate to 500k, maxrate to 9000k, and avg to at least 4000k if possible... 2800 is very low for full resolution SD MPEG-2.

1h 34m should afford you at least 6mbps even on a DVD5. Why such a low bitrate?

Derek

Thanks for the tips. I'm trying to keep the output size to around 2.1 GB to fit other movies on the disc.

I will try your suggestions above, but do you know of any options that reduce blockyness or are you saying that it could be because of the way I specified the VBR rates? I will try anyway and let you know.

nm
18th December 2010, 12:20
I will try your suggestions above, but do you know of any options that reduce blockyness or are you saying that it could be because of the way I specified the VBR rates? I will try anyway and let you know.

The problem is most likely caused by your -minrate 2800k -maxrate 3200k settings that lead to CBR encoding when using -b 2800k. That's not enough for complex scenes.

Try Blue_MisFit's settings with your average bitrate of 2800 kbps. And use 2-pass encoding if you want high-quality output at a fixed size!

mocham
18th December 2010, 20:11
I reencoded using Blue_MisFit's tips and it worked, no blockiness. I was misunderstanding how VBR should be setup.

Regarding 2 pass mode, I also kind of forgot about using this. Can you confirm that my understanding of it is correct per below example? Is the -fs necessary to get the target filesize, or just use the bitrate to control it?

Pass 1:
ffmpeg -i INPUT.mp4 -f dvd -fs 2200000000 -vcodec mpeg2video -s 720x462 -aspect 16:9 -vf "pad=720:480:0:9" -b 2800k -minrate 500k -maxrate 9000k -bufsize 1835k -g 12 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -bf 2 -flags qprd -flags mv0 -flags2 skiprd -an -pass 1 -y /dev/null

Pass 2:
ffmpeg -i INPUT.mp4 -f dvd -fs 2200000000 -vcodec mpeg2video -s 720x462 -aspect 16:9 -vf "pad=720:480:0:9" -b 2800k -minrate 500k -maxrate 9000k -bufsize 1835k -g 12 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -bf 2 -flags qprd -flags mv0 -flags2 skiprd -pass 2 OUTPUT.mpg

Edit: -fs appears to only truncate the output file.. So how does one specify a fixed output size?

nm
19th December 2010, 01:22
Edit: -fs appears to only truncate the output file.. So how does one specify a fixed output size?

By specifying video and audio bitrates. Video bitrate needs to be calculated from the desired file size and movie length, subtracting audio bitrate.

There will also be some overhead in the MPEG-PS format that you might need to consider.