Log in

View Full Version : Optimal encoding with FFmpeg for DVD


Pages : [1] 2

pojke
28th May 2017, 21:13
I want to convert mp4 videos (typically around 135 mins) to mpeg2 with best quality possible while still fitting on single layer DVDs.
I found the parameter below in another thread (https://forum.doom9.org/showthread.php?t=173076).

ffmpeg -i clip.mp4 -f dvd -c:v:0 mpeg2video -bf 2 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -intra_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -inter_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -aspect 16:9 -s 720x480 -r 25 -g 15 -b:v:0 8000000 -maxrate:v:0 8500000 -qmin 1 -lmin 175 -bufsize:v:0 1835008 -packetsize 2048 -muxrate 10080000 -b:a 192000 -ar 48000 -c:a:0 ac3 -map 0:v -map 0:a -map -0:s clip.mpg

but the comment there was that its matrix was "suitable for very high bitrates."

I experimented, comparing it to this WinFF DVD preset:

ffmpeg -i clip.mp4 -f dvd -target ntsc-dvd -r 30000/1001 -vf scale=720:480 -aspect 16:9 -vb 8000k -g 12 -mbd rd -trellis 1 -flags +mv0 -cmp 0 -subcmp 2 clip.mpg

The first parameter seems to work better because it actually produces a file close to the bitrate I specify while the winFF one doesn't.
But the first one produces a framerate of 25fps, and the 2nd one produces 29.97fps. Which is best for DVD? (my source files are 30fps).

Also, I've read that 2-pass encodes can be higher quality and will be sized fit the DVD more precisely. How do I specify in the parameter that it should be 2-pass?

I already know how to calculate bitrates and author DVDs, so ultimately I'm just looking for the optimum 2-pass VBR parameter for what I'd like to do.

manolito
28th May 2017, 22:32
Hi pojke,

I made ffmpeg_VBR plugins for AVStoDVD and for DVDStyler a while ago, both have the option to use an "Extremely High Quality" 2-pass VBR mode for FFmpeg. For DVDStyler my plugin is transparently integrated into the software, so this might be the easiest way to use this mode.

The FFmpeg parameters for this mode were basically developed by forum member Fishman0919, and they were optimized further with the help of some DVDStyler forum members.

If you prefer to use FFmpeg from the command line, here is the basic script:

ffmpeg.exe -i %in% %aspect% %threads% %filter% %size% %dc% -g 12 -bf 2 -maxrate 8000k -q:v 2 %first_hq% %CQM% -pass 1 -passlogfile "%out_path%ffmpeg" -an -c:v mpeg2video %il% "%out_path%pass1.m2v"

ffmpeg.exe -i %in% %aspect% %threads% %filter% %size% %dc% -g 12 -bf 2 -lmin 0.75 -mblmin 50 -qmin 1 -qmax 31 -maxrate 8000k -b:v %bitrate%k %second_hq% %CQM% -pass 2 -passlogfile "%out_path%ffmpeg" -an -c:v mpeg2video %il% %out%

Of course you need to resolve all the values for the variables, this part from the original batch file from AVStoDVD should give you the needed information:

:2pass
IF %bitrate% GTR 7990 SET bitrate=7990
IF EXIST "%out_path%ffmpeg*.log" DEL "%out_path%ffmpeg*.log"
IF EXIST "%out_path%pass1.m2v" DEL "%out_path%pass1.m2v"
IF [%interlaced%==[1 SET il=-flags +ilme+ildct -alternate_scan 1 -top 1
IF [%bff%==[1 SET il=-flags +ilme+ildct -alternate_scan 1 -top 0
IF NOT [%Force 2-pass VBR%==[1 IF NOT [%Force 2-pass VBR%==[2 IF EXIST "Fox New.txt" SET /P CQM=<"Fox New.txt"
IF NOT [%Force 2-pass VBR%==[1 SET first_hq=-b_strategy 2 -brd_scale 2 -profile:v 4
SET second_hq=-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
SET user_hq=%user_hq:-bf 2 =%
IF [%Force 2-pass VBR%==[2 SET second_hq=%user_hq%
IF [%Force 2-pass VBR%==[1 SET second_hq=


Cheers
manolito

pojke
29th May 2017, 01:26
Thanks, but I'm kind of lost with some of that because I'm not familiar with AVSTODVD or Styler. I like authoring DVDs with DVDLab Pro, so I'm not really looking for a complete solution. For this I just want to encode with command line FFmpeg.

I see now that it's your parameter that I quoted above. Is that particular one not best for what I'm doing? If not, could you put a modified one in the form that is accepted by the command line? I don't know what's meant by "%threads% %filter%" etc.

manolito
29th May 2017, 01:48
OK, you need to post your source properties (the MediaInfo information), plus the target DVD format (PAL or NTSC, progressive or interlaced, and the average video bitrate). I can then post an FFmpeg command line which will be adapted to your needs.


Cheers
manolito

pojke
29th May 2017, 03:20
It's an mp4 with a codec ID "isom". Audio is 112K AAC. I want to encode to NTSC (720x480) and I assume progressive (isn't that normal?). For the 1st video, the time is 2:13:05, so I calculated a bitrate of 4250 so that it would fit with 192K ac3 audio.

I didn't know the source mattered. I just plugged in the bitrate for video and audio, resolution and file name when trying the parameter I mentioned. Without the matrix stuff, it looked like this:

ffmpeg -i game.mp4 -f dvd -c:v:0 mpeg2video -bf 2 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -aspect 16:9 -s 720x480 -r 25 -g 15 -b:v:0 4250000 -maxrate:v:0 8500000 -qmin 1 -lmin 175 -bufsize:v:0 1835008 -packetsize 2048 -muxrate 10080000 -b:a 192000 -ar 48000 -c:a:0 ac3 -map 0:v -map 0:a -map -0:s game.mpg

manolito
29th May 2017, 21:03
Alright, here are the FFmpeg calls for a 2-pass VBR encode using parameters for "Extremely High Quality".


Convert.bat
ffmpeg.exe -i "I:\test.mp4" -f mpeg2video -c:v:0 mpeg2video -b_strategy 2 -brd_scale 2 -profile:v 4 -intra_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -inter_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -aspect 16:9 -s 720x480 -r 24000/1001 -g 12 -pix_fmt yuv420p -b:v:0 7990000 -maxrate:v:0 8000000 -dc 10 -bf 2 -q:v 2 -bufsize:v:0 1835008 -packetsize 2048 -muxrate 10080000 -vf scale=718:480,pad=720:480:1:0 -map 0:v:0 -an -passlogfile "I:\ffmpeg" -pass 1 -y "NUL.avi"


ffmpeg.exe -i "I:\test.mp4" -f mpeg2video -c:v:0 mpeg2video -pre_dia_size 5 -dia_size 5 -qcomp 0.7 -qblur 0 -preme 2 -me_method dia -sc_threshold 0 -bidir_refine 4 -profile:v 4 -mbd rd -mbcmp satd -precmp satd -cmp satd -subcmp satd -skipcmp satd -intra_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -inter_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -aspect 16:9 -s 720x480 -r 24000/1001 -g 12 -pix_fmt yuv420p -b:v:0 7990000 -maxrate:v:0 8000000 -dc 10 -bf 2 -lmin 0.75 -mblmin 50 -qmin 1 -bufsize:v:0 1835008 -packetsize 2048 -muxrate 10080000 -vf scale=718:480,pad=720:480:1:0 -map 0:v:0 -passlogfile "I:\ffmpeg" -pass 2 "I:\test.m2v" -f ac3 -b:a 192000 -ar 48000 -c:a:0 ac3 -map 0:a:0 "I:\test.ac3"

IF EXIST "I:\ffmpeg*.log" DEL "I:\ffmpeg*.log"


All the bold parts need to be modified for different sources and targets. This one is only for progressive sources. For target NTSC it encodes to 23.976 fps, pulldown must be added by your authoring application.

If your source file is 30fps progressive then you might get smoother results by replacing "24000/1001" with "30000/1001". This will avoid the fps conversion from 30fps to 23.976fps which is performed by FFmpeg by just dropping whole frames.

My test source had a frame size of 426x240, to keep the correct aspect ratio some padding was added using the "-vf scale" and "pad" parameters. You need to calculate these values manually for each different source. Depending on your source frame size you might be able to remove the whole "-vf" parameter.

You just need to save this code as a batch file and put this batch file into a folder where you have a current version of FFmpeg.


Good luck
manolito

pojke
30th May 2017, 17:24
Thank you! That seems to work well. The .bat file explanation was important. I had been using ffmpeg by pasting the parameters into the command line and couldn't figure out how to do that with 2 passes.

Some remaining questions:

The output bitrate was 4195 for my test clip, which is below the 4250 that I specified. Is such a difference normal? Less is OK, but I wouldn't want it to go over the DVD size.

Does the location of the passlog file matter? Can it be in a separate location from the source/output/ffmpeg ?

Is it possible to use the other method (pasting the parameter into the command line) with 2-pass encoding?

manolito
30th May 2017, 22:46
Good to hear that it works for you... :D

IMO the requested output bitrate is generally met quite well in FFmpeg 2-pass VBR mode. It did happen a couple of times for me that the bitrate was a little lower, and the reason was that the source movie had end credits which did not require many bits. FFmpeg did use a quantizer of 0 for these end credits, but it was not enough to bring the overall bitrate up to the requested value.

The passlog file can be anywhere on your HDD. Just don't delete it before finishing the second pass.

Pasting the FFmpeg params into the command line is possible, but not for both passes at once. You need to paste the params for the first pass first, then run the first pass. After the first pass has finished you can paste the params for the second pass and execute it.

I think using a batch file which runs both passes with one command is easier...

To make it even easier I modified the batch file for much better usability:

Convert.bat
@ECHO off

====================================================
SET aspect=16:9
SET size=720x480
REM SET vfilter=-vf scale=718:480,pad=720:480:1:0
SET framerate=29.97
SET VBitrate=8000k
SET logfile=%temp%\ffmpeg
SET ABitrate=192k
SET AChannels=2
====================================================






SET FF_DRIVE=%~d0
SET FF_PATH=%~p0
%FF_DRIVE%
CD "%FF_PATH%"
SET in="%~1"
SET in_path=%~dp1
SET in_name=%~n1
SET Vout="%in_path%%in_name%.m2v"
SET Aout="%in_path%%in_name%.ac3"


ffmpeg.exe -i %in% -f mpeg2video -c:v:0 mpeg2video -b_strategy 2 -brd_scale 2 -profile:v 4 -intra_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -inter_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -aspect %aspect% -s %size% -r %framerate% -g 12 -pix_fmt yuv420p -b:v:0 %VBitrate% -maxrate:v:0 8500000 -dc 10 -bf 2 -q:v 2 -bufsize:v:0 1835008 -packetsize 2048 -muxrate 10080000 %vfilter% -map 0:v:0 -an -passlogfile "%logfile%" -pass 1 -y "NUL.avi"


ffmpeg.exe -i %in% -f mpeg2video -c:v:0 mpeg2video -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,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -inter_matrix "8,8,9,9,10,10,11,11,8,9,9,10,10,11,11,12,9,9,10,10,11,11,12,12,9,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16" -aspect %aspect% -s %size% -r %framerate% -g 12 -pix_fmt yuv420p -b:v:0 %VBitrate% -maxrate:v:0 8500000 -dc 10 -bf 2 -lmin 0.75 -mblmin 50 -qmin 1 -bufsize:v:0 1835008 -packetsize 2048 -muxrate 10080000 %vfilter% -map 0:v:0 -passlogfile "%logfile%" -pass 2 %Vout% -f ac3 -b:a %Abitrate% -ar 48000 -ac %AChannels% -c:a:0 ac3 -map 0:a:0 %Aout%

IF EXIST "%logfile%*.log" DEL "%logfile%*.log"


Now you can set all your parameters right at the top of the file. The input clip is the first (and only) parameter for the batch file. This makes it possible to Copy&Paste or Drag&Drop the input clip on the batch file (or on a link to the batch file on your desktop).


Enjoy
manolito

pojke
31st May 2017, 02:54
I encoded the whole video this time. Everything looks great in MPC-HC, but there were some repeated errors in the command window during encoding at first:
"Past duration 0.xxxxx too large"
"rc buffer underflow"
"max bitrate possibly to small or try trellis with large lmax or increase qmax"

When loading the m2v into DVDLab it shows a warning that "open GOPs were detected," and explains that it may cause chapter points to be less precise. If that's the only flaw, it's not a big deal.

Are any those things important enough to require corrections?


I'm totally unfamiliar with the syntax in the batch, especially the significance of the "%" symbol. It's part of what confused me earlier. Should they remain or are they removed when values are inserted? Same for the "~" and quotation marks. I'm wondering what the "SET section would look like after being filled in.

And after setting those, is the parameter section left exactly as is?

manolito
31st May 2017, 04:12
Are any those things important enough to require corrections?

No, I don't think so...

Later FFmpeg versions got into the habit to introduce more and more warnings which largely can be ignored.

The first "Past duration too large" is very common for MP4 or FLV files from the Internet. I never saw any adverse effects.

The rc buffer underflow warning is something I have never seen so far, but if it was really a serious buffer underflow you would not be able to author the streams, the authoring application would refuse to author them.

The next warning "max bitrate possibly too small..." makes no sense at all. The max bitrate for both passes is set to 8500 kbps which is already a little high for FFmpeg (FFmpeg tends to overshoot the specified max bitrate). And the recommendation to use trellis or increase qmax is nonsense.

Trellis has a severe bug in the MPEG2 encoder which can totally screw up the result. And qmax is at the default of 31, it should not be set to a higher value.


The DVDLab message about open GOPs is also BS. The preferred and best way to encode for DVDs is to use open GOPs. It is true that chapter points could be shifted slightly to the next I-Frame during authoring, but this is rarely a problem. The only valid reason to use closed GOPs is if you are dealing with streams which have several angles.


Looks like you are not familiar with batch files... :p

I can't give you a complete tutorial, but the use of the % sign is easy to explain.

At the top of the script some variables are set. This is done with the SET command:
SET my_var= blablabla

Later in the script you can reference this variable by using the variable name enclosed in % characters.
She said: %my_var% would be resolved to
She said: blablabla

Quotation marks in batch files must be used for strings which contain special characters like spaces. In this batch file we need to use it for file names with the full path like
c:\program files (x86)\ffmpeg\my file.mp4

The ~ character is a little more complicated, if you are curious there are quite a few batch file tutorials on the Internet.


Cheers
manolito

pojke
31st May 2017, 06:37
It's good to know I don't have to worry about the warnings. They have also shown up in the past during mp4 encodings.

You are correct, this is my first experience with batch files (other than clicking the ff-prompt.bat file). I'll try to learn more about the syntax and rules as it might be more convenient than what I've been doing.

Thanks for all the examples and explanations. Much appreciated.

GMJCZP
4th June 2017, 00:14
Hello manolito:

I was watching your configuration and I wonder if this way FFMPEG handles well the scenes with high movement. That's why I used the option -sc_threshold that gave me good results, like this, for example in a PC with 2 cores:

ffmpeg -i "C:\input.avs" -threads 2 -pass 1 -passlogfile Paso1.log -vcodec mpeg2video -b:v 2700000 -maxrate 9800000 -bufsize 1835000 -g 12 -bf 2 -sc_threshold -25000 -b_strategy 1 -b_sensitivity 10 -me_range 128 -mpv_flags mv0+skip_rd+naq -mv0_threshold 0 -mbd 2 -mbcmp 2 -precmp 2 -subcmp 2 -cmp 2 -dia_size 2 -pre_dia_size 2 -preme 2 -last_pred 3 -dc 8 -lmin 1.0 -qmin 1 -i_qoffset 1.0 -qcomp 0.60 -an -f rawvideo -y NUL

ffmpeg -i "C:\input.avs" -threads 2 -pass 2 -passlogfile Paso1.log -vcodec mpeg2video -b:v 2700000 -maxrate 9800000 -bufsize 1835000 -g 12 -bf 2 -sc_threshold -25000 -b_sensitivity 10 -me_range 128 -trellis 2 -mpv_flags cbp_rd+mv0+skip_rd+naq -mv0_threshold 0 -mbd 2 -mbcmp 2 -precmp 2 -subcmp 2 -cmp 2 -dia_size 2 -pre_dia_size 2 -preme 2 -last_pred 3 -dc 8 -lmin 1.0 -qmin 1 -i_qoffset 1.0 -qcomp 0.60 -aspect 4:3 -psnr -y "C:\video.m2v"

@pause

I would like your opinion not only to use -sc_threshold but all my settings. Thank you very much in advance.

manolito
4th June 2017, 04:20
Hi GMJCZP,

I am really no FFmpeg expert, I got all these advanced parameters from other users... :cool:

You really use a negative value for sc_threshold?
-sc_threshold -25000

The FFmpeg docs say that the range for sc_threshold is 0-100. No idea...

I made a few short test conversions using your parameters and mine, but I could not see too many differences (my script was slower).

Whatever, as usual you should use whatever works best for you, do some comparisons for sources you know well...


Cheers
manolito

GMJCZP
5th June 2017, 01:04
Thanks for answering me, manolito.

Using negative values of sc_threshold increases the appearance of I-frames, which appear mainly in scenes of high movement, while avoiding the macroblocks.

In summary my configuration focuses on two aspects:

- Avoid macroblocks (IMHO weak point of FFMPEG, scenes of high movement, that's why I like for low bitrates (<2500) to use HCEncoder)
- Encode with "reasonable speed".

Thanks again.

Edit: When I use negative of sc_threshold values I'm actually mimicking the performance of HCEncoder.

StainlessS
5th June 2017, 13:14
When I use negative of sc_threshold values I'm actually mimicking the performance of HCEncoder.

Nifty little trick GMJCZP, nice one :)

GMJCZP
5th June 2017, 16:33
Indeed, TinMan :)

I had to find a suitable value for sc_threshold and for b_sensitivity, given a specific bitrate, to match the proportion of I-P-B frames shed by HCEncoder, which IMHO is the world champion for low-bitrate encoding.

Edit: Beginning to code with Mencoder helped me find the sc_threshold option.

manolito
6th June 2017, 11:43
These GMJCZP parameters really got me excited. I did quite a few tests myself, but I always had a hard time picking an encode which I liked better. Old age probably...

So I made a quick and dirty test bench which makes it real easy to compare FFmpeg encodes made with either the Fishman XHQ parameters or the GMJCZP params. Download here:
http://www117.zippyshare.com/v/HVZbGHUT/file.html

Extract the files into a folder, then edit the "Convert.bat" file and enter your settings. Your input file can be entered by Copy&Paste or by Drag&Drop on the batch file.

The input file must have an audio track, a video only file will crash the script.


I modified the GMJCZP parameters slightly. The params for the first pass are from Fishman, the resulting log file worked well in my tests. I also forced the use of the "Fox New" matrix, the FFmpeg default matrix is not so nice IMO.

//EDIT//
I reuploaded a modified version of this test bench. This time the first pass params are separate, this makes sure that the GMJCZP B-Frame tweaks for the first pass are taken into account. Please redownload...


So everyone interested in optimizing FFmpeg for great quality DVD conversions please test some of your critical source files using this script and post your comments...


Cheers
manolito

GMJCZP
6th June 2017, 12:41
Thanks manolito.

I have not reviewed your contribution but it seems fantastic that the results of my experiments serve something, the creation of this post came to me like a finger ring for this moment has arrived. Thanks to pojke.

Edit: manolito, I check your script slightly, I understand that for b_sensitivity to work b_strategy must be set to 1 on the first pass.

Edit2: lol, according to the MPlayer manual (b_strategy<=>FFMpeg ; vb_strategy<=>MEncoder):

vb_strategy=<0−2> (pass one only)

strategy to choose between I/P/B-frames:

0
Always use the maximum number of B-frames (default).

1
Avoid B-frames in high motion scenes. See the b_sensitivity option to tune this strategy.

2
Places B-frames more or less optimally to yield maximum quality (slower). You may want to reduce the speed impact of this option by tuning the option brd_scale.


b_sensitivity=<any integer greater than 0>

Adjusts how sensitively vb_strategy=1 detects motion and avoids using B-frames (default: 40). Lower sensitivities will result in more B-frames. Using more B-frames usually improves PSNR, but too many B-frames can hurt quality in high-motion scenes. Unless there is an extremely high amount of motion, b_sensitivity can safely be lowered below the default; 10 is a reasonable value in most cases.


So putting brd_scale would no longer be necessary, unless you want to use b_strategy = 2, which changes things.

Edit3: manolito, the Fox New matrix is the one that provides the highest quality with high bitrates?

manolito
6th June 2017, 15:48
manolito, I check your script slightly, I understand that for b_sensitivity to work b_strategy must be set to 1 on the first pass.

I don't know, but so far I was under the impression that for the first pass most advanced parameters are not needed. The passlog file just gives a compression curve to the second pass (i.e. provides info about the compressibility of the source), and the b_sensitivity param in the second pass should not depend on the b_strategy param in the first pass. But maybe I am wrong... :o

Just saw that my second pass params use "-g 12 -bf 2". Doesn't this override any "b_sensitivity" param?


manolito, the Fox New matrix is the one that provides the highest quality with high bitrates?

This is one of the weirder things about these HQ params. The Fox New matrix comes from manono who extracted it from a commercial DVD, and it eats even more bitrate (and provides better details) than the classic Fox Home Theater matrix. And convential wisdom tells that this is a High Bitrate matrix.

When I was working with Fishman on the original XHQ parameters I suggested to use a matrix designed for lower bitrates, but his tests showed that the MPEG Adapted matrix worked better even for very low bitrates. And in the DVDStyler forum a member SilverSolver found that the Fox New matrix gave even better results than the MPEG Adapted matrix. So I made the Fox New matrix the standard for these XHQ params, and so far I found the results very good (and I got no complaints from forum members).


Cheers
manolito

GMJCZP
6th June 2017, 20:39
manolito, I think the thing is like this:

If b_strategy = 1 => set the value of b_sensitivity, setting the value of brd_scale is unnecessary
If b_strategy = 2 => set the value of brd_scale, setting the value of b_sensitivity is unnecessary.

Just saw that my second pass params use "-g 12 -bf 2". Doesn't this override any "b_sensitivity" param?

Not at all:

1) -g 12 means that the GOP (Group Of Frames) of I-frames in the frame structure is equal to 12 and applies only to an input video of 23,976 fps to which will do it 3:2 pulldown. So:

g = 12 => 3:2 pulldown
g = 15 => DVD PAL
g = 18 => DVD NTSC

By the way, I do not have it defined in the script above (post 12). As I do not remember having problems to not define it when using a video in AVS maybe is not mandatory to establish it, but it is a good practice to do so, so I will update the post.

2) -bf 2 means that the B-frames in the frame structure are equal to 2, and for standard DVD's it is mandatory. With b_sensitivity what you do is change the frequency with which the pair of B-frames will appear.

So I made the Fox New matrix the standard for these XHQ params, and so far I found the results very good (and I got no complaints from forum members).


Now I am the one who is excited, so this matrix is "the divine flame" when it comes to matrices. I will use it indistinctly from now on regardless of the value of the bitrate.

manolito
7th June 2017, 06:36
Thanks for the B-Frame strategy explanation, I think I understand it now. Well, one thing I still don't understand:
For the second pass b_strategy is not defined. Which means that the default b_strategy = 0 (max number of B_Frames) is used for the second pass. Does b_sensitivity have any effect at all if b_stragey is not = 1?
Adjusts how sensitively vb_strategy=1 detects motion and avoids using B-frames
What I want to say is that for the second pass b_strategy should be set to 1 if using b_sensitivity=10. If b_stragety is not set then b_sensitivity has no effect. Or am I misundestanding something here?

//EDIT//
Oops, I totally overlooked this one:
vb_strategy=<0−2> (pass one only)
So if b_strategy cannot be used for the second pass what does b_sensitivity actually do for the second pass?
I hate the FFmpeg documentation... :devil:


For the GOP size the FFmpeg default is 12 which I use anyways, no matter if my target is PAL, NTSC or Pulldown. Using a GOP size of 15 or 18 I found that the slightly better compression for larger GOP sizes does not make up for the loss in quality, especially for GOP 18. It would be nice if FFmpeg had an Auto-GOP feature like HCenc...


Cheers
manolito

manolito
7th June 2017, 09:53
After a couple of test conversions I can confirm that using the b_sensitivity parameter for the second pass has no effect at all. It should be removed from the second pass.

Otherwise comparing a couple of encodes using either the Fishman parameters or the GMJCZP parameters showed that generally the GMJCZP encodes had a lot less B-Frames. And these encodes also showed a very slight tendency to undersize. For the visual quality I still cannot point my fingers on any differences. Both encodes looked damn good to me.


Cheers
manolito


//EDIT//
I reuploaded a modified version of my test bench script here:
http://forum.doom9.org/showthread.php?p=1808832#post1808832
Please redownload...

GMJCZP
7th June 2017, 16:57
For the GOP size the FFmpeg default is 12

Thanks manolito.

Using a GOP size of 15 or 18 I found that the slightly better compression for larger GOP sizes does not make up for the loss in quality, especially for GOP 18. It would be nice if FFmpeg had an Auto-GOP feature like HCenc...

Set de GOP size change the frame structure, IMHO is more safe put g=12, 15 or 18, given the fps of the video input, and I agree with you that FFMPEG should also have the AUTOGOP feature. That's why I use sc_threshold and b_sensitivity for "manually" set the GOP and thus try to emulate the AUTOGOP function of HCEncoder.

For curiosity, here is a extract of the HCEncoder help:

*AUTOGOP
parameter goplength (8 – 18) type integer
Status not required
Default 15 (12 for 23.976 fps)
Example *AUTOGOP 12
This command sets the maximum GOP length to be used by the autogop algorithm.
Running in AUTOGOP mode means the encoder tries to distribute the I, P and B frames in an
optimal manner based on the activity of the frames.
Encoding using AUTOGOP will be DVD-compliant if the next values are used:
• For NTSC source to be pulldowned, use values 12 – 14.
• For PAL source a maximum value of 15 should be used.
• For 29.97 NTSC source the maximum of 18 can be used.

I hate the FFmpeg documentation...

Lol, I recommend the MPlayer help for these things.

I reuploaded a modified version of my test bench script

Thanks, I'll have a look at it.

GMJCZP
8th June 2017, 21:46
@echo off

@REM -----------------------------------------------------------------------------------------------
@REM
@REM FFMPEG MPEG2 Profile (video output only)
@REM GMJCZP, version 4.2, 27/06/2021
@REM
@REM -----------------------------------------------------------------------------------------------

@REM Script based in "DVDs ¿crees que tu codificador es el mejor ENTONCES DEMUÉSTRALO!!! (versión 2.0)" page 2, and tests of Fishman0919, manolito and mine
@REM Thanks to ALEX-KID, manono, Didée, hank315, Fishman0919 and manolito!



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Source and target files
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Source file (if source file is not a avs file then define for output file in the second pass frame size and frame rate, see Other settings)
set E_SRC="input.avs"

@REM Target file
set E_VID="video.m2v"



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Rate control settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Medium bitrate (b)
set E_BR=3000k

@REM Maximum Bitrate (maxrate) (Use 9800k max for DVD compatibility)
set VBV_MBR=9800k

@REM Maximum buffer size (bufsize) (Use 1835k max for DVD compatibility)
set VBV_MBS=1835k

@REM Fixed quality VBR (q) (Fishman0919's suggestion)
set E_FQ=2.0

@REM Minimum quantizer (qmin) (2 is good value for low bitrate, b<=1800k)
set E_MQ=1.0

@REM Minimum frame-level Lagrange multiplier (lmin) [0.01;255.0] (Fishman0919 suggests a value of 0.75)
set E_MLM=0.75

@REM Minimum macroblock-level Lagrange multiplier (mblmin) [0.01;255.0] (Fishman0919 suggests a value of 50.0)
set E_MBL=50.0

@REM Quantizer variability (qcomp) [0.00;1.00] (0.75 is good value) (Fishman0919 suggests a value of 0.7)
set E_VQ=0.70



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> GOP structure
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Maximum interval of I-frames or Keyframes (g) (Use 15 for DVD PAL, 18 for DVD NTSC, 12 for Pulldown)
set E_MIK=12

@REM Maximum number of B-frames (bf) [0;4] (Use 2 for DVD compatibility)
set E_MBF=2

@REM Adaptive B-Frames strategy (b_strategy) [0;2] (Pass one only, 0 is deactivated, 1 is fast and 2 is slow. Fishman0919 suggests a value of 2)
set E_ABF=2

@REM Slow adaptive refinement of B-frames (brd_scale) [0;3] (0 is full search, higher is faster; only valid if b_strategy=2. Fishman0919 suggests a value of 2)
set E_SBF=2

@REM Motion detection for B-frames (b_sensitivity) [>0] (Only valid if b_strategy=1)
set E_DBF=40

@REM Threshold for scene change detection (sc_threshold) [−1000000000;1000000000] (Negative values indicate that it is more likely to insert an I-frame when it detects a scene change)
set E_TSD=-30000



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Motion estimation settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Range for motion estimation (me_range) [0;9999]
set E_RME=0

@REM Optimization of rate distortion (mbd) [0;2] (2 is the best value)
set E_RDO=2

@REM Diamond size (and pre-pass too) (dia_size, pre_dia_size) [-99;6] (Negative values are for adaptive diamond)
set E_DIA=-4

@REM Comparison function for the macroblock decision (mbcmp) [0;2000] (0 is SAD, 1 is SSE2, 2 is SADT, +256 for chroma motion estimation, currently does not work (correctly) with B-frames)
set E_CMB=2

@REM Comparison function for pre pass, full, and sub motion estimation (precmp, subcmp, cmp) [0;2000] (0 is SAD, 1 is SSE2, 2 is SADT, +256 for chroma motion estimation, currently does not work (correctly) with B-frames)
set E_CMP=2

@REM Comparison function for frame skip (skip_cmp) [0;2000] (0 is SAD, 1 is SSE2, 2 is SADT, +256 for chroma motion estimation, currently does not work (correctly) with B-frames)
set E_CMS=2

@REM Amount of motion predictors (last_pred) [0;99]
set E_AMP=2



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Other settings
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM Aspect Ratio (aspect) (4/3 or 16/9 for DVD compatibility)
set E_DAR=4/3

@REM Frame size (s) (b up to 2500 kbps =>s=704x480 (NTSC), b greater than 2500 kbps =>s=720x480 (NTSC))
set E_SZE=720x480

@REM Frame rate (r) (use 25 for PAL, 24000/1001 or 30000/1001 para NTSC)
set E_FPS=24000/1001

@REM DC precision (dc) [8;10] (b up to 1800k =>dc=8, between 1800k and 3500k =>dc=9, greater than 3500k =>dc=10)
set E_DC=9



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> Matrices
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@REM MPEG (default matrix for any bitrate)
set E_INTRA=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
set E_INTER=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

@REM MPEG Standard (for any bitrate, the default matrix of FFMPEG, there are matrices better than this)
@REM set E_INTRA=08,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
@REM set E_INTER=16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16

@REM FOX New Matrix (manolito's suggestion, for bitrate>=3000k)
@REM set E_INTRA=08,08,09,09,10,10,11,11,08,09,09,10,10,11,11,12,09,09,10,10,11,11,12,12,09,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16
@REM set E_INTER=08,08,09,09,10,10,11,11,08,09,09,10,10,11,11,12,09,09,10,10,11,11,12,12,09,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16

@REM FOX Home Entertainment
@REM set E_INTRA=08,08,09,11,13,13,14,17,08,08,11,12,13,14,17,18,09,11,13,13,14,17,17,16,11,11,13,13,13,17,18,20,11,13,13,13,16,17,20,24,13,13,13,16,17,20,24,29,13,12,13,17,19,23,28,34,12,13,17,19,23,28,34,41
@REM set E_INTER=08,08,08,09,09,09,09,10,08,08,09,09,09,09,10,10,08,09,09,09,09,10,10,10,09,09,09,09,10,10,10,10,09,09,09,10,10,10,10,11,09,09,10,10,10,10,11,11,09,10,10,10,10,11,11,11,10,10,10,10,11,11,11,11

@REM FOX1
@REM set E_INTRA=08,08,09,11,13,13,14,17,08,08,11,12,13,14,17,18,09,11,13,13,14,17,17,19,11,11,13,13,14,17,18,20,11,13,13,14,16,17,20,24,13,13,14,16,17,20,24,29,13,13,14,17,19,23,28,34,13,14,17,19,23,28,34,41
@REM set E_INTER=08,08,08,09,09,09,09,10,08,08,09,09,09,09,10,10,08,09,09,09,09,10,10,10,09,09,09,09,10,10,10,10,09,09,09,10,10,10,10,11,09,09,10,10,10,10,11,11,09,10,10,10,10,11,11,11,10,10,10,10,11,11,11,11

@REM FOX2
@REM set E_INTRA=08,08,09,11,13,13,14,17,08,08,11,12,13,14,17,18,09,11,13,13,14,17,17,19,11,11,13,13,14,17,18,20,11,13,13,14,16,17,20,24,13,13,14,16,17,20,24,29,13,13,14,17,19,23,28,34,13,14,17,19,23,28,34,41
@REM set E_INTER=08,08,09,09,10,10,11,11,08,09,09,10,10,11,11,12,09,09,10,10,11,11,12,12,09,10,10,11,11,12,13,13,10,10,11,11,12,13,13,14,10,11,11,12,13,13,14,15,11,11,12,13,13,14,15,15,11,12,12,13,14,15,15,16

@REM FOX3
@REM set E_INTRA=08,08,09,11,13,13,14,17,08,08,11,12,13,14,17,18,09,11,13,13,14,17,17,19,11,11,13,13,14,17,18,20,11,13,13,14,16,17,20,24,13,13,14,16,17,20,24,29,13,13,14,17,19,23,28,34,13,14,17,19,23,28,34,41
@REM set E_INTER=16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16

@REM Didée's SixOfNine-HVS (HVS:Human Visual System, for bitrate>=3000k)
@REM set E_INTRA=08,11,12,12,13,15,16,17,11,11,12,12,14,15,16,17,12,12,13,14,15,16,17,18,12,12,14,16,17,18,19,19,13,14,15,17,19,20,20,20,15,15,16,18,20,21,22,22,16,16,17,19,21,22,23,24,17,17,18,19,20,22,24,24
@REM set E_INTER=12,11,12,12,13,14,15,16,11,11,12,12,13,14,14,16,12,12,12,13,14,15,16,17,12,12,13,15,16,17,18,18,13,13,14,16,18,19,19,20,14,14,15,17,19,20,22,22,15,14,16,18,19,22,23,24,16,16,17,18,20,22,24,24

@REM manono1 (the manono's favorite matrix)
@REM set E_INTRA=08,08,08,09,11,13,14,17,08,08,09,11,13,13,14,17,08,08,11,12,13,14,17,94,09,11,13,13,14,17,17,94,11,11,13,13,14,17,94,94,13,13,14,16,17,20,94,94,13,13,14,17,94,94,94,94,13,14,17,94,94,94,94,94
@REM set E_INTER=12,12,13,14,15,16,22,26,12,13,14,15,16,22,26,32,13,14,15,16,22,26,32,41,14,15,16,22,26,32,41,53,15,16,22,26,32,41,53,94,16,22,26,32,41,53,70,94,22,26,32,41,53,70,94,94,26,32,41,53,94,94,94,94

@REM manono2
@REM set E_INTRA=08,12,13,14,15,16,19,22,12,13,14,15,16,19,22,26,13,14,15,16,19,22,26,32,14,15,16,19,22,26,32,41,15,16,19,22,26,32,41,53,16,19,22,26,32,41,53,70,19,22,26,32,41,53,70,94,22,26,32,41,53,70,94,127
@REM set E_INTER=12,12,13,14,15,16,19,22,12,13,14,15,16,19,22,26,13,14,15,16,19,22,26,32,14,15,16,19,22,26,32,41,15,16,19,22,26,32,41,53,16,19,22,26,32,41,53,70,19,22,26,32,41,53,70,94,22,26,32,41,53,70,94,127

@REM manono3 (according to manono, for cases when the movie doesn't compress well at all)
@REM set E_INTRA=08,10,10,12,13,15,16,20,10,10,12,15,17,19,20,20,10,12,15,17,19,20,20,23,12,15,17,19,20,20,25,25,13,17,19,20,23,25,25,27,15,19,20,23,25,27,27,30,16,20,20,25,25,27,30,35,20,20,23,25,27,30,35,45
@REM set E_INTER=12,14,17,18,19,20,24,28,14,16,17,18,19,23,27,32,17,17,18,19,20,27,30,37,18,18,19,20,27,30,35,37,19,19,20,27,30,35,37,40,20,23,27,30,35,37,40,44,24,27,30,35,37,40,40,44,28,32,37,37,40,44,44,48

@REM HVS Best (for low bitrate)
@REM set E_INTRA=08,16,16,16,17,18,21,24,16,16,16,16,17,19,22,25,16,16,17,18,20,22,25,29,16,16,18,21,24,27,31,36,17,17,20,24,30,35,41,47,18,19,22,27,35,44,54,65,21,22,25,31,41,54,70,88,24,25,29,36,47,65,88,115
@REM set E_INTER=18,18,18,18,19,21,23,27,18,18,18,18,19,21,24,29,18,18,19,20,22,24,28,32,18,18,20,24,27,30,35,40,19,19,22,27,33,39,46,53,21,21,24,30,39,50,61,73,23,24,28,35,46,61,79,98,27,29,32,40,53,73,98,129

@REM AVAMAT7 (for low bitrate, also called AUTO-Q2)
@REM set E_INTRA=08,16,19,22,26,28,32,38,16,16,22,24,28,32,38,44,19,22,26,28,32,38,44,48,22,22,26,32,38,44,48,54,22,26,32,38,44,48,54,64,26,32,38,44,48,54,64,74,32,38,44,48,54,64,74,84,38,44,48,54,64,74,84,94
@REM set E_INTER=16,20,24,28,36,42,46,52,20,24,28,36,42,46,52,58,24,28,36,42,46,52,58,62,28,36,42,46,52,58,62,68,36,42,46,52,58,62,68,78,42,46,52,58,62,68,78,88,46,52,58,62,68,78,88,99,52,58,62,68,78,88,99,99



@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@REM >> FFMPEG CLI
@REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ECHO.---------------------------------------------------------------
ECHO.First pass ...
ECHO.---------------------------------------------------------------
ffmpeg.exe -i %E_SRC% -pass 1 -passlogfile Pass.log -vcodec mpeg2video -maxrate %VBV_MBR% -bufsize %VBV_MBS% -g %E_MIK% -bf %E_MBF% -bidir_refine 0 -b_strategy %E_ABF% -brd_scale %E_SBF% -b_sensitivity %E_DBF% -dc %E_DC% -q:v %E_FQ% -intra_vlc true -intra_matrix %E_INTRA% -inter_matrix %E_INTER% -an -f mpeg2video -y NUL


ECHO.---------------------------------------------------------------
ECHO.Second pass ...
ECHO.---------------------------------------------------------------
ffmpeg.exe -i %E_SRC% -pass 2 -passlogfile Pass.log -vcodec mpeg2video -b:v %E_BR% -maxrate %VBV_MBR% -bufsize %VBV_MBS% -g %E_MIK% -bf %E_MBF% -bidir_refine 0 -sc_threshold %E_TSD% -b_sensitivity %E_DBF% -me_range %E_RME% -mpv_flags mv0+naq -mv0_threshold 0 -mbd %E_RDO% -mbcmp %E_CMB% -precmp %E_CMP% -subcmp %E_CMP% -cmp %E_CMP% -skip_cmp %E_CMS% -dia_size %E_DIA% -pre_dia_size %E_DIA% -last_pred %E_AMP% -dc %E_DC% -lmin %E_MLM% -mblmin %E_MBL% -qmin %E_MQ% -qcomp %E_VQ% -intra_vlc true -intra_matrix %E_INTRA% -inter_matrix %E_INTER% -f mpeg2video -color_primaries 5 -color_trc 5 -colorspace 5 -color_range 1 -aspect %E_DAR% -y %E_VID%

IF EXIST "Pass*.log" DEL "Pass*.log"


@pause
@REM THE END

GMJCZP
10th June 2017, 15:46
Version 2.0 (10/06/2017): (https://forum.doom9.org/showthread.php?p=1809116#post1809116)

- Added Colorimetry and color range to MPEG values (SMPTE 170 M for FFMPEG) according to HCEncoder BT.470 BG and the program ReStream.
- Changed the following default values:
E_BR=1600000 (b) (for experimental purposes only)
E_VQ=0.70 (qcomp)
E_DBF=5 (b_sensitivity)
E_TSD=-60000 (sc_threshold)
E_AMP=3 (last_pred)
The default matrix is now HVS Best (b<1800 kbs) (the FOX New matrix is throwing visual defects, while this will not be used).
- Other minor changes

Fishman0919
17th June 2017, 14:23
These GMJCZP parameters really got me excited. I did quite a few tests myself, but I always had a hard time picking an encode which I liked better. Old age probably...

So I made a quick and dirty test bench which makes it real easy to compare FFmpeg encodes made with either the Fishman XHQ parameters or the GMJCZP params. Download here:
http://www117.zippyshare.com/v/HVZbGHUT/file.html

Extract the files into a folder, then edit the "Convert.bat" file and enter your settings. Your input file can be entered by Copy&Paste or by Drag&Drop on the batch file.

The input file must have an audio track, a video only file will crash the script.


I modified the GMJCZP parameters slightly. The params for the first pass are from Fishman, the resulting log file worked well in my tests. I also forced the use of the "Fox New" matrix, the FFmpeg default matrix is not so nice IMO.

//EDIT//
I reuploaded a modified version of this test bench. This time the first pass params are separate, this makes sure that the GMJCZP B-Frame tweaks for the first pass are taken into account. Please redownload...


So everyone interested in optimizing FFmpeg for great quality DVD conversions please test some of your critical source files using this script and post your comments...


Cheers
manolito

I did a quick test and PM you.

All the other test I did came out the same way.


I did a few quick test and I noticed right away detail missing and more macro blocking in GMJCZP videos.

I know comparing video with stills is not a true comparison but with this clip, it's like this thru the whole thing.

1) Where the wall is with the number "47", it should have good detail in it.

2) The windows above the gentlemen's left shoulder walking in the middle with a white shirt. The tree should have good detail. The tree in the video is waving in the wind and with GMJCZP video is very blocky.

3) You should be able to see the lines in the bricks in the walkway OK with Mepg2. With GMJCZP video, they are mostly washed out. MY video fairs a little better.


Original

http://i467.photobucket.com/albums/rr37/fishman0919/Org_zpszfg4yd9r.png (http://s467.photobucket.com/user/fishman0919/media/Org_zpszfg4yd9r.png.html)

Fishman

http://i467.photobucket.com/albums/rr37/fishman0919/fishman_zpsfum2fckl.png (http://s467.photobucket.com/user/fishman0919/media/fishman_zpsfum2fckl.png.html)

GMJCZP

http://i467.photobucket.com/albums/rr37/fishman0919/GMJCZP_zpsnsaw28yp.png (http://s467.photobucket.com/user/fishman0919/media/GMJCZP_zpsnsaw28yp.png.html)


Again, this was just a real quick test... I'll do a bit more this weekend.

manolito
17th June 2017, 15:11
Thanks very much Fishman... :thanks:

I had this suspicion before, it's good to have it confirmed by an expert.

So for me there is no reason to change my XHQ plugin parameters for AVStoDVD and for DVDStyler. Thanks again for taking the time to test this...


Cheers
manolito

GMJCZP
17th June 2017, 17:43
Version 3.0 (17/06/2017):
(https://forum.doom9.org/showthread.php?p=1809116#post1809116)
- Changed the ratecontrol method (rc_strategy). Now it's XVID control!
- Enabled intra_vlc tables for MPEG2 (intra_vlc) (as in HCEncoder)
- Changed the following default values:
E_BR=3000k (b) (Medium Bitrate)
E_DC=9 (dc) (As a consequence of the bitrate change, b)
E_DFQ=2.00 (qsquish) (Variable added)
E_RQA=2.00 (rc_qmod_amp) (Variable added)
E_MLM=236 (lmin)
E_MBL=236 (mblmin)
- The default matrix is now MPEG Standard (It is suggested to consider the other options according to the bitrate, see "Matrices" in "Other settings" section)
- Other cosmetic changes.

PD: IMHO now I can say that with version 3.0 of my script HCEncoder does have a rival to encode to low bitrates: FFMPEG!

manolito
18th June 2017, 13:51
And here comes the competition using Fishman's parameters:
http://www102.zippyshare.com/v/ivWYugog/file.html

Cheers
manolito

GMJCZP
19th June 2017, 03:23
I was trying the Fishman script which uses the Fox New matrix and does not throw visual flaws like my script. Although in itself is not relevant in the performance of FFMPEG I have to find out which or which parameters cause the problem.

GMJCZP
19th June 2017, 05:23
Version 3.1 (19/06/2017): (https://forum.doom9.org/showthread.php?p=1809116#post1809116)

- Removed the trellis parameter that caused visual artifacts when using the FOX New matrix (now its default value is 0). As a consequence of this the coding speed in the second pass has been increased.
- The FOX New matrix now suggests its use for bitrates greater than or equal to 1800k.

GMJCZP
21st June 2017, 17:43
Version 3.2 (21/06/2017): (https://forum.doom9.org/showthread.php?p=1809116#post1809116)

- Disabled for the first pass several parameters, so the encoding speed has been increased drastically.
- Added variable E_FQ (q) (Fishman0919 suggestion).
- Changed the following default values:
E_MLM = 0.75 (lmin)
E_MBL = 50.0 (mblmin)
E_RME = 0 (me_range)
- Other minor changes.

GMJCZP
30th June 2017, 14:59
Version 3.3 (30/06/2017): (https://forum.doom9.org/showthread.php?p=1809116#post1809116)

- Added variable E_DM (dark_mask) (Encoding enhancement in dark scenes).
- Other minor changes.

GMJCZP
30th June 2017, 16:44
Version 3.4 (30/06/2017): (https://forum.doom9.org/showthread.php?p=1809116#post1809116)

- Regression to rc_strategy = 0 (undersize problems), at least for now.

GMJCZP
11th July 2017, 13:43
Version 4.0 (11/07/2017): (https://forum.doom9.org/showthread.php?p=1809116#post1809116)

Several changes, the most important are:
- Changed by default b_strategy to 2, improving encoding in dark areas. This change has generated a domino effect on the GOP structure, including reducing the default value of sc_threshold to -30000.
- Changed the size of the diamond to -4, the negative value is to reduce the impact on the coding speed.
- Changed the default matrix, now it is MPEG.
- Also a group of matrices has been included to be applied depending on the bitrate, the source or the taste of each one.

WSC4
10th September 2019, 08:00
When using the -sc_factor in with these options, I get this error:

Unrecognised option 'sc_factor'.
Error splitting the argument list: Option not found

Also, if using the -me_method option, I get this error:

Codec AVOption me_method (Set motion estimation method) specified for output file #0 (out.mpg) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.

manolito
10th September 2019, 14:14
The FFMpeg devs removed the "sc_factor" param a while ago, so just delete it from your command line.

For the "me_method dia" I have no idea what exactly this error message means. But it never harmed my encodes so far, so I kept this parameter. It may be because of this:
https://trac.ffmpeg.org/ticket/6771


Cheers
manolito

WSC4
11th September 2019, 07:49
Thanks for your info on this.

I am using your code from post #6 (2-pass VBR encode using parameters for "Extremely High Quality")

I changed the -me_method dia to -motion-est dia and the same error displayed. I then used the -method ds option. This did not display that error.

https://ffmpeg.org/ffmpeg-all.html#mestimate

However, it is listed under video filters and I am not too sure I should be using it. It says:

Estimate and export motion vectors using block matching algorithms. Motion vectors are stored in frame side data to be used by other filters.

This filter accepts the following options:

method

Specify the motion estimation method. Accepts one of the following values:

I used the ds value.

What are your thoughts?

manolito
11th September 2019, 14:17
No idea, sorry... :confused:

Since this is just a non-fatal warning I will just ignore it. After reading a few posts about this "me_method" param my impression is that this global option was removed because each different encoder handles it differently. So there are now encoder specific options for motion estimation. After some user complaints the "me_method" param was reintroduced as an alias for the encoder specific option.

The warning probably means that this alias is not applicable for the MPEG2 encoder. IMO the worst thing which could happen is that the option is ignored and some default being used.

//EDIT/
I also updated my post #6 (removed the "sc_factor" param and reduced max bitrate from 8500 to 8000). This means of course that the average bitrate must be at least a little bit below 8000.

WSC4
11th October 2019, 02:48
Why did you reduce the bit rate?

Can I push the boundaries on this to the limit? I want to get the highest quality and highest bit rate possible.

In my settings, I have -b:v 9000k -maxrate:v 9800k

I have studied the DVD video standards that I found on the Internet, and it seems that the Maximum video bit rate is 9.8 Mbps. After system overhead, the maximum rate of combined elementary streams (audio + video + subpicture) is 10.08 Mb/s.

The video + audio with the FFmpeg encode came to the Overall bit rate: 10.0 Mb/s as shown via MediaInfo.

Is this OK?

manolito
11th October 2019, 04:59
The reason for reducing the max bitrate and also the max average bitrate is that the FFmpeg MPEG2 encoder still has a lousy rate control. Overshooting the specified max bitrate is very common (even the very old and deprecated QuEnc which is also based on libavcodec had this overshooting), and this can cause errors when multiplexing and authoring the encoded stream. You can check such a high bitrate encode by authoring it with MuxMan. If MuxMan does not choke on it then you are fine, but if it does choke then you should reencode the source with a lower bitrate and/or a different quant matrix.

Other MPEG2 encoders like CCE, HCenc or ProCoder do also overshoot, but to a much lesser degree than FFmpeg. Also these encoders seem to have a better VBV buffer control than FFmpeg so you only get muxing and authoring errors very rarely.

kolak
15th October 2019, 19:53
CCE basically never. Probably has the best rate control from any DVD compliant encoder.

manolito
16th October 2019, 07:30
I only have some experience with CCE 2.50 up to 2.70 (switched to HCenc afterwards), but I do remember that these versions did overshoot the specified max bitrate in many cases. The MuxMan log file shows the peak bitrates, so this was easy to see. But this never caused Mplex and DVDAuthor to choke on these encodes (contrary to encodes made with libavcodec).

kolak
16th October 2019, 22:16
Not sure about MuxMan, but I take Scenarist as reference muxer for DVD (it's very picky one) and I had basically 0 problems (done encodes in thousands over 8 years with 2.7 and SP3).
It's not about very short peaks, but properly calculated ones which take into account all DVD muxing restrictions.
ProCoder was ok, but not as good.

WSC4
22nd October 2019, 09:39
Sorry, I forgot to subscribe to this thread and have just seen these replies.

I found a number of bit rate viewers to install, and here are the results of my FFmpeg encode which is video + audio.

http://members.optusnet.com.au/wsc3/Bitrate%20Viewer.png The Bitrate Viewer shows a maximum short peak of 10698 kbps at 2:33 time.

http://members.optusnet.com.au/wsc3/MPEG-2%20Validator.gif MPEG-2 Validator shows a maximum short peak of 10447 kbps at 154 seconds. The average bit-rate is 8750 kb/s

The programs you mention may fail my bit rates, but what about real-time tests on modern DVD players today? Will a DVD player stop, pause, start, show pixelation or show an error on the screen or just not play at all?

I do not have a dedicated DVD player, only a modern, high-end Blu-ray player. Testing on this would be unfair.

manolito
22nd October 2019, 11:28
Just dug out some very old threads about this problem. The problem is not only the encoder, the muxing and the authoring applications are just as important.

Have a look at this thread:
https://forum.doom9.org/showthread.php?p=739319#post739319
and especially this post:
https://forum.doom9.org/showthread.php?p=743503#post743503

Of course when using a modern BD player for playback you probably won't get any stutter even with a DVD which is outside of the specs. But I would not recommend to simply ignore the specs.

For me the ultimate (and free) DVD compliance checker is the latest free version of MuxMan (just as picky as Scenarist, but I cannot afford Scenarist). Mplex/DVDAuthor and FFmpeg/DVDAuthor are far less reliable in my experience.

kolak
1st November 2019, 22:28
Sorry, I forgot to subscribe to this thread and have just seen these replies.

I found a number of bit rate viewers to install, and here are the results of my FFmpeg encode which is video + audio.

http://members.optusnet.com.au/wsc3/Bitrate%20Viewer.png The Bitrate Viewer shows a maximum short peak of 10698 kbps at 2:33 time.

http://members.optusnet.com.au/wsc3/MPEG-2%20Validator.gif MPEG-2 Validator shows a maximum short peak of 10447 kbps at 154 seconds. The average bit-rate is 8750 kb/s

The programs you mention may fail my bit rates, but what about real-time tests on modern DVD players today? Will a DVD player stop, pause, start, show pixelation or show an error on the screen or just not play at all?

I do not have a dedicated DVD player, only a modern, high-end Blu-ray player. Testing on this would be unfair.

Those bitrate viewers are most often not very good and they don't take into account whole VBV model. Spikes above 10Mbit are fine if they are very short.

WSC4
17th April 2020, 10:10
Hi Manolito, Has there been any update to your parameters that you posted here:

https://forum.doom9.org/showthread.php?p=1808247#post1808247

I need to use your commands to encode an interlaced MPEG video to progressive, what are you thoughts on FFmpeg's YADIF or the new FFmpeg BWDIF deinterlacer? I have seen reports that it is better than YADIF, which is pretty old now.

manolito
17th April 2020, 12:26
No, there is no update, these are still the parameters I use... :)

And I have no idea if Yadif or BWDIF give better deinterlacing results. I tried them both, and the quality looked pretty much the same to me. When making DVDs I usually do not bother to deinterlace interlaced sources. My ancient CRT TV displays interlaced content perfectly, and to tell ffmpeg to encode in interlaced mode all you have to do is add these params to the command line:
-flags +ilme+ildct -alternate_scan 1 -top 1
(This is for a TFF source file, for BFF use -top 0).


Cheers
manolito

GMJCZP
29th May 2021, 04:39
Version 4.1 (28/05/2021): (https://forum.doom9.org/showthread.php?p=1809116#post1809116)

- Eliminated sc_factor because changes in FFMpeg 4.