How to concatenate two MP4 files using FFmpeg?

后端 未结 22 3401
遇见更好的自我
遇见更好的自我 2020-11-22 02:32

I\'m trying to concatenate two mp4 files using ffmpeg. I need this to be an automatic process hence why I chose ffmpeg. I\'m converting the two files into .ts files and th

22条回答
  •  没有蜡笔的小新
    2020-11-22 03:19

    Here is a script (works for an arbitrary number of specified files (not just all in the working directory), without additional files, also works for .mov; tested on macOS):

    #!/bin/bash
    
    if [ $# -lt 1 ]; then
        echo "Usage: `basename $0` input_1.mp4 input_2.mp4 ... output.mp4"
        exit 0
    fi
    
    ARGS=("$@") # determine all arguments
    output=${ARGS[${#ARGS[@]}-1]} # get the last argument (output file)
    unset ARGS[${#ARGS[@]}-1] # drop it from the array
    (for f in "${ARGS[@]}"; do echo "file '$f'"; done) | ffmpeg -protocol_whitelist file,pipe -f concat -safe 0 -i pipe: -vcodec copy -acodec copy $output
    

提交回复
热议问题