Commit f769671f authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '090c67d5'

* commit '090c67d5':
  matroskaenc: write correct Display{Width, Height} in stereo encoding

Conflicts:
	libavformat/matroskaenc.c

See: 6103faaaMerged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents a38a1d51 090c67d5
...@@ -696,13 +696,15 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, ...@@ -696,13 +696,15 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb,
static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb,
AVStream *st, int mode) AVStream *st, int mode, int *h_width, int *h_height)
{ {
int i; int i;
int ret = 0; int ret = 0;
AVDictionaryEntry *tag; AVDictionaryEntry *tag;
MatroskaVideoStereoModeType format = MATROSKA_VIDEO_STEREOMODE_TYPE_NB; MatroskaVideoStereoModeType format = MATROSKA_VIDEO_STEREOMODE_TYPE_NB;
*h_width = 1;
*h_height = 1;
// convert metadata into proper side data and add it to the stream // convert metadata into proper side data and add it to the stream
if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) || if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) ||
(tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) { (tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) {
...@@ -722,6 +724,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, ...@@ -722,6 +724,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb,
} }
} }
// iterate to find the stereo3d side data
for (i = 0; i < st->nb_side_data; i++) { for (i = 0; i < st->nb_side_data; i++) {
AVPacketSideData sd = st->side_data[i]; AVPacketSideData sd = st->side_data[i];
if (sd.type == AV_PKT_DATA_STEREO3D) { if (sd.type == AV_PKT_DATA_STEREO3D) {
...@@ -735,11 +738,13 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, ...@@ -735,11 +738,13 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb,
format = (stereo->flags & AV_STEREO3D_FLAG_INVERT) format = (stereo->flags & AV_STEREO3D_FLAG_INVERT)
? MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT ? MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT
: MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT; : MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT;
*h_width = 2;
break; break;
case AV_STEREO3D_TOPBOTTOM: case AV_STEREO3D_TOPBOTTOM:
format = MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM; format = MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM;
if (stereo->flags & AV_STEREO3D_FLAG_INVERT) if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
format--; format--;
*h_height = 2;
break; break;
case AV_STEREO3D_CHECKERBOARD: case AV_STEREO3D_CHECKERBOARD:
format = MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR; format = MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR;
...@@ -750,11 +755,13 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, ...@@ -750,11 +755,13 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb,
format = MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR; format = MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR;
if (stereo->flags & AV_STEREO3D_FLAG_INVERT) if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
format--; format--;
*h_height = 2;
break; break;
case AV_STEREO3D_COLUMNS: case AV_STEREO3D_COLUMNS:
format = MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR; format = MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR;
if (stereo->flags & AV_STEREO3D_FLAG_INVERT) if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
format--; format--;
*h_width = 2;
break; break;
case AV_STEREO3D_FRAMESEQUENCE: case AV_STEREO3D_FRAMESEQUENCE:
format = MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR; format = MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR;
...@@ -762,8 +769,6 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, ...@@ -762,8 +769,6 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb,
format++; format++;
break; break;
} }
ret = stereo->type;
break; break;
} }
} }
...@@ -771,6 +776,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, ...@@ -771,6 +776,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb,
if (format == MATROSKA_VIDEO_STEREOMODE_TYPE_NB) if (format == MATROSKA_VIDEO_STEREOMODE_TYPE_NB)
return ret; return ret;
// if webm, do not write unsupported modes
if ((mode == MODE_WEBM && if ((mode == MODE_WEBM &&
format > MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM && format > MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM &&
format != MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT) format != MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT)
...@@ -781,6 +787,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, ...@@ -781,6 +787,7 @@ static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb,
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
// write StereoMode if format is valid
put_ebml_uint(pb, MATROSKA_ID_VIDEOSTEREOMODE, format); put_ebml_uint(pb, MATROSKA_ID_VIDEOSTEREOMODE, format);
return ret; return ret;
...@@ -927,27 +934,20 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, ...@@ -927,27 +934,20 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
// check both side data and metadata for stereo information, // check both side data and metadata for stereo information,
// write the result to the bitstream if any is found // write the result to the bitstream if any is found
ret = mkv_write_stereo_mode(s, pb, st, mkv->mode); ret = mkv_write_stereo_mode(s, pb, st, mkv->mode,
&display_width_div,
&display_height_div);
if (ret < 0) if (ret < 0)
return ret; return ret;
switch (ret) {
case AV_STEREO3D_SIDEBYSIDE:
case AV_STEREO3D_COLUMNS:
display_width_div = 2;
break;
case AV_STEREO3D_TOPBOTTOM:
case AV_STEREO3D_LINES:
display_height_div = 2;
break;
}
if (((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) || if (((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) ||
((tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) || ((tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) ||
(codec->pix_fmt == AV_PIX_FMT_YUVA420P)) { (codec->pix_fmt == AV_PIX_FMT_YUVA420P)) {
put_ebml_uint(pb, MATROSKA_ID_VIDEOALPHAMODE, 1); put_ebml_uint(pb, MATROSKA_ID_VIDEOALPHAMODE, 1);
} }
// write DisplayWidth and DisplayHeight, they contain the size of
// a single source view and/or the display aspect ratio
if (st->sample_aspect_ratio.num) { if (st->sample_aspect_ratio.num) {
int64_t d_width = av_rescale(codec->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); int64_t d_width = av_rescale(codec->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
if (d_width > INT_MAX) { if (d_width > INT_MAX) {
...@@ -965,6 +965,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, ...@@ -965,6 +965,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
uint32_t color_space = av_le2ne32(codec->codec_tag); uint32_t color_space = av_le2ne32(codec->codec_tag);
put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space)); put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space));
} }
end_ebml_master(pb, subinfo); end_ebml_master(pb, subinfo);
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment