[FFmpeg-trac] #7640(undetermined:new): first part of cut out video only contains audio
FFmpeg
trac at avcodec.org
Sun Dec 30 06:05:30 EET 2018
#7640: first part of cut out video only contains audio
-------------------------------------+-------------------------------------
Reporter: hanshenrik | Owner:
Type: defect | Status: new
Priority: normal | Component:
Version: git-master | undetermined
Keywords: | Resolution:
Blocking: | Blocked By:
Analyzed by developer: 0 | Reproduced by developer: 0
-------------------------------------+-------------------------------------
Comment (by erikbs):
This happens if you copy a video stream and the first frame in the output
video is not a keyframe. Keyframes are the only frames that actually
contain a complete picture – the ones in-between are just stored as diffs,
since that is more efficient when there are relatively few changes between
frames. If you cut a video and the first frame is not a keyframe, then you
will have nothing to calculate the intermediate frames from, which is why
the video is usually rendered black / random colours until the next
keyframe (usually a couple of seconds later).
Replying to [ticket:7640 hanshenrik]:
> this doesn't happen if omitting "-c:v copy -c:a copy"
It is because if you do not specify ''copy'', the stream will be re-
encoded and in the process ffmpeg will have access to the entire data
stream. A new keyframe will be written as the first frame in the output
stream. With ''copy'', ffmpeg will just raw copy the stream from the
specified timecode, even if you need earlier parts of the stream to play
it correctly (in this case the keyframe used to calculate the first few
frames).
There is no way to cut the video between keyframes without either
experiencing this or re-encoding the stream. Thus you have two options:
1. Re-encode the video (you can still do -c:a copy, the audio can usually
be cut at any time)
2. Cut the video a little earlier or later, so that a keyframe is the
first one. I do not know how that is done efficiently with ffmpeg (i.e.
without trial and error), but it is easy to do it with the GUI tool
Avidemux, which has buttons for skipping to the next/prev keyframe (just
remember to set the correct container format, it seems to default to AVI).
End points need not be keyframes.
If you want to avoid re-encoding the entire clip, you can also combine the
solutions: re-encode the first two seconds from your desired cutting point
until the first keyframe and cut the video losslessly from the first
keyframe, then concatenate the two clips.
--
Ticket URL: <https://trac.ffmpeg.org/ticket/7640#comment:1>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list