ffmpeg | branch: master | Hendrik Leppkes <h.lepp...@gmail.com> | Sun Nov 13 22:55:34 2016 +0100| [8fad4b4e251bb21f8871fa829b593454528aff24] | committer: Hendrik Leppkes
Merge commit '785c25443b56adb6dbbb78d68cccbd9bd4a42e05' * commit '785c25443b56adb6dbbb78d68cccbd9bd4a42e05': movenc: Apply offsets on timestamps when peeking into interleaving queues Merged-by: Hendrik Leppkes <h.lepp...@gmail.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8fad4b4e251bb21f8871fa829b593454528aff24 --- libavformat/internal.h | 13 ++++++------- libavformat/movenc.c | 14 ++++++-------- libavformat/mux.c | 29 +++++++++++++++++++---------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index da64c64..9d614fb 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -657,14 +657,13 @@ int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf /** * Find the next packet in the interleaving queue for the given stream. - * The packet is not removed from the interleaving queue, but only - * a pointer to it is returned. + * The pkt parameter is filled in with the queued packet, including + * references to the data (which the caller is not allowed to keep or + * modify). * - * @param ts_offset the ts difference between packet in the queue and the muxer. - * - * @return a pointer to the next packet, or NULL if no packet is queued - * for this stream. + * @return 0 if a packet was found, a negative value if no packet was found */ -const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream, int64_t *ts_offset); +int ff_interleaved_peek(AVFormatContext *s, int stream, + AVPacket *pkt, int add_offset); #endif /* AVFORMAT_INTERNAL_H */ diff --git a/libavformat/movenc.c b/libavformat/movenc.c index efa050e..7a726c6 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -4484,15 +4484,13 @@ static int mov_flush_fragment(AVFormatContext *s, int force) for (i = 0; i < s->nb_streams; i++) { MOVTrack *track = &mov->tracks[i]; if (!track->end_reliable) { - int64_t ts_offset; - const AVPacket *next = ff_interleaved_peek(s, i, &ts_offset); - if (next) { - track->track_duration = next->dts - track->start_dts + ts_offset; - if (next->pts != AV_NOPTS_VALUE) - track->end_pts = next->pts; + AVPacket pkt; + if (!ff_interleaved_peek(s, i, &pkt, 1)) { + track->track_duration = pkt.dts - track->start_dts; + if (pkt.pts != AV_NOPTS_VALUE) + track->end_pts = pkt.pts; else - track->end_pts = next->dts; - track->end_pts += ts_offset; + track->end_pts = pkt.dts; } } } diff --git a/libavformat/mux.c b/libavformat/mux.c index 77823a4..4d47ddc 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -692,6 +692,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) pts_backup = pkt->pts; dts_backup = pkt->dts; + // If the timestamp offsetting below is adjusted, adjust + // ff_interleaved_peek similarly. if (s->output_ts_offset) { AVStream *st = s->streams[pkt->stream_index]; int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); @@ -1180,23 +1182,30 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } } -const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream, int64_t *ts_offset) +int ff_interleaved_peek(AVFormatContext *s, int stream, + AVPacket *pkt, int add_offset) { AVPacketList *pktl = s->internal->packet_buffer; while (pktl) { if (pktl->pkt.stream_index == stream) { - AVPacket *pkt = &pktl->pkt; - AVStream *st = s->streams[pkt->stream_index]; - *ts_offset = st->mux_ts_offset; - - if (s->output_ts_offset) - *ts_offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); - - return pkt; + *pkt = pktl->pkt; + if (add_offset) { + AVStream *st = s->streams[pkt->stream_index]; + int64_t offset = st->mux_ts_offset; + + if (s->output_ts_offset) + offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); + + if (pkt->dts != AV_NOPTS_VALUE) + pkt->dts += offset; + if (pkt->pts != AV_NOPTS_VALUE) + pkt->pts += offset; + } + return 0; } pktl = pktl->next; } - return NULL; + return AVERROR(ENOENT); } /** ====================================================================== diff --cc libavformat/internal.h index da64c64,de55af5..9d614fb --- a/libavformat/internal.h +++ b/libavformat/internal.h @@@ -604,67 -442,14 +604,66 @@@ int ff_format_output_open(AVFormatConte void ff_format_io_close(AVFormatContext *s, AVIOContext **pb); /** + * Parse creation_time in AVFormatContext metadata if exists and warn if the + * parsing fails. + * + * @param s AVFormatContext + * @param timestamp parsed timestamp in microseconds, only set on successful parsing + * @param return_seconds set this to get the number of seconds in timestamp instead of microseconds + * @return 1 if OK, 0 if the metadata was not present, AVERROR(EINVAL) on parse error + */ +int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds); + +/** + * Standardize creation_time metadata in AVFormatContext to an ISO-8601 + * timestamp string. + * + * @param s AVFormatContext + * @return <0 on error + */ +int ff_standardize_creation_time(AVFormatContext *s); + +#define CONTAINS_PAL 2 +/** + * Reshuffles the lines to use the user specified stride. + * + * @param ppkt input and output packet + * @return negative error code or + * 0 if no new packet was allocated + * non-zero if a new packet was allocated and ppkt has to be freed + * CONTAINS_PAL if in addition to a new packet the old contained a palette + */ +int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecParameters *par, int expected_stride); + +/** + * Retrieves the palette from a packet, either from side data, or + * appended to the video data in the packet itself (raw video only). + * It is commonly used after a call to ff_reshuffle_raw_rgb(). + * + * Use 0 for the ret parameter to check for side data only. + * + * @param pkt pointer to packet before calling ff_reshuffle_raw_rgb() + * @param ret return value from ff_reshuffle_raw_rgb(), or 0 + * @param palette pointer to palette buffer + * @return negative error code or + * 1 if the packet has a palette, else 0 + */ +int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette); + +/** + * Finalize buf into extradata and set its size appropriately. + */ +int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf); + +/** * Find the next packet in the interleaving queue for the given stream. - * The packet is not removed from the interleaving queue, but only - * a pointer to it is returned. + * The pkt parameter is filled in with the queued packet, including + * references to the data (which the caller is not allowed to keep or + * modify). * - * @param ts_offset the ts difference between packet in the queue and the muxer. - * - * @return a pointer to the next packet, or NULL if no packet is queued - * for this stream. + * @return 0 if a packet was found, a negative value if no packet was found */ - const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream, int64_t *ts_offset); + int ff_interleaved_peek(AVFormatContext *s, int stream, + AVPacket *pkt, int add_offset); #endif /* AVFORMAT_INTERNAL_H */ diff --cc libavformat/mux.c index 77823a4,37c4541..4d47ddc --- a/libavformat/mux.c +++ b/libavformat/mux.c @@@ -684,42 -353,23 +684,44 @@@ FF_ENABLE_DEPRECATION_WARNING * Those additional safety checks should be dropped once the correct checks * are set in the callers. */ - static int write_packet(AVFormatContext *s, AVPacket *pkt) { - int ret; + int ret, did_split; + int64_t pts_backup, dts_backup; + + pts_backup = pkt->pts; + dts_backup = pkt->dts; + + // If the timestamp offsetting below is adjusted, adjust + // ff_interleaved_peek similarly. + if (s->output_ts_offset) { + AVStream *st = s->streams[pkt->stream_index]; + int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); + + if (pkt->dts != AV_NOPTS_VALUE) + pkt->dts += offset; + if (pkt->pts != AV_NOPTS_VALUE) + pkt->pts += offset; + } + if (s->avoid_negative_ts > 0) { - AVRational time_base = s->streams[pkt->stream_index]->time_base; - int64_t offset = 0; + AVStream *st = s->streams[pkt->stream_index]; + int64_t offset = st->mux_ts_offset; + int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts; - if (s->internal->offset == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && - (pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) { - s->internal->offset = -pkt->dts; - s->internal->offset_timebase = time_base; + if (s->internal->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE && + (ts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) { + s->internal->offset = -ts; + s->internal->offset_timebase = st->time_base; + } + + if (s->internal->offset != AV_NOPTS_VALUE && !offset) { + offset = st->mux_ts_offset = + av_rescale_q_rnd(s->internal->offset, + s->internal->offset_timebase, + st->time_base, + AV_ROUND_UP); } - if (s->internal->offset != AV_NOPTS_VALUE) - offset = av_rescale_q(s->internal->offset, s->internal->offset_timebase, time_base); if (pkt->dts != AV_NOPTS_VALUE) pkt->dts += offset; @@@ -1185,14 -622,17 +1188,20 @@@ int ff_interleaved_peek(AVFormatContex AVPacketList *pktl = s->internal->packet_buffer; while (pktl) { if (pktl->pkt.stream_index == stream) { - AVPacket *pkt = &pktl->pkt; - AVStream *st = s->streams[pkt->stream_index]; - *ts_offset = st->mux_ts_offset; - - if (s->output_ts_offset) - *ts_offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); - - return pkt; + *pkt = pktl->pkt; - if (add_offset && s->internal->offset != AV_NOPTS_VALUE) { - int64_t offset = av_rescale_q(s->internal->offset, - s->internal->offset_timebase, - s->streams[stream]->time_base); ++ if (add_offset) { ++ AVStream *st = s->streams[pkt->stream_index]; ++ int64_t offset = st->mux_ts_offset; ++ ++ if (s->output_ts_offset) ++ offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base); ++ + if (pkt->dts != AV_NOPTS_VALUE) + pkt->dts += offset; + if (pkt->pts != AV_NOPTS_VALUE) + pkt->pts += offset; + } + return 0; } pktl = pktl->next; } _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog