DEV Community

Discussion on: Concatenate Videos Together Using ffmpeg!

Collapse
andr_dessent_18eee53f6af profile image
André Dessent

Hi! thanks for this info! i have a question: is it possible to program a list of concatenation to do? for exemple: i have 50 videos, and i want to merge each of them with the same intro video with my brand. do i have to do 50 times the same operation, or can i program it?
thanks!

Collapse
dak425 profile image
Donald Feury Author • 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
Collapse
andr_dessent_18eee53f6af profile image
André Dessent

Thanks for your quick answer! sorry buy i'm a beginner with programming and ffmpeg and this programm would make me win a lot of time! i have a question concerning concatenation:
i have two files
1-video1 is an intro: mp4 file, 1280x720, 25 fps, with only one stream (only video, no audio)
2-video2: mp4 file, 1920x1080, 25 fps
i would like to change video2 resolution to 1280x720, and then concatenate video1 and the new video2.
is there a way to do that in one command?
thanks!