[FFmpeg-devel] [PATCH] lavf/matroskadec: Demux the PixelCrop* values

wm4 nfxjfg at googlemail.com
Sun Mar 27 15:50:02 CEST 2016


On Sat, 26 Mar 2016 16:56:55 -0600
Nic Wolfe <nic at wolfeden.ca> wrote:

> The Matroska spec defines PixelCropTop, PixelCropBottom, PixelCropLeft,
> and PixelCropRight elements: https://www.matroska.org/technical/specs/index.html
> 
> This commit adds support for demuxing these values so that
> applications using libav*
> are able to use them when playing the stream. They're added to the AVStream's
> metadata if they are set to something non-zero.

That's a bad way to do it and you know it.

> 
> 
> My official patch is base64 encoded and attached but I will also

Don't do this, I doubt most mail clients provide a way to easily view
this.

> include the diff below for (hopefully) convenience.
> 
> Thanks,
> 
> Nic
> 
> 
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index d788232..72537df 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -139,6 +139,10 @@ typedef struct MatroskaTrackVideo {
>      EbmlBin color_space;
>      uint64_t stereo_mode;
>      uint64_t alpha_mode;
> +    uint64_t crop_bottom;
> +    uint64_t crop_top;
> +    uint64_t crop_left;
> +    uint64_t crop_right;
>  } MatroskaTrackVideo;
> 
>  typedef struct MatroskaTrackAudio {
> @@ -364,10 +368,10 @@ static const EbmlSyntax matroska_track_video[] = {
>      { MATROSKA_ID_VIDEOPIXELHEIGHT,    EBML_UINT,  0,
> offsetof(MatroskaTrackVideo, pixel_height) },
>      { MATROSKA_ID_VIDEOCOLORSPACE,     EBML_BIN,   0,
> offsetof(MatroskaTrackVideo, color_space) },
>      { MATROSKA_ID_VIDEOALPHAMODE,      EBML_UINT,  0,
> offsetof(MatroskaTrackVideo, alpha_mode) },
> -    { MATROSKA_ID_VIDEOPIXELCROPB,     EBML_NONE },
> -    { MATROSKA_ID_VIDEOPIXELCROPT,     EBML_NONE },
> -    { MATROSKA_ID_VIDEOPIXELCROPL,     EBML_NONE },
> -    { MATROSKA_ID_VIDEOPIXELCROPR,     EBML_NONE },
> +    { MATROSKA_ID_VIDEOPIXELCROPB,     EBML_UINT,  0,
> offsetof(MatroskaTrackVideo, crop_bottom) },
> +    { MATROSKA_ID_VIDEOPIXELCROPT,     EBML_UINT,  0,
> offsetof(MatroskaTrackVideo, crop_top) },
> +    { MATROSKA_ID_VIDEOPIXELCROPL,     EBML_UINT,  0,
> offsetof(MatroskaTrackVideo, crop_left) },
> +    { MATROSKA_ID_VIDEOPIXELCROPR,     EBML_UINT,  0,
> offsetof(MatroskaTrackVideo, crop_right) },
>      { MATROSKA_ID_VIDEODISPLAYUNIT,    EBML_NONE },
>      { MATROSKA_ID_VIDEOFLAGINTERLACED, EBML_NONE },
>      { MATROSKA_ID_VIDEOSTEREOMODE,     EBML_UINT,  0,
> offsetof(MatroskaTrackVideo, stereo_mode), { .u =
> MATROSKA_VIDEO_STEREOMODE_TYPE_NB } },
> @@ -2152,6 +2156,16 @@ static int matroska_parse_tracks(AVFormatContext *s)
>              if (track->video.stereo_mode && track->video.stereo_mode
> < MATROSKA_VIDEO_STEREOMODE_TYPE_NB)
>                  av_dict_set(&st->metadata, "stereo_mode",
> ff_matroska_video_stereo_mode[track->video.stereo_mode], 0);
> 
> +            /* export the matroska crop settings as metadata */
> +            if (track->video.crop_bottom != 0)
> +                av_dict_set_int(&st->metadata, "crop_bottom",
> track->video.crop_bottom, 0);
> +            if (track->video.crop_top != 0)
> +                av_dict_set_int(&st->metadata, "crop_top",
> track->video.crop_top, 0);
> +            if (track->video.crop_left != 0)
> +                av_dict_set_int(&st->metadata, "crop_left",
> track->video.crop_left, 0);
> +            if (track->video.crop_right != 0)
> +                av_dict_set_int(&st->metadata, "crop_right",
> track->video.crop_right, 0);
> +
>              /* export alpha mode flag as metadata tag  */
>              if (track->video.alpha_mode)
>                  av_dict_set(&st->metadata, "alpha_mode", "1", 0);



More information about the ffmpeg-devel mailing list