Skip to content

Instantly share code, notes, and snippets.

@schlomo
Created January 15, 2014 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schlomo/8443968 to your computer and use it in GitHub Desktop.
Save schlomo/8443968 to your computer and use it in GitHub Desktop.
Simple Video Tricks: Concatenate
#!/bin/bash
#
# concatenate several SOURCE_CONCAT_FILE_NAMES files into a mp4
# FIRST_NAME and second argument are file names or parts of a filename. All files inbetween will be concatenated.
START="$1" ; shift
END="$1" ; shift
COMMON_PREFIX=""
# find all input files
# input files are all files from FIRST_NAME to LAST_NAME
mapfile -t SOURCES < <(ls | sed -n -e "/$START/,/$END/p")
# FIRST_NAME and LAST_NAME is input file name without suffix
FIRST_NAME="${SOURCES%.*}"
LAST_NAME="${SOURCES[@]: -1:1}"
LAST_NAME="${LAST_NAME%.*}"
RESULT_FILE_NAME="Concat_${FIRST_NAME}___${LAST_NAME}.mp4"
SOURCE_CONCAT_FILE_NAMES="concat:$(for s in "${SOURCES[@]}" ; do echo -n "$s|" ; done)"
exec avconv -i "$SOURCE_CONCAT_FILE_NAMES" -codec copy "$@" "$RESULT_FILE_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment