How to cut from multiple input videos and concat to single video using ffmpeg?

后端 未结 1 1845
面向向阳花
面向向阳花 2021-01-14 18:01

I did something like this

ffmpeg -i video1.mp4 -ss 00:01:00 -to 00:03:00 -i video2.mp4 -ss 00:05:00 -to 00:02:00 -c copy cut.mp4

Apparently

相关标签:
1条回答
  • 2021-01-14 18:45

    You have to tell ffmpeg that you want to concatenate each video and audio stream:

    ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex
    "[0:v]trim=start=60:end=180,setpts=PTS-STARTPTS[v0];
     [0:a]atrim=start=60:end=180,asetpts=PTS-STARTPTS[a0];
     [0:v]trim=start=300:end=420,setpts=PTS-STARTPTS[v1];
     [0:a]atrim=start=300:end=420,asetpts=PTS-STARTPTS[a1];
     [v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]"
    -map "[v]" -map "[a]" output.mp4
    
    • (a)trim creates each segment, (a)setpts resets the segment timestamps (recommended for concat), and concat concatenates each segment. See FFmpeg Filters for documentation on each filter.

    • I broke up the command into separate lines for readability. Reconstitute into a single line or add whatever line-break characters are suitable for your environment.

    • This will re-encode the video but cutting will be accurate. If you want to avoid re-encoding see the concat demuxer but cutting may not be accurate and results may not be satisfactory.

    • The -to value cannot be smaller than the -ss value, so I'm going to assume you meant -ss 00:05:00 -to 00:07:00 instead of -ss 00:05:00 -to 00:02:00.

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