[FFmpeg-devel] [PATCH] Write Pixel Aspect Ratio tag to QuickTime files

Baptiste Coudurier baptiste.coudurier
Thu Jul 8 04:22:08 CEST 2010


On 07/07/2010 07:12 PM, Daniel Kristjansson wrote:
> On Wed, 2010-07-07 at 14:35 -0700, Baptiste Coudurier wrote:
>> On 07/07/2010 02:17 PM, Daniel Kristjansson wrote:
>>> It's required in the spec, p118 of qtfs.pdf, "Pixel aspect ratio. This
>>> extension is mandatory for video formats that use non-square pixels."
>> My specs say MPEG-4 and uncompresed YCbCr. Dated 2007-09-04
>
> Mine is dated 2010-05-03.

Nice a new one :)
Unbelievable that they still refuses to document the 'ctts' atom ...

>>> The QuickTime player (shows 1440x1080 MPEG-2 material at 36:27 rather
>>> than 16:9 without this. I did not test whether NTSC/PAL material is
>>> played correctly.
>>
>> What kind of mpeg-2 using which codec ?
>> Can you share a sample ?
>
> ffmpeg -vframes 300 -i /mythtv/video1/2131_20100706083000.mpg \
>         -r 30000/1001 -acodec pcm_s16le -async 1 -vcodec mpeg2video \
>         -y -s 1440x1080 -aspect 16:9 -threads 3 -vtag xdv2 \
>         -flags ildct+ilme -b 35M -bf 0 -ac 2 -ar 48000 pasp.mov
>
> http://www.cuymedia.net/ffmpeg/pasp.mov
> http://www.cuymedia.net/ffmpeg/no-pasp.mov

-bf 0 ? That's not what xdv2 is representing.

> Admittedly both clips are unwatchable because there is no fiel
> tag to tell the QuickTime player to do deinterlacing, but I haven't
> figured out how to add that properly to movenc.c yet since the
> interlacing info is located on the frames and not in the context.
> For my purposes, I just write the fiel tag when the height != 720.
>
>>> +    if (track->mode == MODE_MOV)
>>> +        mov_write_pasp_tag(pb, track);
>>
>> Move the check for sample_aspect ratio here and don't write the atom if
>> it is not set or square.
>
> In the attached the check is in both locations, so the
> mov_write_pasp_tag() function can still be used to write
> a 1:1 tag, but it doesn't do this by default now.
>
> -- Daniel
>
>
> mov-pasp-v3.patch
>
>
> --- libavformat/movenc.c.orig	2010-07-07 13:17:32.571296315 -0400
> +++ libavformat/movenc.c	2010-07-07 17:42:02.740670652 -0400
> @@ -747,6 +747,25 @@ static int mov_write_subtitle_tag(ByteIO
>       return updateSize(pb, pos);
>   }
>
> +static int mov_write_pasp_tag(ByteIOContext *pb, MOVTrack *track)
> +{
> +    int64_t pos = url_ftell(pb);
> +    unsigned hSpacing = 1, vSpacing = 1;
> +
> +    if (track->enc->sample_aspect_ratio.den&&
> +        track->enc->sample_aspect_ratio.num) {
> +        hSpacing = track->enc->sample_aspect_ratio.num;
> +        vSpacing = track->enc->sample_aspect_ratio.den;
> +    }
> +
> +    put_be32(pb, 0);     /* size */
> +    put_tag(pb, "pasp"); /* tag  */
> +    put_be32(pb, hSpacing);
> +    put_be32(pb, vSpacing);
> +
> +    return updateSize(pb, pos);
> +}
> +
>   static int mov_write_video_tag(ByteIOContext *pb, MOVTrack *track)
>   {
>       int64_t pos = url_ftell(pb);
> @@ -793,6 +812,10 @@ static int mov_write_video_tag(ByteIOCon
>       else
>           put_be16(pb, 0x18); /* Reserved */
>       put_be16(pb, 0xffff); /* Reserved */
> +    if (track->mode == MODE_MOV&&
> +        track->enc->sample_aspect_ratio.den&&
> +        track->enc->sample_aspect_ratio.num)
> +        mov_write_pasp_tag(pb, track);

This will uselesslly write a pasp for 1:1.

-- 
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org



More information about the ffmpeg-devel mailing list