On Wed,  3 Apr 2013 14:11:10 +0200, Luca Barbato <[email protected]> wrote:
> Most formats do not support negative timestamps, shift them to avoid
> unexpected behaviour and a number of bad crashes.
> ---
> 
> Added some more documentation and copied over the timebase.
> 
>  libavformat/avformat.h    | 13 ++++++++++++
>  libavformat/ffmenc.c      |  1 +
>  libavformat/framecrcenc.c |  3 ++-
>  libavformat/matroskaenc.c |  4 ++--
>  libavformat/md5enc.c      |  3 ++-
>  libavformat/mux.c         | 25 +++++++++++++++++++---
>  libavformat/oggenc.c      |  1 +
>  tests/ref/lavf/asf        |  4 ++--
>  tests/ref/lavf/mpg        |  2 +-
>  tests/ref/lavf/ts         |  2 +-
>  tests/ref/seek/lavf-asf   | 54 
> +++++++++++++++++++++++------------------------
>  tests/ref/seek/lavf-mpg   | 54 
> +++++++++++++++++++++++------------------------
>  tests/ref/seek/lavf-ts    | 54 
> +++++++++++++++++++++++------------------------
>  13 files changed, 128 insertions(+), 92 deletions(-)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 067a787..f66e610 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -360,6 +360,7 @@ typedef struct AVProbeData {
>  #define AVFMT_TS_NONSTRICT 0x20000 /**< Format does not require strictly
>                                          increasing timestamps, but they must
>                                          still be monotonic */
> +#define AVFMT_TS_NEGATIVE  0x40000 /**< Format allows muxing negative 
> timestamps. If not set the timestamp will be shifted in av_write_frame and 
> av_interleaved_write_frame so they start from 0. */
>  
>  /**
>   * @addtogroup lavf_encoding
> @@ -1021,6 +1022,18 @@ typedef struct AVFormatContext {
>       */
>  #define RAW_PACKET_BUFFER_SIZE 2500000
>      int raw_packet_buffer_remaining_size;
> +
> +    /**
> +     * Offset to remap timestamps to be non-negative.
> +     * Expressed in timebase units.
> +     */
> +    int64_t offset;
> +
> +    /**
> +     * Timebase for the timestamp offset.
> +     */
> +    AVRational offset_timebase;
> +
>  } AVFormatContext;
>  
>  typedef struct AVPacketList {
> diff --git a/libavformat/ffmenc.c b/libavformat/ffmenc.c
> index 386487f..91658e1 100644
> --- a/libavformat/ffmenc.c
> +++ b/libavformat/ffmenc.c
> @@ -245,4 +245,5 @@ AVOutputFormat ff_ffm_muxer = {
>      .write_header      = ffm_write_header,
>      .write_packet      = ffm_write_packet,
>      .write_trailer     = ffm_write_trailer,
> +    .flags             = AVFMT_TS_NEGATIVE,
>  };
> diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c
> index de6fa2b..fed0cca 100644
> --- a/libavformat/framecrcenc.c
> +++ b/libavformat/framecrcenc.c
> @@ -43,5 +43,6 @@ AVOutputFormat ff_framecrc_muxer = {
>      .video_codec       = AV_CODEC_ID_RAWVIDEO,
>      .write_header      = ff_framehash_write_header,
>      .write_packet      = framecrc_write_packet,
> -    .flags             = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
> +    .flags             = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT |
> +                         AVFMT_TS_NEGATIVE,
>  };
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index b1e4a1e..567a0ad 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -1304,7 +1304,7 @@ AVOutputFormat ff_matroska_muxer = {
>      .write_packet      = mkv_write_packet,
>      .write_trailer     = mkv_write_trailer,
>      .flags             = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS |
> -                         AVFMT_TS_NONSTRICT,
> +                         AVFMT_TS_NONSTRICT | AVFMT_TS_NEGATIVE,
>      .codec_tag         = (const AVCodecTag* const []){
>           ff_codec_bmp_tags, ff_codec_wav_tags, 0
>      },
> @@ -1326,7 +1326,7 @@ AVOutputFormat ff_webm_muxer = {
>      .write_packet      = mkv_write_packet,
>      .write_trailer     = mkv_write_trailer,
>      .flags             = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS |
> -                         AVFMT_TS_NONSTRICT,
> +                         AVFMT_TS_NONSTRICT | AVFMT_TS_NEGATIVE,
>  };
>  #endif
>  

Also why is matroska here? I do not think it supports negative timestamps.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to