ffmpeg: Combine/merge multiple mp4 videos not working, output only contains the first video

前端 未结 10 840
逝去的感伤
逝去的感伤 2020-12-22 22:48

Here is the command I am using to combine multiple videos:

ffmpeg -i 75_540_38HQ2.mp4 -i 76_70_20.mp4 -i 76_173_80.mp4 -i 81_186_35.mp4 -vcodec copy -acodec copy M         


        
相关标签:
10条回答
  • 2020-12-22 23:22

    From the ffmpeg man page "Examples" section:

    You can put many streams of the same type in the output:

    ffmpeg -i test1.avi -i test2.avi -vcodec copy -acodec copy \
           -vcodec copy -acodec copy test12.avi -newvideo -newaudio
    

    In addition to the first video and audio streams, the resulting output file test12.avi will contain the second video and the second audio stream found in the input streams list.

    The "-newvideo", "-newaudio" and "-newsubtitle" options have to be specified immediately after the name of the output file to which you want to add them.

    If you meant you want to concatenate them, the FAQ has instructions.

    I'm not sure if this question/answer belongs on SuperUser.

    0 讨论(0)
  • 2020-12-22 23:26

    You have to convert them into an MPEG format that can be easily concatenated. Below is a script I use and call "ffcat" for my GoPro videos. It essentially runs several "ffmpeg -i" commands which produce concatenate-able MPEG, which is piped to an ffmpeg command that then converts them to an H.264 mp4 file.

    It also sizes the videos to 720p but you may not want that.

    The "h264options" are flags I recently found on the internet at h264.code-shop.com

    Hope this helps, Reid


    cmd="( "
    
    h264options="-vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 \
     -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
     -me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \
     -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \
       -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10\
     -qmax 51 -qdiff 4"
    
    outfile="out-`date +%F-%H%M.%S`.mp4"
    
    for i; do
        cmd="${cmd}ffmpeg -i $i -ab 256000 -vb 10000000 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 100 -f mpeg -; "
    done
    cmd="${cmd} ) | ffmpeg -y -i - -threads 8 ${h264options} -vb 10000000 -acodec libfaac -ar 44100 -ab 128k -s 1280x720 ${outfile}"
    echo "${cmd}"
    eval ${cmd}
    
    0 讨论(0)
  • 2020-12-22 23:26

    Forget about FFmpeg, use MP4Box instead, it is easy and faster:

        mp4box -add video1.mp4 -cat video2.mp4 -cat video3.mp4 output.mp4
    

    It is available for Windows, Linux and OS X: http://www.videohelp.com/tools/mp4box

    If you are on Windows you can use YAMB which is a GUI for MP4Box that works great: http://www.videohelp.com/tools/YAMB

    UPDATE Jun-2016: FFmpeg has added a concatenation filter, more info here: https://stackoverflow.com/a/11175851/218418

    0 讨论(0)
  • 2020-12-22 23:26

    As found here, you have a few options:

    1. concat protocol:

    ffmpeg -i "concat:input1.ts|input2.ts|input3.ts" -c copy output.ts
    

    2. concat filter:

    this one I don't fully understand, you probably need to look at all the diagrams and filter graphs, but it lets you deal with multiple formats and differing codec properties

        ffmpeg -i input1.mp4 -i input2.webm -i input3.mov \
    -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \
    -map "[outv]" -map "[outa]" output.mkv
    

    3. concat demuxer:

    First, you need to generate a list file of some sort, eg. "mylist.txt"

        # this is a comment
        file '/path/to/file1.wav'
        file '/path/to/file2.wav'
        file '/path/to/file3.wav'
    

    Second, you need to run a command to use the list

    ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.wav
    
    0 讨论(0)
提交回复
热议问题