[FFmpeg-devel] [PATCH] h264/aac in flv

Michael Niedermayer michaelni
Tue May 6 15:12:42 CEST 2008


On Tue, May 06, 2008 at 11:13:01AM +0200, Baptiste Coudurier wrote:
> Michael Niedermayer wrote:
> > On Mon, May 05, 2008 at 04:01:35PM +0200, Baptiste Coudurier wrote:
> >> Baptiste Coudurier wrote:
> >>> Hi guys,
> >>>
> >>> $subject, 2 patches, I'll commit pts/dts renaming seperately.
> >>>
> >>> Specs: http://www.adobe.com/devnet/flv/
> >>>
> >> Muxer dts delay update, this is simpler I think.
> > [...]
> >> @@ -305,18 +349,35 @@
> >>          put_byte(pb, FLV_TAG_TYPE_AUDIO);
> >>      }
> >>  
> >> +    if (enc->codec_id == CODEC_ID_H264) {
> >> +        if (ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size) < 0)
> >> +            return -1;
> >> +        assert(pkt->size);
> >> +        size = pkt->size;
> >> +        if (!flv->delay && (int)pkt->dts < 0)
> >> +            flv->delay = (1LL<<32) - pkt->dts;
> >> +        ts = (int)pkt->dts + flv->delay; // XXX first dts is negative
> >> +    } else
> >> +        ts = pkt->pts;
> > 
> > If you add a constant to all timestamps of one stream but not to the
> > timestamps of the other streams then there would be a slight AV sync error.
> 
> Good point.
> 
> >>      put_be24(pb,size + flags_size);
> >> -    put_be24(pb,pkt->pts);
> >> -    put_byte(pb,pkt->pts >> 24);
> >> +    put_be24(pb,ts);
> >> +    put_byte(pb,ts >> 24);
> >>      put_be24(pb,flv->reserved);
> >>      put_byte(pb,flags);
> >>      if (enc->codec_id == CODEC_ID_VP6)
> >>          put_byte(pb,0);
> >>      if (enc->codec_id == CODEC_ID_VP6F)
> >>          put_byte(pb, enc->extradata_size ? enc->extradata[0] : 0);
> >> +    else if (enc->codec_id == CODEC_ID_AAC)
> >> +        put_byte(pb,1); // AAC raw
> >> +    else if (enc->codec_id == CODEC_ID_H264) {
> >> +        put_byte(pb,1); // AVC NALU
> > 
> >> +        put_be24(pb,pkt->pts - (int)pkt->dts);
> > 
> > why the cast ?
> 
> Because truncate_ts will make them positive :/
> Attached patch may solve the issue.

int can be 64bit, int32_t would be more correct.


[...]
> Index: libavformat/utils.c
> ===================================================================
> --- libavformat/utils.c	(revision 13010)
> +++ libavformat/utils.c	(working copy)
> @@ -2401,8 +2401,10 @@
>  static void truncate_ts(AVStream *st, AVPacket *pkt){
>      int64_t pts_mask = (2LL << (st->pts_wrap_bits-1)) - 1;
>  
> -//    if(pkt->dts < 0)
> -//        pkt->dts= 0;  //this happens for low_delay=0 and B-frames, FIXME, needs further investigation about what we should do here
> +    /* negative dts happens for low_delay=0 and B-frames
> +     * must not truncate because wrap bits < 64 will not get them */
> +    if(pkt->dts < 0)
> +        return;

Iam against this change.


[...]
> @@ -49,11 +52,15 @@
>      offset_t duration_offset;
>      offset_t filesize_offset;
>      int64_t duration;
> +    int delay; ///< first dts delay for AVC
>  } FLVContext;
>  
>  static int get_audio_flags(AVCodecContext *enc){
>      int flags = (enc->bits_per_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;
>  

> +    if (enc->codec_id == CODEC_ID_AAC) // specs force these parameters
> +        return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | FLV_SAMPLESSIZE_16BIT | FLV_STEREO;

Is this also correct for AAC streams for which these arent true? Or are
such streams just not supported?


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

The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- 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/20080506/8c813a77/attachment.pgp>



More information about the ffmpeg-devel mailing list