Skip to content

Instantly share code, notes, and snippets.

@end2endzone
Last active January 11, 2024 00:06
Show Gist options
  • Save end2endzone/1f0c3cfb7280e7f0eaab2fca814af3f8 to your computer and use it in GitHub Desktop.
Save end2endzone/1f0c3cfb7280e7f0eaab2fca814af3f8 to your computer and use it in GitHub Desktop.
Batch file for demuxing audio files using ffmpeg. Drag and drop files over the batch file to use or specify each files on the command line. ffmpeg must be in your PATH. For example, get the actual audio codec stream from a *.webp or *.mkv or *.m4a. The script automatically detects the internal audio codec and finds the associated file extension.
@echo off
:: Process all drag and drop files
if [%1]==[] goto :eof
:loop
call :demux "%~1"
shift
if not [%1]==[] goto loop
:: Pause at the end of processing all files.
pause
goto :eof
:demux
echo Demuxing %~nx1...
::Finding audio codec file extension
ffprobe -loglevel error -select_streams a:0 -show_entries stream=codec_name -of csv=p=0 "%~1">%TEMP%\ffmpeg_demux_file_ext.tmp
if errorlevel 1 echo Failed to find audio codec file extension. && pause && exit /B 1
:: Reading the file extension.
set /P DEMUX_CODEC_FILE_EXT=< %TEMP%\ffmpeg_demux_file_ext.tmp
if errorlevel 1 echo Failed to read file %TEMP%\ffmpeg_demux_file_ext.tmp. && pause && exit /B 1
echo Found codec file extension: %DEMUX_CODEC_FILE_EXT%
echo.
:: Demuxing using ffmpeg
echo Demuxing...
ffmpeg -y -hide_banner -i "%~1" -vn -acodec copy "%~dpn1".%DEMUX_CODEC_FILE_EXT%
if errorlevel 1 echo Failed to demux input file "%~1". && pause && exit /B 1
echo.
goto :eof
:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment