VideoHelp Forum
+ Reply to Thread
Results 1 to 4 of 4
Thread
  1. Member
    Join Date
    Mar 2024
    Location
    germany
    Search Comp PM
    Hi I have a .bat file to convert and change channel volume levels (with ffmpeg) from 5.1 Audio to Stereo, and a different .bat for Stereo/Mono Audio that doesn't change loudness.
    Now I have to manually look if a movie is 5.1 or Mono/Stereo and decide which .bat to run. I would like to make one .bat with a condition so it looks what the channel layout for a specific language is and then decide which profile to run. I hope this makes sense. It has to check also the language tag, because sometimes (in my case) german is 2.0 but English is 5.1 or vice versa.

    From my understanding I would need ffprobe which gives me the channel count and language for every audio track
    Code:
    ffprobe -i %~1 -v error -select_streams a -of csv=p=0 -show_entries stream=channels,index:stream_tags=language
    So I have kinda all the pieces but I don't know how to put them together in a .bat script

    Thank you for any advice

    Profile A: 5.1

    Code:
    ffmpeg ^
    	-i "%~1" ^
    	-af "pan=stereo|c0=c2+0.6*c0+0.6*c4+c3|c1=c2+0.6*c1+0.6*c5+c3" -map 0:v:0 -c:v copy -map 0:a:m:language:ger -codec:a ac3 -b:a 160k -ar 44100 -sn -dn ^
    	"G:\%~n1.mkv"
    Profile B: Stereo/Mono
    Code:
    ffmpeg ^
    	-i "%~1" ^
    	-map 0:v:0 -c:v copy -map 0:a:m:language:ger -codec:a ac3 -b:a 160k -ar 44100 -sn -dn ^
    	"G:\%~n1.mkv"
    
    This is the whole .bat
    Code:
    @echo off
    :again
    
    ffmpeg ^
    	-i "%~1" ^
    	-map 0:v:0 -c:v copy -map 0:a:m:language:ger -codec:a ac3 -b:a 160k -ar 44100 -sn -dn ^
    	"G:\%~n1.mkv"
    if NOT ["%errorlevel%"]==["0"] goto:error
    echo %~n1 Done!
    
    shift
    if "%~1" == "" goto:end
    goto:again
    
    :error
    
    echo There was an error. Please check your input file or report an issue on github.com/L0Lock/FFmpeg-bat-collection/issues.
    pause
    exit 0
    
    :end
    
    cls
    echo Encoding succesful. This window will close after 10 seconds.
    timeout /t 1
    Quote Quote  
  2. Member
    Join Date
    Apr 2007
    Location
    Australia
    Search Comp PM
    Hi.
    I'ts been a while since I saw someone else using esc codes to change screen colours.
    I occasionally use them myself.

    I created a multi audio, multi subtitle MKV from a DVD using MakeMKV.exe (movie - The Fifth Element)

    The following batch file has a line listing all the audio tracks found.
    I left it in to help diagnose any problems. (Where I say tags, read it as parameters or arguments, as you wish.)

    The batch file is written assuming all the tags in your videos are as listed and you are consistent with your conversions.
    i.e. A missing language tag will mean the tag for the channel count moves from %%i to %%h.
    (There are probably a better ways of getting and setting the variables %lang% and %channels%.)

    My batch file is:
    the 4th tag is the language (%%d). This should be consistent across all MKVs
    the 9th tag is the channel count (%%i). This is a tag that showed as the 10th tag (%%j) on other MKVs I have.

    All ffmpeg executables are echoed, and NOT run. Change when you're happy.

    To_Stereo v01.cmd
    Code:
    @echo off
    :loop
    ffmpeg.exe -i "%~1" -y nul 2>&1 | find /i "stream" | find "Audio" > "%~n1.txt"
    
    :: List all audio tracks, with tags. To use parentheses as delimiters, the order of the delimiters is important.
    echo These audio tracks were found.
    for /f "usebackq tokens=1-12 delims=,^:^#() " %%a in ("%~n1.txt") do echo A-%%a B-%%b C-%%c D-%%d E-%%e F-%%f G-%%g H-%%h I-%%i J-%%j K-%%k L-%%l
    echo.
    for /f "usebackq tokens=1-12 delims=,^:^#() " %%a in ("%~n1.txt") do set lang=%%d&& set channels=%%i&& call :channelcount
    
    shift
    if "%~1" neq "" goto :loop
    goto :end
    
    :channelcount
    if %channels% equ mono call :1channel "%~1"
    if %channels% equ 5.1  call :6channel "%~1"
    goto :eof
    
    :1channel
    echo Process mono
    echo ffmpeg -i "%~1" ^
        -map 0:v:0 -c:v copy -map 0:a:m:language:%lang% -codec:a ac3 -b:a 160k -ar 44100 -sn -dn ^
        "G:\%~n1.mkv"
    goto :eof
    
    :6channel
    echo Process 5.1
    echo ffmpeg -i "%~1" ^
        -af "pan=stereo|c0=c2+0.6*c0+0.6*c4+c3|c1=c2+0.6*c1+0.6*c5+c3" -map 0:v:0 -c:v copy -map 0:a:m:language:%lang% -codec:a ac3 -b:a 160k -ar 44100 -sn -dn ^
        "G:\%~n1.mkv"
    goto :eof
    
    :end
    ::del "*.txt"
    pause
    Cheers.
    Last edited by pcspeak; 19th Mar 2024 at 13:10. Reason: Removed multiple spaces in the batch file. No biggie.
    Quote Quote  
  3. Originally Posted by geextah_2 View Post
    -map 0:v:0 -c:v copy -map 0:a:m:language:ger -codec:a ac3 -b:a 160k -ar 44100 -sn -dn ^
    Just out of curiosity... I assume the audio is 48kHz. Why resample it at 44.1kHz?
    Quote Quote  
  4. Member
    Join Date
    Mar 2024
    Location
    germany
    Search Comp PM
    @pcspeak thank you for your reply. I will test this and give you feedback. It looks aswesome
    I don't know what "using esc codes to change screen colours" means. all the credit goes to the author from github (github.com/L0Lock/FFmpeg-bat-collection) I just found his .bat scripts and started to build in my own commands ^^

    @hello_hello you are right all the audio is usually 48k but my tv (usb) has real problems, and often glitches the video and audio streams so I started to make the audio as small as possible
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!