[FFmpeg-devel] [PATCH] asf muxer: gracefully handle negative timestamps

Michael Niedermayer michaelni
Fri Mar 12 17:20:21 CET 2010


On Fri, Mar 12, 2010 at 07:24:39AM +0100, Vladimir Pantelic wrote:
> Michael Niedermayer wrote:
>> On Thu, Mar 11, 2010 at 06:59:34PM +0100, Vladimir Pantelic wrote:
>>>  Michael Niedermayer wrote:
>>>
>>>>  muxers are not supposed to store random values
>>>>
>>>>  id suggest
>>>>  1. add a flag to muxers specifying the capability of negative dts 
>>>> support
>>>>  2. check for that flag in common code (utils.c) and offset all 
>>>> timestamps
>>>>      so as to avoid neagative dts if not set
>>>
>>>  something like the attached?
>>
>> no that will make timestamps non monotone
>
> right, offset has to be applied always of course, v2 attached
>

>  avformat.h |    2 ++
>  utils.c    |   25 +++++++++++++++++++++++++
>  2 files changed, 27 insertions(+)
> 39a4d0087a4c535ece67b7a7b88d8754d4ee3534  lavf_avfmt_positive_ts_v2.patch
> Index: libavformat/avformat.h
> ===================================================================
> --- libavformat/avformat.h	(revision 22465)
> +++ libavformat/avformat.h	(working copy)
> @@ -245,6 +245,7 @@
>  #define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. */
>  #define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
>  #define AVFMT_NODIMENSIONS  0x0800 /**< Format does not need width/height */
> +#define AVFMT_POSITIVE_TS   0x1000 /**< Format allows positive timestamps only */
>  
>  typedef struct AVOutputFormat {
>      const char *name;
> @@ -636,6 +637,7 @@
>      unsigned int packet_size;
>      int preload;
>      int max_delay;
> +    int64_t ts_offset;
>  
>  #define AVFMT_NOOUTPUTLOOP -1
>  #define AVFMT_INFINITEOUTPUTLOOP 0
> Index: libavformat/utils.c
> ===================================================================
> --- libavformat/utils.c	(revision 22465)
> +++ libavformat/utils.c	(working copy)
> @@ -2706,6 +2706,31 @@
>      default:
>          break;
>      }
> +
> +    if(s->oformat->flags & AVFMT_POSITIVE_TS) {
> +        int pts_negative = (pkt->pts != AV_NOPTS_VALUE && pkt->pts < 0);
> +        int dts_negative = (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0);
> +        if(pts_negative || dts_negative) {
> +            // negative timestamps are not allowed by this oformat, offset them all to be positive
> +            if(!s->ts_offset) {
> +                if(pts_negative && dts_negative) {
> +                    s->ts_offset = -1 * (pkt->pts < pkt->dts ? pkt->pts : pkt->dts );
> +                } else if (pts_negative) {
> +                    s->ts_offset = -1 * pkt->pts;
> +                } else {
> +                    s->ts_offset = -1 * pkt->dts;
> +                }
> +                av_log(s, AV_LOG_ERROR, "negative timestamps not supported by this oformat, applying offset: %"PRId64"\n", s->ts_offset);
> +            }
> +        }
> +        if(s->ts_offset) {
> +            if(pkt->pts != AV_NOPTS_VALUE)
> +                pkt->pts += s->ts_offset;
> +            if(pkt->dts != AV_NOPTS_VALUE)
> +                pkt->dts += s->ts_offset;
> +        }
> +    }

AV desync

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100312/7213ee97/attachment.pgp>



More information about the ffmpeg-devel mailing list