DEV Community

Discussion on: Concatenate Videos Together Using ffmpeg!

Collapse
 
dak425 profile image
Donald Feury • Edited

You could definitely script it, just loop over each file in the directory where your videos are stored and run the same command

Could look something like this:

#! /usr/bin/env sh

dir=$1
intro=$2
out=$3

for f in $dir/*.mp4
do
    ffmpeg -i $intro -i $f -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" "$out/$(basename $f)"
done
Enter fullscreen mode Exit fullscreen mode

I just whipped that up real fast and not sure if it works 100% but the idea is that it will:

  • Loop over all the files with .mp4 file extensions in the given directory
  • Run an ffmpeg command that use as inputs, the file given as the argument for the intro and the file of the current iteration of the loop, and write the newly combined version to a given directory