E
E
Evgeny Ivanov2019-12-24 12:26:11
PHP
Evgeny Ivanov, 2019-12-24 12:26:11

How to properly split video using ffmpeg?

I cut the ffmpeg video file with the preservation of audio tracks.

echo Y | ffmpeg -i original_video.mkv -map 0:a -map 0:v -ss 00:00:04 -codec copy -t 10 cut_1.mkv 
echo Y | ffmpeg -i original_video.mkv -map 0:a -map 0:v -ss 00:00:14 -codec copy -t 20 cut_2.mkv

I open the resulting files in VLC media player.
When playing cut_1.mkv, I see a black screen for the first second, but there is a corresponding sound.
The video then plays normally. And at the end, about 0.3 seconds, the video jumps right to the end, that is, these 0.3 seconds are missing.
When playing cut_2.mkv everything is the same, but I see a black screen for the first 4 seconds.
And at the end of the video ends (jumps to the beginning) at 19 seconds, although its duration is 20.
I checked it in different players.
Glitches are different, but one way or another there are always problems at the beginning of the video or at the end.
I cut the video using MP4Splitter - a program using ffmpeg. The same glitches.
I cut the video using Movavi Video Editor 15 Plus (it looks like it will recode the video when saving the fragment). Everything was cut normally, without black screens and other glitches.
How to properly split video using ffmpeg?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-12-24
@tumbler

The problem is that you don't start cutting from the keyframe, and transcoding is prohibited. Hence the blackness to the first I-frame. The -ss solution is based on the fact that ffmpeg can jump keyframes without decoding, and if -ss comes before -i, then the stream will start to be cut off exactly from the next keyframe, and not from the place you specified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question