avformat/matroskadec: Fix sample_aspect_ratio for stereo matroska content

matroskaenc.c applies divisors to the display width/height when generating
stereo content. This patch adds the corresponding multipliers to matroskadec.c
so that the original sample aspect ratio can be recovered.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
This commit is contained in:
Aaron Colwell 2015-11-23 12:06:14 -08:00 committed by wm4
parent 5e6ce28dab
commit ec83efd4d3
1 changed files with 32 additions and 2 deletions

View File

@ -1648,6 +1648,30 @@ static int matroska_parse_flac(AVFormatContext *s,
return 0; return 0;
} }
static void mkv_stereo_mode_display_mul(int stereo_mode, int *h_width, int *h_height)
{
switch (stereo_mode) {
case MATROSKA_VIDEO_STEREOMODE_TYPE_MONO:
case MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_RL:
case MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR:
case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL:
case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR:
break;
case MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT:
case MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT:
case MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_RL:
case MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR:
*h_width = 2;
break;
case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTTOM_TOP:
case MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM:
case MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_RL:
case MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR:
*h_height = 2;
break;
}
}
static int matroska_parse_tracks(AVFormatContext *s) static int matroska_parse_tracks(AVFormatContext *s)
{ {
MatroskaDemuxContext *matroska = s->priv_data; MatroskaDemuxContext *matroska = s->priv_data;
@ -2007,6 +2031,8 @@ static int matroska_parse_tracks(AVFormatContext *s)
if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
MatroskaTrackPlane *planes = track->operation.combine_planes.elem; MatroskaTrackPlane *planes = track->operation.combine_planes.elem;
int display_width_mul = 1;
int display_height_mul = 1;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_tag = fourcc; st->codec->codec_tag = fourcc;
@ -2014,10 +2040,14 @@ static int matroska_parse_tracks(AVFormatContext *s)
st->codec->bits_per_coded_sample = bit_depth; st->codec->bits_per_coded_sample = bit_depth;
st->codec->width = track->video.pixel_width; st->codec->width = track->video.pixel_width;
st->codec->height = track->video.pixel_height; st->codec->height = track->video.pixel_height;
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, av_reduce(&st->sample_aspect_ratio.num,
&st->sample_aspect_ratio.den, &st->sample_aspect_ratio.den,
st->codec->height * track->video.display_width, st->codec->height * track->video.display_width * display_width_mul,
st->codec->width * track->video.display_height, st->codec->width * track->video.display_height * display_height_mul,
255); 255);
if (st->codec->codec_id != AV_CODEC_ID_HEVC) if (st->codec->codec_id != AV_CODEC_ID_HEVC)
st->need_parsing = AVSTREAM_PARSE_HEADERS; st->need_parsing = AVSTREAM_PARSE_HEADERS;