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 ... (also posted over at doom9)
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).
Code:@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
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 11 of 11
Thread
-
-
-
Thank you. That link is for is a gui program.
I needed something like a .bat file which I can copy into a folder of MP4s and just run it, and it figures out what adjustments to make.
The updated brute-force crappy-code .bat file below is based on the ffmpeg commandline and
- takes progressive .mp4 input files and
- creates TFF interlaced PAL DVD-spec mpeg2 output files in a sub-folder
- resizes using lanczos and centers and pads with black bars to 4:3 if necessary (ie if not 16:9 input)
- adjusts volumes to a reference -18
Can anyone provide advice on ffmpeg filters you would recommend to, say, sharpen and maybe denoise a bit during conversion ?
Code:@echo on set mediainfo_path=c:\software\mediainfo\mediainfo.exe set ffmpeg_path=C:\SOFTWARE\ffmpeg\0-latest-x64\bin\ffmpeg.exe set mpeg2_path=.\mpeg2 MD "%mpeg2_path%" REM NTSC REM set width=720 REM set height=480 REM set fps=29.97 REM PAL set width=720 set height=576 set fps=25 REM http://todayiwantedtoprogram.tumblr.com/post/15142587796/what-does-ffmpegs-target-pal-dvd-actually-do REM http://ffmpeg.org/pipermail/ffmpeg-devel/2010-November/097933.html REM define PAL DVD mpeg2 TFF interlaced conversion flags for 16x9 and 4x4. Resize and center-pad with black bars. REM (I would have liked to add flag +cgop but it stops ffmpeg from working) set sw_interlaced=-flags +ildct+ilme+loop -ildctcmp satd -cmp satd -subcmp satd -mbcmp satd -mbd rd -top 1 set sw_mpeg2_pal_16x9=-c:v mpeg2video -pix_fmt yuv420p -dc 10 -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% %sw_interlaced% set sw_mpeg2_pal_4x3=-c:v mpeg2video -pix_fmt yuv420p -dc 10 -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% %sw_interlaced% REM define MP2 audio bitrate 224k 44100hz conversion flags set sw_audio=-c:a mp2 -ac 2 -ab 224k -ar 44100 REM define volume adjustment parameters and create a vbs file to parse the "stats-like" intermediate file looking for the "Integrated loudness" I value SET refVol=18 SET aebur128File=%mpeg2_path%\vol.ebur.txt SET adjVFile=%mpeg2_path%\adjV.txt SET vbsVolFile=%mpeg2_path%\vol.vbs call :fred_create_vbs_once REM loop through all mp4 files incurrent folder and convert them for %%y in ("*.mp4") do ( call :fred_do_conversion "%%y" ) del "%mpeg2_path%\mi.txt" exit :fred_do_conversion SETLOCAL ENABLEDELAYEDEXPANSION REM first, determine the aspect ratio of the current input file del "!mpeg2_path!\mi.txt" "!mediainfo_path!" --Inform=Video;%%AspectRatio/String%% "%~1" > ".\mi.txt" set /p ar= < ".\mi.txt" REM second, parse the current input file and determine the adjustment in audio volume we need to make del "%aebur128File%" del "%adjVFile%" "!ffmpeg_path!" -y -vn -nostats -threads 8 -i "%~dpnx1" -filter_complex ebur128 -f null - > "%aebur128File%" 2>&1 cscript //B //NOLOGO "%vbsVolFile%" "%aebur128File%" > "%adjVFile%" set /p adjV= < "%adjVFile%" del "%aebur128File%" del "%adjVFile%" SET sw_adjV=-af volume=volume=!adjV!dB:precision=float REM do a straight 16:9 resize to !width!x!height! if "!ar!" == "16:9" ECHO "!ffmpeg_path!" -i "%~dpnx1" -map_metadata -1 !sw_mpeg2_pal_16x9! !sw_audio! !sw_adjV! -y "!mpeg2_path!\%~n1.mpg" if "!ar!" == "16:9" "!ffmpeg_path!" -i "%~dpnx1" -map_metadata -1 !sw_mpeg2_pal_16x9! !sw_audio! !sw_adjV! -y "!mpeg2_path!\%~n1.mpg" REM else do a 4x3 preserve-aspect-ratio resize and center-pad with black bars. if NOT "!ar!" == "16:9" ECHO "!ffmpeg_path!" -i "%~dpnx1" -map_metadata -1 !sw_mpeg2_pal_4x3! !sw_audio! !sw_adjV! -y "!mpeg2_path!\%~n1.mpg" if NOT "!ar!" == "16:9" "!ffmpeg_path!" -i "%~dpnx1" -map_metadata -1 !sw_mpeg2_pal_4x3! !sw_audio! !sw_adjV! -y "!mpeg2_path!\%~n1.mpg" goto :eof :fred_create_vbs_once SETLOCAL ENABLEDELAYEDEXPANSION REM create the VBS to determine what audio volume conversion factor to use REM PARSE output from this command using vbscript REM "C:\SOFTWARE\ffmpeg\0-latest\bin\ffmpeg.exe" -y -vn -nostats -threads 8 -i "input.mp4" -filter_complex ebur128 -f null - > "%aebur128File%" 2>&1 DEL "%vbsVolFile%" ECHO ' read vol from ffmpeg file and return the Maximum Volume value only > "%vbsVolFile%" ECHO ' parameter number 0 is the quote-delimited filename to read aebur128File (ebur128) >> "%vbsVolFile%" ECHO set Args = Wscript.Arguments >> "%vbsVolFile%" ECHO if Args.Count ^<^> 1 then >> "%vbsVolFile%" ECHO wscript.echo( "? Invalid number of arguments - usage is: this.vbs aebur128File.txt") >> "%vbsVolFile%" ECHO Wscript.Quit 2 ' 0=OK >> "%vbsVolFile%" ECHO end if >> "%vbsVolFile%" ECHO aebur128File = args(0) >> "%vbsVolFile%" ECHO ' read ebur128 from ffmpeg file and return the Integrated Loudness I value only >> "%vbsVolFile%" ECHO Const ForReading = 1 >> "%vbsVolFile%" ECHO Dim objStdOut, objFSO , objFile, line, e, s, v, adj, adjE, er >> "%vbsVolFile%" ECHO ''Set objStdOut = WScript.StdOut >> "%vbsVolFile%" ECHO Set objFSO = CreateObject("Scripting.FileSystemObject") >> "%vbsVolFile%" ECHO Set objFile = objFSO.OpenTextFile(aebur128File, ForReading) >> "%vbsVolFile%" ECHO er = 1 >> "%vbsVolFile%" ECHO v = 0 >> "%vbsVolFile%" ECHO adj = 0 >> "%vbsVolFile%" ECHO Do Until objFile.AtEndOfStream >> "%vbsVolFile%" ECHO line = lcase(objFile.ReadLine) >> "%vbsVolFile%" ECHO if instr(line,lcase("Integrated loudness:")) > 0 then >> "%vbsVolFile%" ECHO line = lcase(objFile.ReadLine) >> "%vbsVolFile%" ECHO s = instr(line,lcase("I:")) + 2 >> "%vbsVolFile%" ECHO e = instr(line,lcase("LUFS")) - 1 >> "%vbsVolFile%" ECHO 'WScript.StdOut.WriteLine "line=" ^& line >> "%vbsVolFile%" ECHO 'WScript.StdOut.WriteLine s ^& " " ^& e >> "%vbsVolFile%" ECHO if s^<=0 or e^<=0 then >> "%vbsVolFile%" ECHO exit do >> "%vbsVolFile%" ECHO end if >> "%vbsVolFile%" ECHO v = trim(mid(line,s,e-s+1)) >> "%vbsVolFile%" ECHO 'WScript.StdOut.WriteLine "string v=" ^& v >> "%vbsVolFile%" ECHO v = cdbl(v) >> "%vbsVolFile%" ECHO 'WScript.StdOut.WriteLine "cdbl v=" ^& v >> "%vbsVolFile%" ECHO ''' adjust to -!refVol! (-23 is standard) >> "%vbsVolFile%" ECHO ''' v = -23 - v >> "%vbsVolFile%" ECHO v = -!refVol! - v >> "%vbsVolFile%" ECHO 'WScript.StdOut.WriteLine "-!refVol!-v v=" ^& v >> "%vbsVolFile%" ECHO adj = min(abs(max(v,0)),!refVol!) >> "%vbsVolFile%" ECHO 'WScript.StdOut.WriteLine "adj=" ^& adj >> "%vbsVolFile%" ECHO er = 0 >> "%vbsVolFile%" ECHO exit do >> "%vbsVolFile%" ECHO end if >> "%vbsVolFile%" ECHO Loop >> "%vbsVolFile%" ECHO adjE=adj >> "%vbsVolFile%" ECHO WScript.StdOut.WriteLine adjE >> "%vbsVolFile%" ECHO objFile.Close >> "%vbsVolFile%" ECHO set objFile = nothing >> "%vbsVolFile%" ECHO set objFSO = nothing >> "%vbsVolFile%" ECHO wscript.quit(er) ' 1=error. 0=ok >> "%vbsVolFile%" ECHO function Max(a,b) >> "%vbsVolFile%" ECHO Max = a >> "%vbsVolFile%" ECHO If b ^> a then Max = b >> "%vbsVolFile%" ECHO end function >> "%vbsVolFile%" ECHO function Min(a,b) >> "%vbsVolFile%" ECHO Min = a >> "%vbsVolFile%" ECHO If b ^< a then Min = b >> "%vbsVolFile%" ECHO end function >> "%vbsVolFile%" goto :eof
-
Last edited by hech54; 13th Jan 2015 at 23:38.
-
hech had a typo earlier - "batter person" . I thought it was intentional... for .bat files
For interlaced encoding, TFF. (This doesn't convert to interlaced - it only specifies interlaced encoding)
Code:-flags +ilme+ildct -alternate_scan 1 -top 1
https://ffmpeg.org/ffmpeg-filters.html#hqdn3d-1 -
if you have it going with ffmpeg why not to just leave it there, with avisynth you'd need to load it through ffmpegsource or dgavcindex(preferably demuxed) but you could get many issues with variety of your inputs, ffmpeg seems to be better idea in this case,
I just encoded your ffmpeg line , second time without that %sw_interlaced% variable and got progressive video, I mention this because I encode only progressive DVD's and nobody ever complained, ffmpeg just gives it interlaced flags, how valid is that progressive stream for DVD I cannot say in this case because I use HcEncoder, just mentioning that progressive stream is fine to burn on DVD .... -
Well, I am a tad wary of installing programs ... and at the time this did seem easy enough to try. Didn't say I was suffering unduly nor had a lack of results, only a few queries which some kind souls may assist with. Becoming a better person wasn't a consideration although it is a thought
Oh well. I'm happy enough with the PAL 25fps mpeg4->mpeg2 conversions with the addition of the -alternate_scan 1 above.
OK, thank you.
- i did get issues with a couple of the 29.97 conversions; the attempted padding broke with ffmpeg yielding a negative number type failure message
- i will look at dgavcindex and consider doing something differently for 29.97 as I reckon my rellie needs it in PAL 25fps ... I searched but no links came up readily for an ffmpeg commandline or an avisynth script to do that conversion (I gather NTSC->PAL has a range of potential issues I've never had to deal with before, but there must be something someone has already done before in avisynth ... 29.97 is a 1.2mb sample)
- I will check out creating a PAL progressive source DVD without the interlacing stuff and see how it goes
Thank you; batty may be close enough, but hey no one is an angel
OK, add -alternate_scan 1.Last edited by hydra3333; 14th Jan 2015 at 03:00.
-
If you want to use DGavcindex, I'd really think you'd need to demux streams first or better use ffmpegsource2. To calculate pads (borders in Avisynth) but for 4:3 inputs, you'd need to extract horizontal and vertical resolution with mediainfo and make calculations, but batch script is not handy at all for this, it cannot calculate floating point numbers ... so it might be just better off figuring correct formula for that ffmpeg and sticking overall what you are doing already , or if you know avisynth math symbols and code for math, to calculate it over there, not sure how complicated it would be ,in that case loading clip with that dgavcindex or ffmpegsource2
-
<snip> double post
Last edited by hydra3333; 16th Jan 2015 at 18:32.
-
Thank you. I had DG's NV tools so with your pointers I was able to open .mp4s in avisynth with that and deal with aspect ratios etc better.
You were all right of course. For the various sources I received (mainly 1950's b+w aircraft stuff all of which had been "converted over time" well before it got to me), this part broke on occasion:
Code:-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"
So, I ended up having to brute-force them using a combo of [avisynth, HC, mediainfo, 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 general workflow, but it seems to work close enough for these sources.