You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
lavf: Only initialize s->offset once when using avoid_negative_ts make_zero
When given a stream starting at dts=0, it would previously consider s->offset as uninitialized and set an offset when the second packet was written, ending up writing two packets with dts=0. By initializing this field to AV_NOPTS_VALUE, we make sure that we only initialize it once, on the first packet. Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
@@ -329,12 +329,12 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
AVRational time_base = s->streams[pkt->stream_index]->time_base;
|
AVRational time_base = s->streams[pkt->stream_index]->time_base;
|
||||||
int64_t offset = 0;
|
int64_t offset = 0;
|
||||||
|
|
||||||
if (!s->offset && pkt->dts != AV_NOPTS_VALUE &&
|
if (s->offset == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE &&
|
||||||
(pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
|
(pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
|
||||||
s->offset = -pkt->dts;
|
s->offset = -pkt->dts;
|
||||||
s->offset_timebase = time_base;
|
s->offset_timebase = time_base;
|
||||||
}
|
}
|
||||||
if (s->offset)
|
if (s->offset != AV_NOPTS_VALUE)
|
||||||
offset = av_rescale_q(s->offset, s->offset_timebase, time_base);
|
offset = av_rescale_q(s->offset, s->offset_timebase, time_base);
|
||||||
|
|
||||||
if (pkt->dts != AV_NOPTS_VALUE)
|
if (pkt->dts != AV_NOPTS_VALUE)
|
||||||
|
@@ -101,6 +101,7 @@ AVFormatContext *avformat_alloc_context(void)
|
|||||||
ic = av_malloc(sizeof(AVFormatContext));
|
ic = av_malloc(sizeof(AVFormatContext));
|
||||||
if (!ic) return ic;
|
if (!ic) return ic;
|
||||||
avformat_get_context_defaults(ic);
|
avformat_get_context_defaults(ic);
|
||||||
|
ic->offset = AV_NOPTS_VALUE;
|
||||||
|
|
||||||
ic->internal = av_mallocz(sizeof(*ic->internal));
|
ic->internal = av_mallocz(sizeof(*ic->internal));
|
||||||
if (!ic->internal) {
|
if (!ic->internal) {
|
||||||
|
Reference in New Issue
Block a user