0

I'm trying to write a concatenation script (windows) to add an intro.mp4 video to over a hundred other mp4 videos in a directory.

The codec will stay the same mp4, the intro filename will stay the same, but the main video names will change, but all are in the same directory.

I've started writing the bash script

#!/bin/bash
for file in *.mp4; do ffmpeg -i CONCAT COMMAND HERE; done

Any help would be much appreciated.

Thanks all!

  • Do you want intro.mp4 followed by all the files? Eg intro.mp4+1.mp4+2.mp4 ... or intro.mp4 + 1.mp4, and then a second file intro.mp4 + 2.mp4? – fcbsd May 2 at 14:27
  • 1
    I have done with @echo off mkdir output for %%i in (videos/*.mp4) do ( echo file 'intro.mp4' > list.txt echo file 'videos/%%~nxi' >> list.txt ffmpeg -safe 0 -y -f concat -i list.txt -c copy "output/%%~nxi" ) del list.txt Thank You much for help! – Oleg Volodchenko May 2 at 14:56
0

Something like:

ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4

Details of concatenate command can be found here. The inputs need to be a file list other wise ffmpeg errors out with unknown keyword.

The -safe 0 is not required if the file paths are relative.

So your bash script would look like:

#! /bin/bash
set -eou pipefail
NAME="file"
NEW="new-"
for file in *.mp4; 
do
    touch input.txt
    echo $NAME 'intro.mp4' >> filelist.txt
    echo $NAME $file  >> filelist.txt
    ffmpeg -f concat -safe 0 -i filelist.txt -c copy $NEW$file;
    rm filelist.txt
done

The filelist.txt should look like:

file intro.mp4
file nextvideo.mp4
| improve this answer | |
  • @OlegVolodchenko sorry the input needs to be a filelist - see new example – fcbsd May 2 at 13:11
  • probably need to edit the /usr/local/bin/bash to /bin/bash - it's not creating the filelist.txt properly as the file is not been deleted between each call - it's removing a non existent input.txt - so the filelist.txt has extra junk that will mess it up. – fcbsd May 2 at 13:32
  • it's not deleting the filelist.txt file between each go - but it's also not putting the word file into filelist.txt - each line should be file nameof.mp4 – fcbsd May 2 at 13:38
  • you could try changing the echo lines to echo file intro.mp4 >> filelist.txt and echo file $file >> filelist.txt but you will need to check if the resulting file looks like the example shown in the answer. – fcbsd May 2 at 14:00
  • the error message unknown keyword '$NAME' means that for some reason bash is not replacing $NAME with the word file in the filelist.txt if you create a filelist.txt as shown in the answer and run the ffmpeg command from the command line does it work? – fcbsd May 2 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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