- 
	
	
	
		FFMPEG Command Line Best Results? 
		Hi, how can I get the best (or good) results with FFMPEG command line MPEG-2 Video codec?  I want to keep the bitrate at 5000kbps.  I know 5000kbps is low for MPEG-2, I don't want a perfect picture, I just want it to look better.  Here's my code.
 
 
	Quote: 
		 
 for %%a in ("*.*") do ffmpeg -i "%%a" -s 704x576 -pix_fmt yuv420p -r 25 -codec:v mpeg2_qsv -vf setfield=tff -flags +ilme+ildct -g 1 -b:v 5000k -minrate:v 0k -maxrate:v 9000k -bufsize:v 1835008 -scan_offset 1 -ar 48000 -acodec ac3 -b:a 384k -f dvd -muxrate 10080k -packetsize 2048 "DVD %%~na.vob"
 pause
 
 
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		The -g 1 is a big problem and likely your main issue, that means intra encoding (no p, b frames) . You would need many times more bitrate for it to look ok
 
 Use -g 15 for PAL dvd
 
 You can try multipass encoding too
 
 You can look at this thread for supposedly optimal ffmpeg mpeg2 encoding. (But the results are still worse than other mpeg2 encoders)
 http://forum.doom9.org/showthread.php?t=174620
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		Thanks for that tip, the video looks better using -g 15.  But now I can't control my bitrate (outputting around 4000kbps no matter what my bitrate setting is). 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		
	Quote: 
		
 
				Originally Posted by  shampistols69  
