FFMPEG An Intermediate Guide/Concatenation

From Wikibooks, open books for an open world
Jump to navigation Jump to search

With this script, multiple videos can be put together into one file. The process uses the -c copy parameter, meaning the video file is built from the existing video streams, and no processor-intensive re-encoding is necessary.

ffmpeg_concat() {

 timestamp=$(date "+%Y%m%d%H%M%S")
  # Unlike in JavaScript, no spaces may surround the "=" equals sign to set a variable.

# generate file list
 for path in $@; do
  echo "file '$path' " >>ffmpeg_concat.$timestamp.txt
   # ffmpeg only supports apostrophes, no quotation marks.

# ask user for output file extension to specify which container format should be used by FFmpeg
printf "Output file extension: " 
read output_extension

# put it together
ffmpeg -f concat -safe 0 -i ffmpeg_concat.$timestamp.txt -c copy ffmpeg_concat.$timestamp.$output_extension
 # -safe 0  allows concatinating files outside the current working directory
 # -c copy  passes through the existing video and audio streams without re-encoding it and only multiplexes it, making the process take only a fraction of the time since disk reading/writing speeds are the only limitation.