How to merge videos by avconv?

前端 未结 10 2196
逝去的感伤
逝去的感伤 2021-01-30 17:12

I have several chunks in folder.

0001.mp4
0002.mp4
0003.mp4
...
0112.mp4

I would like to merge them into full.mp4

I tried to use:

相关标签:
10条回答
  • 2021-01-30 17:22

    mp4 files cannot be simply concatenated, as the "accepted" answer suggests.

    If you run that, and that alone, you'll end up with output.mp4 having only the contents of file1.mp4.

    That said, what you're looking to do in the original question can in fact be done, as long as you split original file into mpeg streams correctly.

    The following commands will split input.mp4 into 3x 60 second segments, in file[1-3].ts:

    avconv -ss 0 -i input.mp4 -t 60 -vcodec libx264 -acodec aac \
        -bsf:v h264_mp4toannexb -f mpegts -strict experimental -y file1.ts
    avconv -ss 0 -i input.mp4 -t 60 -vcodec libx264 -acodec aac \
        -bsf:v h264_mp4toannexb -f mpegts -strict experimental -y file2.ts
    avconv -ss 0 -i input.mp4 -t 60 -vcodec libx264 -acodec aac \
        -bsf:v h264_mp4toannexb -f mpegts -strict experimental -y file3.ts
    

    You can then put them back together much as the other answer suggests:

    avconv -i concat:"file1.ts|file2.ts|file3.ts" -c copy \
       -bsf:a aac_adtstoasc -y full.mp4
    

    I used this process to create a scalable, parallel transcoder as described at:

    • http://blog.dustinkirkland.com/2014/07/scalable-parallel-video-transcoding-on.html
    0 讨论(0)
  • 2021-01-30 17:24
    avconv -i concat:file1.mp4\|file2.mp4 -c copy output.mp4
    

    I don't know if works with any container's type ( worked for me with AVI ).

    0 讨论(0)
  • 2021-01-30 17:26

    After no getting an answer to the error message I was having with all of these similar answers:

    ~ avconv -i 'concat:' -c copy test.mp4
    avconv version 12.3, Copyright (c) 2000-2018 the Libav developers
      built on Jan 22 2019 21:47:11 with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
    concat:: Protocol not found
    

    I dug through some Google results, went into the bug tracker, and found these:

    • https://lists.libav.org/pipermail/libav-bugs/2017-October/005736.html
    • https://bugzilla.libav.org/show_bug.cgi?id=1026#c4
    • https://bugzilla.libav.org/show_bug.cgi?id=1083
    • https://bugzilla.libav.org/buglist.cgi?bug_status=all&content=concat&no_redirect=1&order=Importance&product=&query_format=specific

    Seems it was not only disabled at some point, but removed in version 12, but my build 12.3 on Mac 10.13.6 from Homebrew still has "concat" listed in the input protocols, and I see it in the documentation as well, thus that 1 outstanding bug report.

    I've had some luck using this command:

    cat *.VOB | avconv -i - -c copy test.mp4
    
    0 讨论(0)
  • 2021-01-30 17:30

    I am using ffmpeg command to do this. Here is example:

    ffmpeg -i concat:/dev/null|file1.ts|file2.ts -c copy -bsf:a aac_adtstoasc -y output.mp4
    

    Take a look at this github project for Distributed parallel video trascoding

    0 讨论(0)
  • 2021-01-30 17:35

    This one works for me:

    avconv -i "concat:001.mp4|002.mp4|003.mp4" -c copy full.mp4
    

    Just concats all the files into one mp4 without re-encoding them.

    0 讨论(0)
  • 2021-01-30 17:38

    This method will do for concating raw *.avi files only, I suppose. But since lots of people willing to join avi files will end up viewing this question I'll post my answer here anyway:

    cat *.avi > out_tmp.avi
    avconv -i out_tmp.avi -c copy output.avi
    

    One more time: works for uncompressed *.avi files only.

    0 讨论(0)
提交回复
热议问题