[FFmpeg-cvslog] avformat/matroskadec: set aspect ratio only when DisplayWidth and DisplayHeight are in pixels

James Almer git at videolan.org
Sun Oct 16 02:53:52 EEST 2016


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sat Oct 15 18:01:50 2016 -0300| [bad8bbc26aa3151c734daa9568b14c2c7d9aa6d2] | committer: James Almer

avformat/matroskadec: set aspect ratio only when DisplayWidth and DisplayHeight are in pixels

A missing DisplayUnit element or one with the default value of 0 means
DisplayWidth and DisplayHeight should be interpreted as pixels.

The current code setting st->sample_aspect_ratio is wrong when DisplayUnit
is anything else.

Reviewed-by: Carl Eugen Hoyos <ceffmpeg at gmail.com>
Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bad8bbc26aa3151c734daa9568b14c2c7d9aa6d2
---

 libavformat/matroska.h    |  8 ++++++++
 libavformat/matroskadec.c | 15 +++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/libavformat/matroska.h b/libavformat/matroska.h
index 15e401c..8ad89da 100644
--- a/libavformat/matroska.h
+++ b/libavformat/matroska.h
@@ -309,6 +309,14 @@ typedef enum {
   MATROSKA_VIDEO_STEREOMODE_TYPE_NB,
 } MatroskaVideoStereoModeType;
 
+typedef enum {
+  MATROSKA_VIDEO_DISPLAYUNIT_PIXELS      = 0,
+  MATROSKA_VIDEO_DISPLAYUNIT_CENTIMETERS = 1,
+  MATROSKA_VIDEO_DISPLAYUNIT_INCHES      = 2,
+  MATROSKA_VIDEO_DISPLAYUNIT_DAR         = 3,
+  MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN     = 4,
+} MatroskaVideoDisplayUnit;
+
 /*
  * Matroska Codec IDs, strings
  */
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index acf1ccb..0d17a7e 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -168,6 +168,7 @@ typedef struct MatroskaTrackVideo {
     uint64_t pixel_width;
     uint64_t pixel_height;
     EbmlBin color_space;
+    uint64_t display_unit;
     uint64_t interlaced;
     uint64_t field_order;
     uint64_t stereo_mode;
@@ -436,7 +437,7 @@ static const EbmlSyntax matroska_track_video[] = {
     { MATROSKA_ID_VIDEOPIXELCROPT,     EBML_NONE },
     { MATROSKA_ID_VIDEOPIXELCROPL,     EBML_NONE },
     { MATROSKA_ID_VIDEOPIXELCROPR,     EBML_NONE },
-    { MATROSKA_ID_VIDEODISPLAYUNIT,    EBML_NONE },
+    { MATROSKA_ID_VIDEODISPLAYUNIT,    EBML_UINT,  0, offsetof(MatroskaTrackVideo, display_unit), { .u= MATROSKA_VIDEO_DISPLAYUNIT_PIXELS } },
     { MATROSKA_ID_VIDEOFLAGINTERLACED, EBML_UINT,  0, offsetof(MatroskaTrackVideo, interlaced),  { .u = MATROSKA_VIDEO_INTERLACE_FLAG_UNDETERMINED } },
     { MATROSKA_ID_VIDEOFIELDORDER,     EBML_UINT,  0, offsetof(MatroskaTrackVideo, field_order), { .u = MATROSKA_VIDEO_FIELDORDER_UNDETERMINED } },
     { MATROSKA_ID_VIDEOSTEREOMODE,     EBML_UINT,  0, offsetof(MatroskaTrackVideo, stereo_mode), { .u = MATROSKA_VIDEO_STEREOMODE_TYPE_NB } },
@@ -2296,11 +2297,13 @@ static int matroska_parse_tracks(AVFormatContext *s)
             if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB)
                 mkv_stereo_mode_display_mul(track->video.stereo_mode, &display_width_mul, &display_height_mul);
 
-            av_reduce(&st->sample_aspect_ratio.num,
-                      &st->sample_aspect_ratio.den,
-                      st->codecpar->height * track->video.display_width  * display_width_mul,
-                      st->codecpar->width  * track->video.display_height * display_height_mul,
-                      255);
+            if (track->video.display_unit == MATROSKA_VIDEO_DISPLAYUNIT_PIXELS) {
+                av_reduce(&st->sample_aspect_ratio.num,
+                          &st->sample_aspect_ratio.den,
+                          st->codecpar->height * track->video.display_width  * display_width_mul,
+                          st->codecpar->width  * track->video.display_height * display_height_mul,
+                          255);
+            }
             if (st->codecpar->codec_id != AV_CODEC_ID_HEVC)
                 st->need_parsing = AVSTREAM_PARSE_HEADERS;
 



More information about the ffmpeg-cvslog mailing list