0

So, I'm trying to cut a video as such:

ffmpeg -ss 35:58.907 -i Source.mkv \
  -copyts -to 36:43.857 -map 0:0 -map 0:2 \
  -c:v libx264 -preset slow -tune film -crf 18 -vf "ass=Source.ass" \
  -c:a copy Destination.mkv

Afterwards, I try playing Destination.mkv using MPC-HC.

Audio was cut perfectly, but the Video starts with several seconds of black/blank frames. Audio & Video remains in perfect sync, though.

How can I prevent these black frames from happening?

1
  • Although I sometimes have seen this problem (with captured DVB-streams), I am not able to reproduce your error. Could you please provide a sample? I'd think that it is caused by -copyts; however, I cannot prove my theory because in my setup(s), everything works flawlessly.
    – flolilo
    Sep 10, 2017 at 17:28

1 Answer 1

0

Okay, so my problem is definitely caused by "missing key frames".

So, to fix it, I now do it in two stages:

(Note that the original source timestamp I want to cut from is 35:58.907):

# Move forward the cutting timestamp by N seconds. Here, N=6.00
ffmpeg -ss 35:52.907 -i Source.mkv \
  -copyts -to 36:43.857 -map 0:0 -map 0:2 \
  -c:v libx264 -preset slow -tune film -crf 18 -vf "ass=Source.ass" \
  -c:a copy Intermediate.mkv

This step produces several seconds of black frames at the beginning, but it does have the section I want to cut from properly. Then I follow up with:

# Re-cut the video starting N seconds forward. Here, N=6.00
ffmpeg -i Intermediate.mkv -ss 00:06.000 \
  -c:v libx264 -preset slow -tune film -crf 18 \
  -c:a copy Destination.mkv

Yes, I have to encode the video twice, so there would be some degradation, but visually I see no degradation, so I think this two-step processing is acceptable for my needs.

(And if visual artifacts start appearing, I can use a much lower -crf for the first step, say 15, or 12, or -- God forbid -- even 0 if need be.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .