History

movenc: Apply offsets on timestamps when peeking into interleaving queues

Martin Storsjö committed 10 years ago

Commit 785c2541 parent eccfb973 files · +30 −15Browse files

Unified · Split

3 files
  1. libavformat/internal.h +6 −5
  2. libavformat/movenc.c +6 −6
  3. libavformat/mux.c +18 −4
libavformat/internal.h+6−5
@@ -443,12 +443,13 @@ void ff_format_io_close(AVFormatContext *s, AVIOContext **pb); · 442 unmodified lines
443443
444444 /**
445445 * Find the next packet in the interleaving queue for the given stream.
446− * The packet is not removed from the interleaving queue, but only
447− * a pointer to it is returned.
446+ * The pkt parameter is filled in with the queued packet, including
447+ * references to the data (which the caller is not allowed to keep or
448+ * modify).
448449 *
449− * @return a pointer to the next packet, or NULL if no packet is queued
450− * for this stream.
450+ * @return 0 if a packet was found, a negative value if no packet was found
451451 */
452−const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);
452+int ff_interleaved_peek(AVFormatContext *s, int stream,
453+ AVPacket *pkt, int add_offset);
453454
454455 #endif /* AVFORMAT_INTERNAL_H */
libavformat/movenc.c+6−6
@@ -3262,13 +3262,13 @@ static int mov_flush_fragment(AVFormatContext *s, int force) · 3261 unmodified lines
32623262 for (i = 0; i < s->nb_streams; i++) {
32633263 MOVTrack *track = &mov->tracks[i];
32643264 if (!track->end_reliable) {
3265− const AVPacket *next = ff_interleaved_peek(s, i);
3266− if (next) {
3267− track->track_duration = next->dts - track->start_dts;
3268− if (next->pts != AV_NOPTS_VALUE)
3269− track->end_pts = next->pts;
3265+ AVPacket pkt;
3266+ if (!ff_interleaved_peek(s, i, &pkt, 1)) {
3267+ track->track_duration = pkt.dts - track->start_dts;
3268+ if (pkt.pts != AV_NOPTS_VALUE)
3269+ track->end_pts = pkt.pts;
32703270 else
3271− track->end_pts = next->dts;
3271+ track->end_pts = pkt.dts;
32723272 }
32733273 }
32743274 }
libavformat/mux.c+18−4
@@ -357,6 +357,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 356 unmodified lines
357357 static int write_packet(AVFormatContext *s, AVPacket *pkt)
358358 {
359359 int ret;
360+ // If the timestamp offsetting below is adjusted, adjust
361+ // ff_interleaved_peek similarly.
360362 if (s->avoid_negative_ts > 0) {
361363 AVRational time_base = s->streams[pkt->stream_index]->time_base;
362364 int64_t offset = 0;
@@ -614,15 +616,27 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, · 251 unmodified lines
614616 }
615617 }
616618
617−const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream)
619+int ff_interleaved_peek(AVFormatContext *s, int stream,
620+ AVPacket *pkt, int add_offset)
618621 {
619622 AVPacketList *pktl = s->internal->packet_buffer;
620623 while (pktl) {
621− if (pktl->pkt.stream_index == stream)
622− return &pktl->pkt;
624+ if (pktl->pkt.stream_index == stream) {
625+ *pkt = pktl->pkt;
626+ if (add_offset && s->internal->offset != AV_NOPTS_VALUE) {
627+ int64_t offset = av_rescale_q(s->internal->offset,
628+ s->internal->offset_timebase,
629+ s->streams[stream]->time_base);
630+ if (pkt->dts != AV_NOPTS_VALUE)
631+ pkt->dts += offset;
632+ if (pkt->pts != AV_NOPTS_VALUE)
633+ pkt->pts += offset;
634+ }
635+ return 0;
636+ }
623637 pktl = pktl->next;
624638 }
625− return NULL;
639+ return AVERROR(ENOENT);
626640 }
627641
628642 /**

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t