View Full Version : Command Line Muxing
drtj
12th April 2007, 02:33
I am trying to mux a fixed .ac3 stream into an avi file, so that the fixed ac3 file with replace the original audio stream. I am trying to use a command line utility so that I can make a .bat to process a number of files at once.
So far I have gotten the following syntax.
ffmpeg –i original.avi -vcodec copy –i 1fixed.ac3 –acodec copy fixed.avi
This gives me a file with no working audio, and when it is processing, it says "non monotone timestamps." The file info in gspot and vdubmod are way off as well.
So then I tried to delete the existing original audio track with:
ffmpeg –i original.avi -vcodec copy –an
which worked, and then tried to add the fixed ac3 stream with this:
ffmpeg –i original.avi -vcodec copy –i 1fixed.ac3 –acodec copy fixed.avi
After that though, the video plays, however the audio does not. The stream is there when I look at the properties of the final avi in gspot or vdubmod.
Maybe I could use mencoder? If so, what syntax would I use?
Please help. Your time and assistance is very much appreciated.
drj
celtic_druid
12th April 2007, 04:07
I would suggest AVI-Mux GUI.
Something like:
for %%f in (*.ac3) DO (
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
set TMPAMG=%%~nf.amg
set SRCVFN=%%~dpf%%~nf.avi
set SRCAFN=%%~dpf%%~nf.ac3
set MUXFLN=%%~dpfout\%%~nf.avi
echo CLEAR > "!TMPAMG!"
echo LOAD !SRCVFN!>> "!TMPAMG!"
echo LOAD !SRCAFN!>> "!TMPAMG!"
echo SELECT FILE 1 >> "!TMPAMG!"
echo ADD VIDEOSOURCE >> "!TMPAMG!"
echo SET OUTPUT OPTIONS >> "!TMPAMG!"
echo WITH SET OPTION >> "!TMPAMG!"
echo OVERWRITEDLG 0 >> "!TMPAMG!"
echo CLOSEAPP 1 >> "!TMPAMG!"
echo DONEDLG 0 >> "!TMPAMG!"
echo MAXFILES OFF >> "!TMPAMG!"
echo STDOUTPUTFMT AVI >> "!TMPAMG!"
echo AVI ADDJUNKBEFOREHEADERS 0 >> "!TMPAMG!"
echo AUDIO INTERLEAVE 4 FR >> "!TMPAMG!"
echo PRELOAD 200 >> "!TMPAMG!"
echo AVI HAALIMODE 0 >> "!TMPAMG!"
echo OPENDML 0 >> "!TMPAMG!"
echo LEGACY 0 >> "!TMPAMG!"
echo RECLISTS 0 >> "!TMPAMG!"
echo END WITH>> "!TMPAMG!"
echo START !MUXFLN!>> "!TMPAMG!"
ENDLOCAL
)
for %%f in (*.amg) DO ("AVIMux_GUI.exe" "%%~ff")
del *.amg
avi and ac3 need to be the same name. Output goes to a subdir "out".
drtj
12th April 2007, 04:16
@celtic_druid
thanks for the reply
will I be able to mux a number of files 1 after the other, say with a .bat file, ie. 1.avi w/ 1fixed.ac3, then 2.avi w/ 2fixed.ac3, and so on. That is what I am really looking for, a way to do multipe muxings at once.
sorry, but I am having trouble trying to decipher what you have written. I use avi-mux gui to join .avi files together, but have never seen anything close to what is in your repsonse
celtic_druid
12th April 2007, 06:01
No. You would need 1.avi and 1.ac3 which would output .\out\1.avi with the new audio. Also from the above post it sounds like your avi already has audio. Probably you would end up with 2 streams, so I would suggest something like:
for %%f in (*.avi) DO ("ffmpeg.exe" -i "%%f" -vcodec copy -an "video\%%~f")
which would output a video only avi in a video sub folder. Then you would just update the first script to:
set SRCVFN=%%~dpfvideo\%%~nf.avi
You could also adjust it to take into account a "fixed" suffix.
set SRCAFN=%%~dpf%%~nffixed.ac3 You would have to do *.avi instead of *.ac3 though or you would end up with 1fixedfixed.ac3
drtj
12th April 2007, 07:21
I can mux the files and delete the original audio stream using VirtualDubMod no problem, it is just really tedious. What I am looking for is a way to automate the process a bit, since I am demuxing and remuxing a number of avi files with fixed ac3 streams. So a command line utility like ffmpeg or mencoder is what I am looking for so I can create a .bat file that will take care of a number of files in a row with a click of a button.
celtic_druid
12th April 2007, 08:35
Well the above would just process all files in a given dir.
drtj
12th April 2007, 22:27
...um...not to sound too stupid, but where or what do I do with that code exactly?
celtic_druid
13th April 2007, 03:36
Copy/paste into a batch file.
for %%f in (*.avi) DO (
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
set TMPAMG=%%~nf.amg
set SRCVFN=%%~dpf%%~nf.avi
set SRCAFN=%%~dpf%%~nffixed.ac3
set MUXFLN=%%~dpfout\%%~nf.avi
echo CLEAR > "!TMPAMG!"
echo LOAD !SRCVFN!>> "!TMPAMG!"
echo LOAD !SRCAFN!>> "!TMPAMG!"
echo SELECT FILE 1 >> "!TMPAMG!"
echo ADD VIDEOSOURCE >> "!TMPAMG!"
echo SET OUTPUT OPTIONS >> "!TMPAMG!"
echo WITH SET OPTION >> "!TMPAMG!"
echo OVERWRITEDLG 0 >> "!TMPAMG!"
echo CLOSEAPP 1 >> "!TMPAMG!"
echo DONEDLG 0 >> "!TMPAMG!"
echo MAXFILES OFF >> "!TMPAMG!"
echo STDOUTPUTFMT AVI >> "!TMPAMG!"
echo AVI ADDJUNKBEFOREHEADERS 0 >> "!TMPAMG!"
echo AUDIO INTERLEAVE 4 FR >> "!TMPAMG!"
echo PRELOAD 200 >> "!TMPAMG!"
echo AVI HAALIMODE 0 >> "!TMPAMG!"
echo OPENDML 0 >> "!TMPAMG!"
echo LEGACY 0 >> "!TMPAMG!"
echo RECLISTS 0 >> "!TMPAMG!"
echo END WITH>> "!TMPAMG!"
echo START !MUXFLN!>> "!TMPAMG!"
ENDLOCAL
)
The above creates amg scripts. AVI-Mux GUI doesn't strickly offer commandline muxing, but it does have scripting and a script can be loaded via command line.
for %%f in (*.amg) DO ("AVIMux_GUI.exe" "%%~ff")
This runs AVI-Mux GUI with each script.
for %%f in (*.avi) DO ("ffmpeg.exe" -i "%%f" -vcodec copy -an "video\%%~f")
Since you said the avi's already have audio. This creates video only avi's. Can't see a problem here since you already posted a similar line.
Now that you have a new video only file, you need to modify the script creation to mux that, so
set SRCVFN=%%~dpf%%~nf.avi
becomes
set SRCVFN=%%~dpfvideo\%%~nf.avi
So the total batch would be something like:
mkdir video
for %%f in (*.avi) DO ("ffmpeg.exe" -i "%%f" -vcodec copy -an "video\%%~f")
for %%f in (*.avi) DO (
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
set TMPAMG=%%~nf.amg
set SRCVFN=%%~dpfvideo\%%~nf.avi
set SRCAFN=%%~dpf%%~nffixed.ac3
set MUXFLN=%%~dpfout\%%~nf.avi
echo CLEAR > "!TMPAMG!"
echo LOAD !SRCVFN!>> "!TMPAMG!"
echo LOAD !SRCAFN!>> "!TMPAMG!"
echo SELECT FILE 1 >> "!TMPAMG!"
echo ADD VIDEOSOURCE >> "!TMPAMG!"
echo SET OUTPUT OPTIONS >> "!TMPAMG!"
echo WITH SET OPTION >> "!TMPAMG!"
echo OVERWRITEDLG 0 >> "!TMPAMG!"
echo CLOSEAPP 1 >> "!TMPAMG!"
echo DONEDLG 0 >> "!TMPAMG!"
echo MAXFILES OFF >> "!TMPAMG!"
echo STDOUTPUTFMT AVI >> "!TMPAMG!"
echo AVI ADDJUNKBEFOREHEADERS 0 >> "!TMPAMG!"
echo AUDIO INTERLEAVE 4 FR >> "!TMPAMG!"
echo PRELOAD 200 >> "!TMPAMG!"
echo AVI HAALIMODE 0 >> "!TMPAMG!"
echo OPENDML 0 >> "!TMPAMG!"
echo LEGACY 0 >> "!TMPAMG!"
echo RECLISTS 0 >> "!TMPAMG!"
echo END WITH>> "!TMPAMG!"
echo START !MUXFLN!>> "!TMPAMG!"
ENDLOCAL
)
mkdir out
for %%f in (*.amg) DO ("AVIMux_GUI.exe" "%%~ff")
nbarzgar
13th May 2009, 06:40
Hey there,
it's an old thread, I know, but it touches my problem and I hope someone notices this:
I appreciate the work done on these scripts. I need something similar, but simpler:
batch-muxing of video-only.avi and .mp3 into avi.
(Should I start a new thread?)
Could you/someone explain the values used in the script - or point me to the relevant newbie-manual/documentation?
I am not entirely new to batch-files, but I am new to Avimux gui's requirements and did not really get on with the helpfile on it's homepage. :o
What does 'setlocal' mean, for example, why would I need/use it?
Why do you use screamers around the 'TMPAMG' and what does 'TMPAMG' mean? etc...
Thank you!
buzzqw
13th May 2009, 07:06
HINT: HDConvertToX use avimux_gui for avi muxing
just check (after adding a job in queue) the mux.amg in \applications folder
and here the documentation about avimux scripting
http://www.alexander-noe.com/video/amg/script.html
BHH
nbarzgar
13th May 2009, 07:12
Thanks, this was fast!
I'll try to make do... and post back, when in doubt.
nbarzgar
14th May 2009, 10:50
@buzzqw
I looked at the sample script again and would like to use it.
But how would I as a newbie in these matters know, which variables are acceptable? Is it just programmers' expert knowledge?
Is there another way? Like using mencoder?
I tried ffmpeg, but the files it produces are not seekable in my standalone.
I used this in mencoder and it worked for single files, not if I use batch-variables:
mencoder "filename.avi" -ovc copy -oac copy -mc 0 -noskip -noodml -audiofile "filename.mp3" -o "completed.avi"
This batch not working, since mencoder does not find the files:
for %%F in (*.avi,*.mp3) do "path\to\mencoder" "%%F" -ovc copy -oac copy -mc 0 -noskip -noodml -audiofile "%%F" -o "%%F_new.avi"
Replacing the second and third variable with this didn't work either:
for %%F in (*.avi,*.mp3) do "path\to\mencoder" "%%F.avi" -ovc copy -oac copy -mc 0 -noskip -noodml -audiofile "%%F.mp3" -o "%%F_new.avi"
Thank you for any help or suggestions! :)
J_Darnley
14th May 2009, 11:14
How about:
for %%F in (*.avi) do "path\to\mencoder" "%%~F" -ovc copy -oac copy -mc 0 -noskip -noodml -audiofile "%%~nF.mp3" -o "%%~nF_new.avi"
But this will only work if files are: filename.avi and filename.mp3
If you want documentation try searching in the local "Help and Support" feature (this is what it's called on XP) for a-z and then look at the Command-line reference A-Z. Alternatively try the /? switch for most commands, e.g. for /?
nbarzgar
14th May 2009, 12:49
If you want documentation try searching in the local "Help and Support" feature (this is what it's called on XP) for a-z and then look at the Command-line reference A-Z. Alternatively try the /? switch for most commands, e.g. for /?
Thanks, don't know why I didn't think of that... I only tried the switch and that's not very informative, just the absolute basics.
Of course it helps with batch commands.
But the combination of batch with, e.g. Avimux GUI script and proper variables for Avimux GUI or mencoder are what bothered me.
I tried your suggestion and it worked like a charm! Not only smoothly, the files are seekable on the standalone now!
:thanks:
Thanks for fast answers all round!
deng17
13th May 2010, 15:38
I got this line for demuxing mp3's in an AVI
for %%f in (*.avi) DO ("ffmpeg.exe" -i "%%f" -acodec copy -vn -y "audio\%%~nf.mp3")
How do I add it in the "total batch" script that celtic_druid provided?
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.