Log in

View Full Version : seeking advice using ffmpeg to convert mp4 to mpeg2 for PAL DVD


hydra3333
13th January 2015, 17:45
Hello. Seeking a bit of advice on an ffmpeg commandline to downscale/upscale/bar-ize/convert a bunch of generally low-res arbitrary-sized old mp4's (free stuff) into mpeg2 files for burning to a PAL DVD, for an elderly relative's DVD player ...

The .bat file (code below) produces mpeg2 files.
The ffmpeg settings were "borrowed" from googling (I originally used -target pal-dvd however that over-rode some of the other ffmpeg settings so I had to desist and code the equivalent ffmpeg switches manually after finding out what they were) .

However,
- I'm not sure the output files are fully PAL DVD compatible... any advice ?
- I have not specified interlacing so is that going to be an issue ? If so, I guess I'll have to find the switches to convert it to TFF interlaced
(I will try to burn them tomorrow and see what happens)
- Are there any ffmpeg filters you would recommend to, say, sharpen and maybe denoise a bit ?

I could easily do it and a lot of other things in avisynth, but I'm not sure how to open an .mp4 (sheepish sigh).

@echo on
REM set width=720
REM set height=480
REM set fps=29.97

set width=720
set height=576
set fps=25

del ".\mi.txt"
for %%y in ("*.mp4") do (
call :fred "%%y"
)
del ".\mi.txt"
exit

:fred
SETLOCAL ENABLEDELAYEDEXPANSION
"c:\software\mediainfo\mediainfo.exe" --Inform=Video;%%AspectRatio/String%% "%~1" > ".\mi.txt"
set /p ar= < ".\mi.txt"
REM echo ar=!ar!
REM do a straight 16:9 conversion to %width%x%height%
if "!ar!" == "16:9" "C:\SOFTWARE\ffmpeg\bin\ffmpeg.exe" -i "%~1" -c:v mpeg2video -pix_fmt yuv420p -g 15 -bufsize 1835008 -maxrate 8000000 -packetsize 2048 -muxrate 10080000 -q:v 0 -vf scale="%width%:%height%" -aspect 16:9 -sws_flags lanczos+full_chroma_int -r %fps% -c:a mp2 -ac 2 -ab 224k -ar 44100 -y "%~1.mpg"
REM else do a preserve-aspect-ratio scale and pad
if NOT "!ar!" == "16:9" "C:\SOFTWARE\ffmpeg\bin\ffmpeg.exe" -i "%~1" -c:v mpeg2video -pix_fmt yuv420p -g 15 -bufsize 1835008 -maxrate 8000000 -packetsize 2048 -muxrate 10080000 -q:v 0 -vf scale="'if(gte(a,4/3),%width%,-1)':'if(gt(a,4/3),-1,%height%)'",pad="%width%:%height%:(%width%-iw)/2:(%height%-ih)/2" -aspect 4:3 -sws_flags lanczos+full_chroma_int -r %fps% -c:a mp2 -ac 2 -ab 224k -ar 44100 -y "%~1.mpg"
goto :eof

manolito
16th January 2015, 03:07
Well, I am not an ffmpeg specialist, but since nobody has answered for 3 days, I do have some remarks:

You use a constant quantizer of 0. Seems awfully low, I remember reading comments where a constant quantizer of 2 was recommended.

Your audio sample rate of 44100 is not DVD compliant, you need to use 48000. I would also recommend to use AC3 instead of MP2. (Your script provides the possibility to convert to NTSC, and for an NTSC DVD it is not compliant to just have a single MP2 audio track)

To encode in interlaced mode you need to add the following parameters:
-flags +ilme+ildct -alternate_scan 1 -top 1
for TFF and
-flags +ilme+ildct -alternate_scan 1 -top 0
for BFF sources.

This does not convert a progressive source to interlaced, it just forces interlaced motion estimation and DCT plus the alternate scan order, and it sets the correct field order flag.

To verify that your streams are really DVD compliant, my method of choice is to demux the MPEG2 file and author the elementary streams with MuxMan. If MuxMan has no problems with the streams then you can be almost 100% sure that everything is compliant.


Cheers
manolito

hydra3333
17th January 2015, 00:58
Thank you manolito. Good info, I'll keep that in mind.
For the various sources I received (mainly 1950's b+w stuff all of which had been "converted over time" well before it got to me), this part broke on occasion:
-vf scale="'if(gte(a,4/3),%width%,-1)':'if(gt(a,4/3),-1,%height%)'",pad="%width%:%height%:(%width%-iw)/2:(%height%-ih)/2"
due to various "insightful" croppings during the original conversions.
So, I ended up having to brute-force them using a combo of [avisynth and HC in conjunction with mediainfo and vbs and dos-batch] and cleaned them up a bit using Mdegrain2 and LSFmod while I was at it.
The result is a terrible kludge of a workflow, but it seems to work close enough.
Cheers