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

Nic Wolfe nic at wolfeden.ca
Sat Mar 26 23:56:55 CET 2016


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.


My official patch is base64 encoded and attached but I will also
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lavf-matroskadec-Demux-the-PixelCrop-values.patch.base64
Type: application/octet-stream
Size: 4693 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160326/c55e246c/attachment.obj>


More information about the ffmpeg-devel mailing list