I have a Windows batch using ffprobe to retrieve the codec_names for the video and audio streams for files in a folder
It then converts the codec_names into the appropriate file extensions for the ffmpeg output of the audio and video streams, i.e. it batch demuxes each file
I have this working in Linux as a bash script - it will demux all media files regardless of the codecs used - the steps are more or less the same - but Windows treats it differently.
In Windows it works if every file can accept the audio and video extensions because it uses the last file's audio and video extensions - but if I have a mixture of different files - it will output files with 0 bytes [i.e. corrupt files] because the audio and video streams would not work with those file extensions
ECHO OFF
set "arg[0]=codec_name"
for %%a in (*.*) do C:\ffmpeg\bin\ffprobe.exe -v quiet -select_streams a:0 -show_entries stream=%arg[0]% -of default=noprint_wrappers=1:nokey=1 -i "%%a" >audio.txt
for %%a in (*.*) do C:\ffmpeg\bin\ffprobe.exe -v quiet -select_streams v:0 -show_entries stream=%arg[0]% -of default=noprint_wrappers=1:nokey=1 -i "%%a" >video.txt
set /p codeca=<audio.txt
del audio.txt
if %codeca% == aac set codeca1=m4a
...
if %codeca% == pcm_s32be codeca1=.aiff
It checks 20 different codecs_names in order to create the appropriate extension on output
set /p codecv=<video.txt
del video.txt
if %codecv% == h264 set codecv1=m4v
...
if %codecv% == wmv3 set codecv1=asf
It checks 25 different codec_names in order to create the appropriate extension on output
then to create the demuxed audio and video files:
for %%a in (*.*) do c:\ffmpeg\bin\ffmpeg -i "%%a" -vn -acodec copy "%%a_d%codeca1%"
for %%a in (*.*) do c:\ffmpeg\bin\ffmpeg -i "%%a" -an -vcodec copy "%%a_d.%codecv1%"
if the batch uses >>audio.txt [and if it isn't deleted] results in
aac
aac
aac
opus
dts
and it should create three different audio extensions: m4a, ogg and dts
if the batch uses >>video.txt [and if it isn't deleted] results in
h264
h264
hevc
vp9
vc1
and it should create four different video extensions: m4v, h265, mkv, asf
What am I doing wrong?
I think I need to put some of the code into a function that I call or save the file extensions into a audio array and a video array?
I can post the linux script if someone wants to take a look at it
TIA
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays!
+ Reply to Thread
Results 1 to 8 of 8
Thread
-
Last edited by wiseant; 25th Dec 2023 at 21:28.
-
Hi wiseant.
I came at it from a slightly different direction.
A batch file for extracting everything from every video has sat at the back of my mind for years.
This is it. Maybe it'll be of some use to someone. Setting ':get_extension' variables , I'll leave it up to you add to/enhance.
I found ffmpeg threw up a number of errors/warnings. Investigation showed that 99% of them could be ignored. The output seemed fine.
Having said that - ymmv. I could do more testing. Nah! It's Christmas Day, and there's a BBQ happening next door.
demux-all-v01.cmd
Code:@echo off if not exist New\ md New for %%a in (*.mkv, *.mp4, *.avi) do call :process1 "%%a" goto :end :process1 ffmpeg.exe -i "%~1" -y nul 2>&1 | find /i "stream" >"%~n1.txt" for /f "usebackq tokens=1-6 delims=^:^#^ " %%a in ("%~n1.txt") do ( set stream=%%b:%%c set codec=%%e call :get_extension call :process2 "%~1" ) goto :eof :process2 ffmpeg.exe -i "%~1" -map %stream%? -codec copy -y "New\%~n1.%ext%" goto :eof :get_extension if %codec% equ h264 set ext=mp4 if %codec% equ mpeg4 set ext=mp4 if %codec% equ aac set ext=aac if %codec% equ mp3 set ext=mp3 if %codec% equ pcm_s16le set ext=wav if %codec% equ subrip set ext=srt goto :eof :end ::del "*.txt"
Cheers.Last edited by pcspeak; 26th Dec 2023 at 15:27. Reason: Clarity.
-
@pcspeak
Thanks for that - I'll check it out when I have some time
@ProWo
the linux script is ffprobe_folder.sh
I have it in my /home/unoit/ directory [unoit is my username]
To use it one needs to give it permission to execute:
in the linux terminal type
cd /home/unoit [using your username]
sudo chmod +x ffprobe_folder.sh
It is best to use it for a folder that only contains media files with video and audio
To use it - right_click on a mediafile in the folder and select
Open With
then Open With Other Application...
then Use a custom command
then browse to where ffprobe_folder.sh is
it will then demux all the mediafiles in that folder
It is also possible to create a .desktop file and copy this to the SendTo directory
eg sudo cp /home/unoit/ffprobe_folder /usr/share/Thunar/sendto
then it is possible to right_click on the mediafile in the folder and choose Send To ffprobefolder
ffprobe_folder.sh:
#!/bin/bash
function pause(){
read -p "$*"
}
arg=codec_name
for mediafile in *.*; do
INFO=$(ffprobe -hide_banner -i "$mediafile" -v quiet -select_streams a:0 -show_entries stream=$arg -of default=noprint_wrappers=1:nokey=1 >audio.txt)
str2a=$(sed '1!d' audio.txt)
b=$str2a
codeca=$b
[ -e audio.txt ] && rm audio.txt
if [[ "$b" == 'aac' ]]; then codeca="m4a"; fi
if [[ "$b" == 'dts' ]]; then codeca="dts"; fi
if [[ "$b" == 'opus' ]]; then codeca="ogg"; fi
if [[ "$b" == 'truehd' ]]; then codeca="ac3"; fi
if [[ "$b" == 'vorbis' ]]; then codeca="ogg"; fi
if [[ "$b" == 'wmav1' ]]; then codeca="wma"; fi
if [[ "$b" == 'wmav2' ]]; then codeca="wma"; fi
if [[ "$b" == 'wmapro' ]]; then codeca="wma"; fi
if [[ "$b" == 'wmavoice' ]]; then codeca="wma"; fi
if [[ "$b" == 'wmalossless' ]]; then codeca="wma"; fi
# wav
if [[ "$b" == 'pcm_u8' ]]; then codeca="wav"; fi
if [[ "$b" == 'pcm_s16le' ]]; then codeca="wav"; fi
if [[ "$b" == 'pcm_s24le' ]]; then codeca="wav"; fi
if [[ "$b" == 'pcm_s32le' ]]; then codeca="wav"; fi
if [[ "$b" == 'pcm_f32le' ]]; then codeca="wav"; fi
if [[ "$b" == 'pcm_dvd' ]]; then codeca="wav"; fi
#aiff
if [[ "$b" == 'pcm_s8' ]]; then codeca="aiff"; fi
if [[ "$b" == 'pcm_s16be' ]]; then codeca="aiff"; fi
if [[ "$b" == 'pcm_s24be' ]]; then codeca="aiff"; fi
if [[ "$b" == 'pcm_s32be' ]]; then codeca="aiff"; fi
arg1=codec_name
INFO1=$(ffprobe -hide_banner -i "$mediafile" -v quiet -select_streams v:0 -show_entries stream=$arg1 -of default=noprint_wrappers=1:nokey=1 >video.txt)
str2b=$(sed '1!d' video.txt)
c=$str2b
codecv=$c
codecv="."$c1
[ -e video.txt ] && rm video.txt
if [[ "$c" == 'cfhd' ]]; then codecv=".avi"; fi
if [[ "$c" == 'dvvideo' ]]; then codecv=".avi"; fi
if [[ "$c" == 'ffv1' ]]; then codecv=".avi"; fi
if [[ "$c" == 'flv1' ]]; then codecv=".flv"; fi
if [[ "$c" == 'h264' ]]; then codecv=".m4v"; fi
if [[ "$c" == 'h265' ]]; then codecv=".h265"; fi
if [[ "$c" == 'hevc' ]]; then codecv=".h265"; fi
if [[ "$c" == 'huffyuv' ]]; then codecv=".avi"; fi
if [[ "$c" == 'lagarith' ]]; then codecv=".avi"; fi
if [[ "$c" == 'mjpeg' ]]; then codecv=".avi"; fi
if [[ "$c" == 'mpeg' ]]; then codecv=".m2v"; fi
if [[ "$c" == '"mpegts"' ]]; then codecv=".ts"; fi
if [[ "$c" == 'mpeg1video' ]]; then codecv=".ts"; fi
if [[ "$c" == 'mpeg2video' ]]; then codecv=".m2v"; fi
if [[ "$c" == 'mpeg4' ]]; then codecv=".avi"; fi
if [[ "$c" == 'mpg' ]]; then codecv=".m2v"; fi
if [[ "$c" == 'msmpeg4v1' ]]; then codecv=".asf"; fi
if [[ "$c" == 'msmpeg4v2' ]]; then codecv=".asf"; fi
if [[ "$c" == 'msmpeg4v3' ]]; then codecv=".asf"; fi
if [[ "$c" == 'prores' ]]; then codecv=".mov"; fi
if [[ "$c" == 'theora' ]]; then codecv=".mkv"; fi
if [[ "$c" == 'utvideo' ]]; then codecv=".avi"; fi
if [[ "$c" == 'vc1' ]]; then codecv=".asf"; fi
if [[ "$c" == 'vp8' ]]; then codecv=".mkv"; fi
if [[ "$c" == 'vp9' ]]; then codecv=".mkv"; fi
if [[ "$c" == 'wmv1' ]]; then codecv=".asf"; fi
if [[ "$c" == 'wmv2' ]]; then codecv=".asf"; fi
if [[ "$c" == 'wmv3' ]]; then codecv=".asf"; fi
ffmpeg -i "$mediafile" -v quiet -hide_banner -vn -acodec copy "${mediafile%.*}_d.$codeca"
ffmpeg -i "$mediafile" -v quiet -hide_banner -an -vcodec copy "${mediafile%.*}_d$codecv"
echo video file to demux: $mediafile
echo demuxed video file: "${mediafile%.*}$codecv"
echo demuxed audio file: "${mediafile%.*}.$codeca"
echo video file to demux: $mediafile >> "$mediafile"_log.txt
echo demuxed video file: "${mediafile%.*}$codecv" >> "$mediafile"_log.txt
echo demuxed audio file: "${mediafile%.*}.$codeca" >> "$mediafile"_log.txt
done
$SHELL
ffprobe_folder.desktop:
[Desktop Entry]
Name=ffprobe_folder
Exec=/home/unoit/ffprobe_folder.sh
Icon=
comment=ffmpeg
Type=Application
Terminal=true
Encoding=UTF-8
Categories=Utility;
Comment=
Path=
StartupNotify=false
Here is a Test folder before processing:
[Attachment 75737 - Click to enlarge]
Here is the Test folder after using the script:
[Attachment 75738 - Click to enlarge]
if one uses Open With instead of Send To there won't be any terminal output - but there will be the individual log files
and here is the terminal output when using Send To ffprobefolder:
video file to demux: basicinstinct.ogm
demuxed video file: basicinstinct.asf
demuxed audio file: basicinstinct.ogg
video file to demux: BuckBunny_1.wmv
demuxed video file: BuckBunny_1.asf
demuxed audio file: BuckBunny_1.wma
video file to demux: channelcheck-ddplus_480.mp4
demuxed video file: channelcheck-ddplus_480.m4v
demuxed audio file: channelcheck-ddplus_480.eac3
video file to demux: HD-h264.ts
demuxed video file: HD-h264.m4v
demuxed audio file: HD-h264.ac3
video file to demux: HempHardCheese_AppleProRes.avi
demuxed video file: HempHardCheese_AppleProRes.mov
demuxed audio file: HempHardCheese_AppleProRes.wav
video file to demux: HempHardCheese_dv.avi
demuxed video file: HempHardCheese_dv.avi
demuxed audio file: HempHardCheese_dv.wav
video file to demux: HempHardCheese_ffv1.avi
demuxed video file: HempHardCheese_ffv1.avi
demuxed audio file: HempHardCheese_ffv1.mp3
video file to demux: HempHardCheese_flv.flv
demuxed video file: HempHardCheese_flv.flv
demuxed audio file: HempHardCheese_flv.m4a
video file to demux: HempHardCheese_GoPro.avi
demuxed video file: HempHardCheese_GoPro.avi
demuxed audio file: HempHardCheese_GoPro.wav
video file to demux: HempHardCheese_huff_8bit.avi
demuxed video file: HempHardCheese_huff_8bit.avi
demuxed audio file: HempHardCheese_huff_8bit.wav
video file to demux: HempHardCheese_huff.avi
demuxed video file: HempHardCheese_huff.avi
demuxed audio file: HempHardCheese_huff.mp3
video file to demux: HempHardCheese_lags.avi
demuxed video file: HempHardCheese_lags.avi
demuxed audio file: HempHardCheese_lags.wav
video file to demux: HempHardCheese_mjpeg.avi
demuxed video file: HempHardCheese_mjpeg.avi
demuxed audio file: HempHardCheese_mjpeg.mp3
video file to demux: MainConceptEncoded-sample.mpg
demuxed video file: MainConceptEncoded-sample.m2v
demuxed audio file: MainConceptEncoded-sample.ac3
video file to demux: mp43.wmv
demuxed video file: mp43.asf
demuxed audio file: mp43.wma
video file to demux: OwnerofaLonelyHeart.webm
demuxed video file: OwnerofaLonelyHeart.mkv
demuxed audio file: OwnerofaLonelyHeart.ogg
video file to demux: PE2_Leopard_1080.mkv
demuxed video file: PE2_Leopard_1080.m4v
demuxed audio file: PE2_Leopard_1080.flac
video file to demux: Serenity[2005].avi
demuxed video file: Serenity[2005].avi
demuxed audio file: Serenity[2005].mp3
video file to demux: theweekend.wmv
demuxed video file: theweekend.asf
demuxed audio file: theweekend.wma
video file to demux: TrueHD Sample 1 (Final Fantasy VII Advent Children).mkv
demuxed video file: TrueHD Sample 1 (Final Fantasy VII Advent Children).m4v
demuxed audio file: TrueHD Sample 1 (Final Fantasy VII Advent Children).ac3
video file to demux: VTS_06_0.VOB
demuxed video file: VTS_06_0.m2v
demuxed audio file: VTS_06_0.ac3
video file to demux: wmapro-in-wmavoice.wmv
demuxed video file: wmapro-in-wmavoice.asf
demuxed audio file: wmapro-in-wmavoice.wma
video file to demux: wmv1.wmv
demuxed video file: wmv1.asf
demuxed audio file: wmv1.wmaLast edited by wiseant; 25th Dec 2023 at 21:28.
-
FWIW
Update: for some reason when I first posted this the first line dealing with ffprobe ... >audio.txt got screwed up - so if anyone is interested it has been fixed
Here is Windows batch file to demux one mediafile containing video and audio
User can drag and drop media file on it - or set up a Windows sendto shortcut
myprobe.bat
ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
set "arg=codec_name"
C:\ffmpeg\bin\ffprobe.exe -v quiet -select_streams a:0 -show_entries stream=%arg% -of default=noprint_wrappers=1:nokey=1 -i "%~dpnx1" >audio.txt
C:\ffmpeg\bin\ffprobe.exe -v quiet -select_streams v:0 -show_entries stream=%arg% -of default=noprint_wrappers=1:nokey=1 -i "%~dpnx1" >video.txt
set /p codeca=<audio.txt
set /p codecv=<video.txt
SET a=.
SET codeca1=%a%%codeca%
SET codecv1=%a%%codecv%
rem set audio extensions
if %codeca% == aac set codeca1=.m4a
if %codeca% == dts set codeca1=.dts
if %codeca% == opus set codeca1=.ogg
if %codeca% == truehd set codeca1=.ac3
if %codeca% == vorbis set codeca1=.ogg
if %codeca% == wmav1 set codeca1=.wma
if %codeca% == wmav2 set codeca1=.wma
if %codeca% == wmapro set codeca1=.wma
if %codeca% == wmavoice set codeca1=.wma
if %codeca% == wmalossless set codeca1=.wma
if %codeca% == pcm_u8 codeca1=.wav
if %codeca% == pcm_s16le set codeca1=.wav
if %codeca% == pcm_s24le set codeca1=.wav
if %codeca% == pcm_s32le set codeca1=.wav
if %codeca% == pcm_f32le set codeca1=.wav
if %codeca% == pcm_dvd set codeca1=.wav
if %codeca% == pcm_s8 set codeca1=.aiff
if %codeca% == pcm_s16be set codeca1=.aiff
if %codeca% == pcm_s24be set codeca1=.aiff
if %codeca% == pcm_s32be codeca1=.aiff
rem set video extensions
if %codecv% == cfhd set codecv1=avi
if %codecv% == dvvideo set codecv1=avi
if %codecv% == ffv1 set codecv1=avi
if %codecv% == flv1 set codecv1=flv
if %codecv% == h264 set codecv1=m4v
if %codecv% == h265 set codecv1=h265
if %codecv% == hevc set codecv1=h265
if %codecv% == huffyuv set codecv1=avi
if %codecv% == lagarith set codecv1=avi
if %codecv% == mjpeg set codecv1=avi
if %codecv% == mpeg set codecv1=m2v
if %codecv% == mpeg1video set codecv1=ts
if %codecv% == mpeg2video set codecv1=ts
if %codecv% == mpeg4 set codecv1=avi
if %codecv% == msmpeg4v1 set codecv1=asf
if %codecv% == msmpeg4v2 set codecv1=asf
if %codecv% == msmpeg4v3 set codecv1=asf
if %codecv% == prores set codecv1=mov
if %codecv% == theora set codecv1=mkv
if %codecv% == utvideo set codecv1=avi
if %codecv% == vc1 set codecv1=asf
if %codecv% == vp8 set codecv1=mkv
if %codecv% == vp9 set codecv1=mkv
if %codecv% == wmv1 set codecv1=asf
if %codecv% == wmv2 set codecv1=asf
if %codecv% == wmv3 set codecv1=asf
echo original file is "%~dpnx1"
echo demuxed audio is "%~dpn1_d%codeca1%"
echo demuxed video is "%~dpn1_d.%codecv1%"
c:\ffmpeg\bin\ffmpeg -v quiet -i "%~dpnx1" -vn -c:a copy "%~dpn1_d%codeca1%"
c:\ffmpeg\bin\ffmpeg -v quiet -i "%~dpnx1" -an -c:v copy "%~dpn1_d.%codecv1%"
echo original file is "%~dpnx1" >> %~dpnx1.txt
echo demuxed audio is "%~dpn1_d%codeca1%" >> %~dpnx1.txt
echo demuxed video is "%~dpn1_d.%codecv1%" >> %~dpnx1.txt
pause
sample log file:
original file is "C:\Users\UNOIT\Desktop\Tests\VTS_06_0.VOB"
demuxed audio is "C:\Users\UNOIT\Desktop\Tests\VTS_06_0_d.ac3"
demuxed video is "C:\Users\UNOIT\Desktop\Tests\VTS_06_0_d.ts"Last edited by wiseant; 25th Dec 2023 at 21:29. Reason: spelling
-
@pcspeak
Hi
That code you provided gave me everything I needed to write the functions I wanted
Hope you enjoyed your BBQ - looks like summertime has just started where you are
I will post my code tomorrow -
re demux_folder.zip
ReadMe file for demux_folder.bat
This Windows batch file will demux media files into video and audio files
It can handle over 20 different audio codecs and over 26 different video codecs
ffmpeg.exe and ffprobe.exe are required
The default location for these two files is c:\ffmpeg\bin - just edit the batch file [in any text editor] to change to your location
It is best to use a folder that just contains media files that have audio and video.
To use just drag and drop any media file from the folder to demux_folder.bat
The demuxed files will go into demux folder and the log files will go into logs folder
I tried to upload demux_folder.zip but I got this: {vb:raw post.otherattachments - looks like the file got uploaded
Similar Threads
-
Anybody using Windows Defender controlled folder access?
By davexnet in forum ComputerReplies: 4Last Post: 4th Jul 2023, 19:59 -
batch to choose a file in folder with exception to one specific
By marcorocchini in forum Newbie / General discussionsReplies: 0Last Post: 4th Aug 2022, 19:14 -
How to batch merge video & audios with same name inside a folder in Windows
By maxteddy in forum Video ConversionReplies: 4Last Post: 31st Jan 2022, 11:58 -
GUI ways to Select + Batch process/ convert formats Videos in folder trees?
By insight in forum Video ConversionReplies: 1Last Post: 3rd Aug 2021, 13:26 -
Xstreamer prodigy shared folder is not seen by Windows 10
By g68 in forum Media Center PC / MediaCentersReplies: 1Last Post: 16th Jun 2019, 19:27