topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday December 15, 2024, 8:16 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Append audio to video - command line  (Read 3840 times)

Masonjar13

  • Participant
  • Joined in 2014
  • *
  • Posts: 35
    • View Profile
    • Read more about this member.
    • Donate to Member
Append audio to video - command line
« on: August 09, 2014, 09:45 PM »
I'm looking for a way to append a single mp3 with a single mp4. I have several hundred video/audio pairs that need this done. I'm not doing them each by hand, which is why I specifically need a command-line software. I tried with Avidemux:
Code in AHK
Code: Autohotkey [Select]
  1. Loop, *.mp3
  2. {
  3.     StringReplace,vname,A_LoopFileName,mp3,mp4
  4.     RunWait, %Comspec% /c avidemux --load %vname% --external-mp3 %A_loopFileName% --audio-map --save /done/%A_LoopFileName% --output-format MP4 --quit
  5. }

But all that does is open the program in a window. Same response when ran directly from the cmd prompt. Are there any other programs out there that can do this? Or is there just something wrong with my commands?
Tox ID: 065459DFC23CA5D238F2334168150B8727B1D0826C80DD2F49F35B612B401A0837F89E7C9C86

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Append audio to video - command line
« Reply #1 on: August 10, 2014, 04:40 PM »
Try this ffmpeg method:
ffmpeg -i video.mp4 -i audio.mp3 -map 0:v -map 1:a -codec copy -shortest out.mp4

Edit: Afterwards realized you wrote "append". If you by that meant "add an audio track to play in parallel with the video" then the ffmpeg code should work. But not if you meant concatenation (first video, then afterwards some audio).
« Last Edit: August 10, 2014, 04:47 PM by Nod5 »

Masonjar13

  • Participant
  • Joined in 2014
  • *
  • Posts: 35
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Append audio to video - command line
« Reply #2 on: August 10, 2014, 04:58 PM »
My mistake on the wording. Yes, I did mean to have them parallel. I'll try it out when I can and post back, thanks!
Tox ID: 065459DFC23CA5D238F2334168150B8727B1D0826C80DD2F49F35B612B401A0837F89E7C9C86

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Append audio to video - command line
« Reply #3 on: August 11, 2014, 06:21 AM »
You want to multiplex them, ie. mux them together.

Using nod5's ffmpeg command line above, this command file will do every pair in a directory:

Code: Text [Select]
  1. @echo off
  2. rem MuxIt.cmd <folder>
  3. rem
  4. rem Put ffmpeg.exe in your PATH or edit to include full path to it
  5. pushd "%~1"
  6. for %%a in ("*.mp4") do (
  7.   ffmpeg.exe -i "%%~a" -i "%%~na.mp3" -map 0:v -map 1:a -codec copy -shortest "%%~na-mux.mp4"
  8. )
  9. popd

eg.

"te st.mp4" and "te st.mp3" will become "te st-mux.mp4"

EDIT: BTW, your original AHK script probably would have worked if you'd used the AVIDemux CLI binary, (avidemux2_cli.exe) - not sure, I've always used its GUI version.
« Last Edit: August 11, 2014, 02:29 PM by 4wd »