How to concatenate two MP4 files using FFmpeg?

后端 未结 22 3094
遇见更好的自我
遇见更好的自我 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:25

    After various tries below script worked for me on windows 10 powershell.

        $files=Get-ChildItem -path e:\ -Filter *.mp4
    
    
        $files| ForEach-Object  {"file '$($_.FullName)'"}| Out-File -FilePath e:\temp.txt -Encoding ASCII
    
    
        if (-not (test-path "e:\ffmpeg\bin\ffmpeg.exe")) {throw "e:\ffmpeg\bin\ffmpeg.exe needed"}
    
        E:\ffmpeg\bin\ffmpeg.exe -safe 0 -f concat -i "e:\temp.txt" -c copy -bsf:v hevc_mp4toannexb -an e:\joined.mp4
    
        # Conversion Cleanup
        Remove-Item e:\temp.txt
    

    Here first two lines create a text file temp.txt which has following content

    file 'e:\first.mp4'
    file 'e:\second.mp4'
    

    3rd, 4th lines checks if ffmpeg is available at path and create the "joined.mp4"

    The key differences from other answers are as below

    usage  of -bsf:v hevc_mp4toannexb -an
    

    for my mp4 file above worked, you may need to use other alternatives like below depending on your video encoding.

    h264_mp4toannexb
    

    All such possible Bitstream filters can be found at https://ffmpeg.org/ffmpeg-bitstream-filters.html

提交回复
热议问题