Thanks for that tip, the video looks better using -g 15.  But now I can't control my bitrate (outputting around 4000kbps no matter what my bitrate setting is). 
 
 
 Not sure, you're using mpeg2_qsv the intel quick sync encoder, not the software mpeg2 ffmpeg encoder - maybe it's a  limitation ? Try -c:v mpeg2video for the software encoder
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		To get the requested bitrate you have to use two pass encoding (I don't think the mpeg2_qsv encoder supports this).  Or you can try setting the min, max, and average all to the same 5000k. 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		Thanks. My results are much better now. 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		So what are you doing now?  Which "solution" did you pick? 
 
- 
	
	
		2 Attachment(s) Re: FFMPEG Command Line Best Results? 
		for %%a in ("*.*") do ffmpeg -i "%%a" -s 720x576 -pix_fmt yuv420p -r 25 -codec:v mpeg2video -vf setfield=tff -flags +ilme+ildct -g 15 -b:v 5000k -minrate:v 5000k -maxrate:v 5000k -bufsize:v 1835008 -scan_offset 1 -ar 48000 -acodec ac3 -b:a 384k -f dvd -muxrate 10080k -packetsize 2048 "DVD %%~na.vob"
 pause
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		@ shampistols69.
 Did the last code give you the results you wanted ?
 The 5000 bitrate for example.
 
 Since the change in the g setting helped.
 Try using twice the framerate for this.
 From the code you posted with -r 25 that would be -g 50.
 
 You might read this topic also:
 https://forum.videohelp.com/threads/404452-How-to-use-ffmpeg-to-de-telecine-%28de-inte...PAL-to-PAL-25p
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		So you switched to the software encoder and constant bitrate.  If you want better overall quality you should switch to 2-pass encoding.  That will get you the size (bitrate) you want with bits allocated as needed (ie, shots that need more than 5000 kbps will get more, shots that need less will get less, but all will remain between the specified min and max bitrates).  So, run ffmpeg twice but add "-pass 1" to the first pass then "-pass 2" to the second. 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		
	Quote: 
		
 
				Originally Posted by  cholla  
Since the change in the g setting helped.
 Try using twice the framerate for this.
 From the code you posted with -r 25 that would be -g 50.
 
 
 
 It appears he wants DVD compatible encoding so the GOP size is limited to 15 frames.
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		REPLY TO cholla
 
 That's confusing.
 
 Did you want me to change it to this?  It's not DVD compliant (50fps).  It made my screen crash and I had to restart my laptop.
 
 for %%a in ("*.*") do ffmpeg -i "%%a" -s 720x576 -pix_fmt yuv420p -r 50 -codec:v mpeg2video -vf setfield=tff -flags +ilme+ildct -g 50 -b:v 5000k -minrate:v 5000k -maxrate:v 5000k -bufsize:v 1835008 -scan_offset 1 -ar 48000 -acodec ac3 -b:a 384k -f dvd -muxrate 10080k -packetsize 2048 "DVD %%~na.vob"
 pause
 
 Keeping 25fps and using -g higher than 15 didn't make any noticeable change to me.
 
 The code above your comment gave me consistent 5000kbps.  I'll attach a sample so you can see the result.  The source is progressive 25fps, I used the code to make it DVD compliant.
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		
	Quote: 
		
 
				Originally Posted by  jagabo  
So, run  ffmpeg twice but add "-pass 1" to the first pass then "-pass 2" to the second. 
 
 
 Thanks for the tip.  Are your DMs open?
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		
	Quote: 
		
 
				Originally Posted by  jagabo  
It appears he wants DVD compatible encoding so the GOP size is limited to 15 frames. 
 
 
 @jagabo,
 Is there a way to detect the -g used in a video ?
 More specifically a .vob
 
 If a software like AVStoDVD was use to create a DVD & "Keep MPEG2 DVD Compliant Video:" was checked.
 Would it correct the -g ?
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		
	Quote: 
		
 
				Originally Posted by  cholla  
Is there a way to detect the -g used in a video ?
 More specifically a .vob
 
 
 
 GSpot can show you the GOP structure of MPG and VOB files.  ffprobe can get you a list of frame types (I, B, P).
 
 
	Quote: 
		
 
				Originally Posted by  cholla  
If a software like  AVStoDVD was use to create a DVD & "Keep MPEG2 DVD Compliant Video:" was checked. 
Would it correct the -g ? 
 
 
 Probably.  I don't know about AVStoDVD in particular.
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		@shampistols69.
 I will take a look at the video samples you attached.
 Your last code has an -r 50 also that should have been left at -r 25 with the -g 50.
 But from what jagabo posted this is not DVD compliant.
 
 I got the -g 50 from some information about streaming.
 If you would like to read it:
 http://trac.ffmpeg.org/wiki/EncodingForStreamingSites
 
 jagabo is correct(nothing unusual about that)
 -g 15 for PAL or -g 18 for NTSC.
 
 @ jagabo, I have gspot & I took a look but I could not tell what -g was used in one of my video conversions.
 
 
- 
	
	
		1 Attachment(s) Re: FFMPEG Command Line Best Results? 
		
	Quote: 
		
 
				Originally Posted by  cholla  
..... I have  gspot & I took a look but I could not tell what -g was used in one of my video conversions. 
 
 
 Info about GOP Structure in GSpot (for mpeg2 only, like .mpg or .vob)
 
 See "Structure" in https://en.wikipedia.org/wiki/Group_of_pictures
 g corresponds to N.
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		Yes, the N=12 to the right of |I| <--> |I| is the GOP length.  If you press the VGS button to the left of the circled area you will get a dialog where you can see the frame types and other information:
 
  
 [Attachment 82415 - Click to enlarge]
 
 Red blocs are I frames, green blocks are B frames, blue blocks are P frames.
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		@ Sharc & jagabo.
 Thanks both worked to find the -g.
 
 @ shampistols69
 I worked on a code for you see if it looks better.
 I'm not saying it will but it might.
 The sample did not have audio but I left the audio you used in your code.
 It has a deinterlacer but MediaInfo still shows it as interlaced.
 
	Code: 
 ffmpeg -i "original.mp4" -vf "dejudder=cycle=4,scale=interl=1,setfield=tff,fieldmatch=mode=pc_n_ub:combmatch=full:combpel=80:cthresh=18,scale=720:576,bwdif=mode=0:deint=1:parity=1" -c:v mpeg2video -r 25 -pix_fmt yuv420p -flags +ilme+ildct -b:v 5000k -minrate:v 0 -maxrate:v 9000k -bufsize:v 1835008 -g 15 -acodec ac3 -b:a 384k -ar 48000  -f dvd -muxrate 10080k -packetsize 2048 original.vob
 
 
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		I don't really notice the difference 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		For progressive PAL (25 fps) something relatively simple like this will do; I added some light denoising, it may help in some situations.
 
	Code: 
 ffmpeg -i "S:\shorts\baloons_2.mp4" -aspect 16:9  -vf "hqdn3d=0.5:0.0:2.0:0.0,scale=720:576,chromanr=23" -c:v mpeg2video -r 25 -pix_fmt yuv420p -b:v 7000k -minrate:v 0 -maxrate:v 9000k -bufsize:v 1835008 -g 15 -acodec ac3 -b:a 384k -ar 48000  -f dvd -muxrate 10080k -packetsize 2048 baloons2.vob
 
 
 
 
- 
	
	
		1 Attachment(s) Re: FFMPEG Command Line Best Results? 
		"Progressive PAL" doesn't exist in reality IMO. Even when the content is progressive it should be encoded - or at least flagged - as interlaced to be PAL DVD compliant (PsF). I have never come across a "progressive PAL" DVD encoded and flagged as progressive, although most (DVD) players may probably play it (?).
 Just wondering if someone has ever seen a true "progressive PAL" DVD?
 
 Edit: Proposal for interlaced encoded 2-pass VBR, denoised as suggested by davexnet:
 
	Code: 
 ffmpeg -y -i "%~1" -c:v mpeg2video -b:v 5000k -maxrate 8000k -bf 2 -b_strategy 2 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -mpv_flags qp_rd -flags +ilme+ildct -vf hqdn3d=0.5:0.0:2.0:0.0,crop=1440:1080,scale=720:576,setfield=tff,setsar=16/15 -c:a ac3 -sn -pass 1 "%~1_.vob"
 ffmpeg -y -i "%~1" -c:v mpeg2video -b:v 5000k -maxrate 8000k -bf 2 -b_strategy 2 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -mpv_flags qp_rd -flags +ilme+ildct -vf hqdn3d=0.5:0.0:2.0:0.0,crop=1440:1080,scale=720:576,setfield=tff,setsar=16/15 -c:a ac3 -sn -pass 2 "%~1_.vob"
 
 
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		My Phillips-DVP DVD player (PAL & NTSC compliant) can play PAL progressive.  I make my DVDs with DVDStyler and used progressive PAL all the time. 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		Sharc I think you're technically right, however is it a problem
 In practice?. I don't remember avstodvd having an issue reported by any
 users related to this over the years
 
 
- 
	
	
	
		Re: FFMPEG Command Line Best Results? 
		I only have 2 PAL DVDs.
 Both are Written or burned & not commercial.
 One was done by Nero .
 This one has a nice printed label.
 It shows as Interlaced.
 
 The other is a Sintel/Big Bunny I got off the Internet.It was done in 2012 so I do not remember if I converted it to DVD formatted folders.
 It shows to be written by ImgBurn.
 It shows as progressive.