SHA256
Fix Zero Duration Of Last Video Frame
This commit is contained in:
1 parent
fab189ff3b
commit
7bb47e4974
1 file changed
+10
@@ -1594,6 +1594,16 @@ namespace ADOFAIRenderer.Util.FFmpeg
|
||||
if (response < 0)
|
||||
throw new Exception($"Error occurred while receiving packet from encoder: {GetFFmpegErrorString(response)} (Code: {response})");
|
||||
|
||||
// Packet duration: 1 tick of the codec time base (1 / framerate), the display time of one frame
|
||||
// at the constant frame rate of the output. Applied when the encoder leaves it unknown (0).
|
||||
// The encoders output 0 here because libavcodec clears the frame duration
|
||||
// unless AV_CODEC_FLAG_FRAME_DURATION is set.
|
||||
// The mp4/mov muxer takes the length of the last sample from the duration of the last packet;
|
||||
// with 0 the last frame has no display time and the edit list ends before it.
|
||||
// Reference: https://github.com/FFmpeg/FFmpeg/blob/release/8.0/libavcodec/encode.c (encode_send_frame_internal: frame duration)
|
||||
// Reference: https://github.com/FFmpeg/FFmpeg/blob/release/8.0/libavformat/movenc.c (ff_mov_write_packet: track_duration)
|
||||
if (_pPacket->duration <= 0)
|
||||
_pPacket->duration = 1;
|
||||
// Convert PTS/DTS from codec timebase → stream timebase
|
||||
ffmpeg.av_packet_rescale_ts(_pPacket, _pCodecContext->time_base, _pVideoStream->time_base);
|
||||
_pPacket->stream_index = _pVideoStream->index;
|
||||
|
||||
Reference in new issue
Block a user