Log in

View Full Version : Create DVD compatible MPEG2 using FFMpeg


manolito
22nd March 2016, 15:45
Any FFMpeg specialists out there?

After spending a couple of hours reading docs and googling for advice I figured that I might get some better answers here... :devil:

My questions are about FFMpeg default values if I specify "-c:v mpeg2video" AND "-f mpeg2video" in my command line.

First question:
Is specifying "-f mpeg2video" in addidtion to the codec redundant? Or does this parameter force some additional settings?

Next question:
If I explicitly specify values for GOP size, number of B-Frames and for DC precision (like "-dc 10 -g 12 -bf 2") then my encode will be significantly slower than if I just omit these parameters. For DC precision I found that the default is 0 which makes no sense for DVD. But the resulting MPEG2 file still seems to be 100% DVD compliant.

Does FFMpeg have some kind of "Auto Mode" if the "mpeg2video" parameter is used for the codec and/or for the format? And if so, which values will get used?


Cheers
manolito

kolak
25th March 2016, 15:20
Use HCenc. FFmpeg MPEG2 encoder is "strange".

manolito
25th March 2016, 17:25
Use HCenc. FFmpeg MPEG2 encoder is "strange".

Sorry, this is not an option... :devil:

The FFMpeg MPEG2 encoder may be strange, but it sure spits out excellent quality when using the right parameters.

I mainly need this information for my DVDStyler plugin (allows VBR and HQ encodes while DVDStyler by itself only does CBR).


Cheers
manolito

hank315
25th March 2016, 18:30
AFAIK "-f mpeg2video" is redundant if "-c:v mpeg2video" is already specified.

If I explicitly specify values for GOP size, number of B-Frames and for DC precision (like "-dc 10 -g 12 -bf 2") then my encode will be significantly slower than if I just omit these parameters.
If "-bf 2" is omitted you wil have a IPPPPPPPPPPPIPPPP... scheme, so no B-frames, it takes more time to generate the B-frames with "-bf 2" (IBBPBBPBBPBBIBBPBB... scheme)
Settings for dc and gop length will not have a large impact on encoding speed.

For DC precision I found that the default is 0 which makes no sense for DVD. But the resulting MPEG2 file still seems to be 100% DVD compliant.
The Intra DC coefficient is referred to as intra_dc_precision 0 - 3 which is 8 - 11 bits of precision respectively, tabel 7-4, H.262 standard 02-2000. (http://hank315.nl/files/files/dc7-4.png)
Default in FFMPEG is "-dc 8" which is intra_dc_precision 0.

poisondeathray
25th March 2016, 20:56
The FFMpeg MPEG2 encoder may be strange, but it sure spits out excellent quality when using the right parameters.


Really ? What parameters are you referring to ?

Did something change recently ? Used to produce terrible quality with any settings. No soft pulldown either for "24p" scenarios.

manolito
25th March 2016, 23:35
Thanks very much Hank for the explanations... :thanks:

Makes things a lot clearer for me.
I did not know that FFMpeg by default does not create any B-Frames at all. All MPG2 encoders I have used so far do create B-Frames by default, so I thought that this is an agreed standard for MPEG2. While B-Frames might not be that useful for very high bitrates, they certainly make sense for medium and lower bitrates.


@ poisondeathray

The followqing two-pass parameters (courtesy of Fishman0919) do produce excellent results, at least for bitrates of 3500 and below. According to Fishman the results are superior to HCenc.

ffmpeg.exe -i # -aspect # -dc 10 -g 12 -maxrate 8000k -q:v 2 -b_strategy 2 -brd_scale 2 -bf 2 -profile:v 4 -intra_matrix "8,16,19,22,26,27,29,34,16,16,22,24,27,29,34,37,19,22,26,27,29,34,34,38,22,22,26,27,29,34,37,40,22,26,27,29,32,35,40,48,26,27,29,32,35,40,48,58,26,27,29,34,38,46,56,69,27,29,35,38,46,56,69,83" -inter_matrix "16,17,18,19,20,21,22,23,17,18,19,20,21,22,23,24,18,19,20,21,22,23,24,25,19,20,21,22,23,24,26,27,20,21,22,23,25,26,27,28,21,22,23,24,26,27,28,30,22,23,24,26,27,28,30,31,23,24,25,27,28,30,31,33" -pass 1 -passlogfile "ffmpeg" -an -c:v mpeg2video pass1.m2v"

ffmpeg.exe -i # -aspect # -dc 10 -g 12 -lmin 0.75 -mblmin 50 -qmin 1 -qmax 31 -maxrate 8000k -b:v 3500k -bf 2 -pre_dia_size 5 -dia_size 5 -qcomp 0.7 -qblur 0 -preme 2 -me_method dia -sc_threshold 0 -sc_factor 4 -bidir_refine 4 -profile:v 4 -mbd rd -mbcmp satd -precmp satd -cmp satd -subcmp satd -skipcmp satd -intra_matrix "8,16,19,22,26,27,29,34,16,16,22,24,27,29,34,37,19,22,26,27,29,34,34,38,22,22,26,27,29,34,37,40,22,26,27,29,32,35,40,48,26,27,29,32,35,40,48,58,26,27,29,34,38,46,56,69,27,29,35,38,46,56,69,83" -inter_matrix "16,17,18,19,20,21,22,23,17,18,19,20,21,22,23,24,18,19,20,21,22,23,24,25,19,20,21,22,23,24,26,27,20,21,22,23,25,26,27,28,21,22,23,24,26,27,28,30,22,23,24,26,27,28,30,31,23,24,25,27,28,30,31,33" -pass 2 -passlogfile "ffmpeg" -an -c:v mpeg2video out.m2v

Just replace the # characters with your own values, maybe play with the bitrate...

For soft pulldown you can use DGPulldown.


Cheers
manolito

manolito
26th March 2016, 13:34
The Intra DC coefficient is referred to as intra_dc_precision 0 - 3 which is 8 - 11 bits of precision respectively, tabel 7-4, H.262 standard 02-2000. (http://hank315.nl/files/files/dc7-4.png)
Default in FFMPEG is "-dc 8" which is intra_dc_precision 0.

The table you linked to did confuse me a little. This looks like I will have to adjust all "-dc" commands for FFMpeg by subtracting 8 from the existing value.

Luckily this is not the case. I did a few test encodes using either "-dc 10" or "-dc 2", and in both cases a DC Precision value of 10 was reported (by MediaInfo and Restream). Seems like FFMpeg internally maps these values for MPEG2 encoding.

BTW the default for -dc is not 8, but 0...
-dc <int> E..V.... intra_dc_precision (from -8 to 16) (default 0)
(from the FFMpeg 3.0 help)


Cheers and thanks again
manolito