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
443 443
444/**444/**
445 * Find the next packet in the interleaving queue for the given stream.445 * Find the next packet in the interleaving queue for the given stream.
446 * The packet is not removed from the interleaving queue, but only446 * The pkt parameter is filled in with the queued packet, including
447 * a pointer to it is returned.447 * references to the data (which the caller is not allowed to keep or
448 * modify).
448 *449 *
449 * @return a pointer to the next packet, or NULL if no packet is queued450 * @return 0 if a packet was found, a negative value if no packet was found
450 * for this stream.
451 */451 */
452const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);452int ff_interleaved_peek(AVFormatContext *s, int stream,
453 AVPacket *pkt, int add_offset);
453 454
454#endif /* AVFORMAT_INTERNAL_H */455#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
3262 for (i = 0; i < s->nb_streams; i++) {3262 for (i = 0; i < s->nb_streams; i++) {
3263 MOVTrack *track = &mov->tracks[i];3263 MOVTrack *track = &mov->tracks[i];
3264 if (!track->end_reliable) {3264 if (!track->end_reliable) {
3265 const AVPacket *next = ff_interleaved_peek(s, i);3265 AVPacket pkt;
3266 if (next) {3266 if (!ff_interleaved_peek(s, i, &pkt, 1)) {
3267 track->track_duration = next->dts - track->start_dts;3267 track->track_duration = pkt.dts - track->start_dts;
3268 if (next->pts != AV_NOPTS_VALUE)3268 if (pkt.pts != AV_NOPTS_VALUE)
3269 track->end_pts = next->pts;3269 track->end_pts = pkt.pts;
3270 else3270 else
3271 track->end_pts = next->dts;3271 track->end_pts = pkt.dts;
3272 }3272 }
3273 }3273 }
3274 }3274 }
libavformat/mux.c+18−4
@@ -357,6 +357,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 356 unmodified lines
357static int write_packet(AVFormatContext *s, AVPacket *pkt)357static int write_packet(AVFormatContext *s, AVPacket *pkt)
358{358{
359 int ret;359 int ret;
360 // If the timestamp offsetting below is adjusted, adjust
361 // ff_interleaved_peek similarly.
360 if (s->avoid_negative_ts > 0) {362 if (s->avoid_negative_ts > 0) {
361 AVRational time_base = s->streams[pkt->stream_index]->time_base;363 AVRational time_base = s->streams[pkt->stream_index]->time_base;
362 int64_t offset = 0;364 int64_t offset = 0;
@@ -614,15 +616,27 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, · 251 unmodified lines
614 }616 }
615}617}
616 618
617const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream)619int ff_interleaved_peek(AVFormatContext *s, int stream,
620 AVPacket *pkt, int add_offset)
618{621{
619 AVPacketList *pktl = s->internal->packet_buffer;622 AVPacketList *pktl = s->internal->packet_buffer;
620 while (pktl) {623 while (pktl) {
621 if (pktl->pkt.stream_index == stream)624 if (pktl->pkt.stream_index == stream) {
622 return &pktl->pkt;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 }
623 pktl = pktl->next;637 pktl = pktl->next;
624 }638 }
625 return NULL;639 return AVERROR(ENOENT);
626}640}
627 641
628/**642/**

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