I'm new to bash scripting. I need to find a way of joining .wav's and .mp4's (they are of same length) together as there's about a thousand files I need to go through.

Any suggestions and possible examples I could try? There's probably too many ways of doing this, I looked at avconv as it seemed simple to use, but open to other suggestions (vlc, ffmpeg?)

Also saw this ffmpeg script for a single file:


The original video and audio file names would be identical except for extension.


The following should be equivalent.

for filename in *.mp4; do
    ffmpeg -i "${stub}.wav" -i "${stub}.mp4" -acodec copy -vcodec copy "newfiles/${stub}.avi"
  • The script is in the same folder as all files, but I'm getting ".wav: No such file or directory" after running it. I tried adding a full directory path to the first line without any success: for filename in "/some/path/.mp4"; do – Jonesints Sep 21 '15 at 11:46
  • I figured out that taking the inverted commas from *.mp4 on the first line fixes this issue. I now get an encoding error: 'Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input' here's the full output: pastebin.com/nZA7kFD0 Any suggestions? – Jonesints Sep 21 '15 at 17:24
  • I'm stuck making progress, with for filename in *.mov; do stub="${filename%.*}" /usr/local/Cellar/ffmpeg/2.8/bin/ffmpeg -i movs/"${stub}".mov -i m4a/"${stub}".m4a -vcodec copy -acodec copy -map 0:0 -map 1 MERGED_VIDEOS_MOV/"${stub}.mp4" done I just get movs/.mov: no such file or directory. I'm pretty certain it's to do with the way ffmpeg is handling escaping, but I've tried pretty much everything! – Jonesints Sep 30 '15 at 11:47
  • That suggests "${stub}" is being replaced with nothing. Remove the ffmpeg line and just try echoing out all the values of $stub and see if you can see the problem there. – Oli Sep 30 '15 at 12:22
  • echoing $stub lists the following MERGED_VIDEOS_MOV MERGED_VIDEOS_MP4 batch_process_join_wav_mov.sh batch_process_join_wav_mp4.sh m4a movs – Jonesints Sep 30 '15 at 12:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.