Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-2 Encoding

Reply
 
Thread Tools Search this Thread Display Modes
Old 28th May 2017, 21:13   #1  |  Link
pojke
Registered User
 
Join Date: May 2004
Posts: 47
Optimal encoding with FFmpeg for DVD

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.

Quote:
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:

Quote:
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.
pojke is offline   Reply With Quote
Old 28th May 2017, 22:32   #2  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
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:

Code:
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:

Code:
: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
manolito is offline   Reply With Quote
Old 29th May 2017, 01:26   #3  |  Link
pojke
Registered User
 
Join Date: May 2004
Posts: 47
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.
pojke is offline   Reply With Quote
Old 29th May 2017, 01:48   #4  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
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
manolito is offline   Reply With Quote
Old 29th May 2017, 03:20   #5  |  Link
pojke
Registered User
 
Join Date: May 2004
Posts: 47
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:

Quote:
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
pojke is offline   Reply With Quote
Old 29th May 2017, 21:03   #6  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Alright, here are the FFmpeg calls for a 2-pass VBR encode using parameters for "Extremely High Quality".


Convert.bat
Code:
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

Last edited by manolito; 11th September 2019 at 15:12.
manolito is offline   Reply With Quote
Old 30th May 2017, 17:24   #7  |  Link
pojke
Registered User
 
Join Date: May 2004
Posts: 47
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?
pojke is offline   Reply With Quote
Old 30th May 2017, 22:46   #8  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Good to hear that it works for you...

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
Code:
@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
manolito is offline   Reply With Quote
Old 31st May 2017, 02:54   #9  |  Link
pojke
Registered User
 
Join Date: May 2004
Posts: 47
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?
pojke is offline   Reply With Quote
Old 31st May 2017, 04:12   #10  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Quote:
Originally Posted by pojke View Post
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...

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
manolito is offline   Reply With Quote
Old 31st May 2017, 06:37   #11  |  Link
pojke
Registered User
 
Join Date: May 2004
Posts: 47
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.
pojke is offline   Reply With Quote
Old 4th June 2017, 00:14   #12  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
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:

Code:
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.
__________________
By law and justice!

GMJCZP's Arsenal

Last edited by GMJCZP; 6th June 2017 at 21:06. Reason: Added the parameter -g 12 (for video input of 23.976 fps only)
GMJCZP is offline   Reply With Quote
Old 4th June 2017, 04:20   #13  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Hi GMJCZP,

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

You really use a negative value for sc_threshold?
Quote:
-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
manolito is offline   Reply With Quote
Old 5th June 2017, 01:04   #14  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
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.
__________________
By law and justice!

GMJCZP's Arsenal
GMJCZP is offline   Reply With Quote
Old 5th June 2017, 13:14   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by GMJCZP View Post
When I use negative of sc_threshold values I'm actually mimicking the performance of HCEncoder.
Nifty little trick GMJCZP, nice one
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 5th June 2017, 16:33   #16  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
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.
__________________
By law and justice!

GMJCZP's Arsenal

Last edited by GMJCZP; 5th June 2017 at 16:54.
GMJCZP is offline   Reply With Quote
Old 6th June 2017, 11:43   #17  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
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

Last edited by manolito; 7th June 2017 at 16:22.
manolito is offline   Reply With Quote
Old 6th June 2017, 12:41   #18  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
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):

Quote:
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?
__________________
By law and justice!

GMJCZP's Arsenal

Last edited by GMJCZP; 6th June 2017 at 13:19.
GMJCZP is offline   Reply With Quote
Old 6th June 2017, 15:48   #19  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Quote:
Originally Posted by GMJCZP View Post
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...

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


Quote:
Originally Posted by GMJCZP View Post
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

Last edited by manolito; 6th June 2017 at 16:17.
manolito is offline   Reply With Quote
Old 6th June 2017, 20:39   #20  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
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.

Quote:
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.

Quote:
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.
__________________
By law and justice!

GMJCZP's Arsenal

Last edited by GMJCZP; 6th June 2017 at 21:10.
GMJCZP is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:25.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.