]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '785c25443b56adb6dbbb78d68cccbd9bd4a42e05'
authorHendrik Leppkes <h.leppkes@gmail.com>
Sun, 13 Nov 2016 21:55:34 +0000 (22:55 +0100)
committerHendrik Leppkes <h.leppkes@gmail.com>
Sun, 13 Nov 2016 21:57:02 +0000 (22:57 +0100)
* commit '785c25443b56adb6dbbb78d68cccbd9bd4a42e05':
  movenc: Apply offsets on timestamps when peeking into interleaving queues

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
libavformat/internal.h
libavformat/movenc.c
libavformat/mux.c

index da64c641a7105e3879df85a2b6d120fc5560ada0,de55af5af4d878514e7e323baf244e30b5e54445..9d614fb12ca8a281e952d607dd11fc0954cba184
@@@ -603,68 -441,15 +603,67 @@@ 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 */
Simple merge
index 77823a4e75d83a2d5d96114edca9aa28654b106a,37c4541ad9dfb30bda92a2377a3eb1074dac9ec5..4d47ddcbdeebfb89bc03e4a6b8a9b2c779fea535
@@@ -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;
      }