ffmpeg video splitting less then 10 sec gives black clip - ubuntu 18.04 LTS

Viewed 304

I am using FFmpeg version 4.3-2~18.04.york0 on AWS EC2 server for video splitting, while I split video less then 11 seconds the output.mp4 gives a blank video. I have tried the same thing with my local MAC and Ubuntu 19 but it works fine.

ffmpeg -i input.mp4 -ss 00:01:10 -to 00:01:15 -c:v copy -c:a copy output.mp4
2 Answers

What you can try to do is use the duration flag instead of the end position flag in your command:

ffmpeg -i input.mp4 -ss 00:01:10 -t 10 -c:v copy -c:a copy output.mp4

-t 10 cuts 10 seconds from the starting position that -ss has specified.

If that still doesn't work, it would be helpful if you could clarify your question a bit:

  • Are you using the same version of ffmpeg on the Mac and Ubuntu systems where it works fine?
  • Are you using the same configuration (visible with ffmpeg --help) on all systems?
  • Also, what's confusing to me is your question as a whole: You write that you have issues with videos of less than 11 seconds, but what you're trying to do in the command is cut 5 seconds of a video that seems to be at least 1min10s long (based on the starting position of 00:01:10).

It usually happens because the video segment you want to extract doesn't contain any I-frame (key frame). A video typically has one key frame every 10 seconds, so it's likely that your video segment doesn't have any because its duration is only 5 seconds.

There is some caveat on using video codec copy (-c:v copy). In your case it's impossible to do a codec copy because your video segment doesn't have any key frame, hence a blank video.

To trim a video segment that has no key frame, you need to reencode it, i.e. by using other video codec option than copy, such as -c:v x264. To preserve the quality, you can set crf to 17 or 18:

ffmpeg -i input.mp4 -ss 00:01:10 -to 00:01:15 -c:v x264 -crf 17 -c:a copy output.mp4

Reencoding is always much slower than codec copy, but because the duration is only 5 seconds, it should take less than a minute to reencode it (depends on the CPU).

I'm not sure why your original command was working on your local computer. It might be due to a different version of ffmpeg or a different video source (e.g. input.mp4 in your local happens to have a key frame in the timestamp range).

Related