0

So I am using the following to convert all our videos in /home/vids to mp4 and output them in /home/vids2 but now I would like to add another video that plays before and after each video in /home/vids.

The video link is /home/intro/play.mp4 this video should be played before and after each of the videos in /home/vids. To clarify if /home/intro/play.mp4 is 10 seconds long and if a video in `/home/vids' is 30 seconds long then the finished video should be 50 seconds long after you combine them.

find /home/vids -type f -execdir ffmpeg -i '{}' -filter:v drawtext="fontfile=/root/FreeSans.ttf:text='TEXT EXAMPLE':fontcolor=black@1.0:fontsize=24:y=h-line_h-30:x=w/20*mod(t\,60)" -f mp4 -vcodec libx264 -preset fast -profile:v main -acodec aac -movflags +faststart '/home/vids2/{}.mp4' \;
0

If the videos are encoded using the same codecs you can utilize the concat operator.

If you have media files with exactly the same codec and codec parameters you can concatenate them as described in "Concatenation of files with same codecs". If you have media with different codecs you can concatenate them as described in "Concatenation of files with different codecs" below.

$ cat build_ffmpegs.bash
#!/bin/bash

intro=/home/intro/play.mp4
outro=/home/intro/play.mp4

cd /home/vid

for i in vid*; do
    ffmpeg -f concat -safe 0 \
      -i < <(printf "file '%s'\n" $intro $(readlink -f $i) $outro) \
      -c copy /home/vid2/output_${i}
done

Running this will generate ffmpeg commands like so:

ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid1.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid1.mp4
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid2.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid2.mp4
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid3.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid3.mp4
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid4.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid4.mp4
ffmpeg -f concat -safe 0 -i < <(printf "file '%s'\n" /home/intro/play.mp4 /home/vid/vid5.mp4 /home/intro/play.mp4) -c copy /home/vid2/output_vid5.mp4

You should be able to adapt the ffmpeg commands to whatever other specifics you need from here.

References

|improve this answer|||||

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.