1

I try to figure out how to use FFmpeg to trim videos. I have created a 30 second .mov screen capture using Apple's QuickTime player, and then tried to trim it using three different ways:

  1. Using -copyts, without re-encoding

    ffmpeg -copyts -ss 00:00:10 -i input.mov -to 00:00:15 -map 0 -c copy output.mov
    
  2. Using -copyts, with re-encoding

    ffmpeg -copyts -ss 00:00:10 -i input.mov -to 00:00:15 -c:v libx264 -crf 23 -c:a aac -b:a 192k output.mov
    
  3. Using -trim (with re-encoding, which is the only option):

    ffmpeg -i input.mov -vf trim=10:15 output.mov
    

No matter which approach I tried, the output video is always 15 seconds long and the first 10 seconds of that is just a black screen, whereas what I expected is a 5-second video and without the black screen.

All the three solutions are from here: Cut part from video file from start position to end position with FFmpeg (answers by @slhck and @malat), and are very high-voted, so I expect they should work without issues, but they don't. Why is that? Is there a problem with the commands, or with the video?

The video is uploaded here: https://github.com/jsx97/test/blob/main/input.mov

12
  • All three work fine for me. Might be your player, or an issue with your version of ffmpeg. Incidently, the file has no audio, so second option does not require audio parameters.
    – Sark
    Commented Jun 12 at 13:40
  • @Sark Which player you use? "All three work fine for me." - You mean there is no "black screen"?
    – jsx97
    Commented Jun 12 at 13:47
  • 1
    @jax97...MPC-HC and no black screen. Try trim=10:15,setpts=PTS-STARTPTS for third script.
    – Sark
    Commented Jun 12 at 14:03
  • @Sark Yes, this fixed the "black screen" problem. But why does it work for one player and not for another? Does it mean that using setpts=PTS-STARTPTS is a recommended practice, which is often overlooked?
    – jsx97
    Commented Jun 12 at 14:09
  • 1
    I recommend you to first try without re-encoding (using -c copy), without -copyts (so that the timestamp of the first output frames starts from zero), and with -t 5 instead of -to 15: ffmpeg -y -ss 00:00:10 -i input.mov -t 5 -c copy output.mov. In case it's not working, try the other solutions. The reason for the black screen is that the timestamp of the first frame is 10.0 (seconds) due to -copyts, and not zero. We may check the PTS timestamps using FFprobe: ffprobe -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries frame=pts_time output.mov.
    – Rotem
    Commented Jun 12 at 20:55

0

You must log in to answer this question.

Browse other questions tagged .