diff options
author | James Almer <jamrial@gmail.com> | 2016-09-28 01:20:57 +0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2016-10-06 19:49:10 +0300 |
commit | 9b8ac526f6b283024327de27167dfd465f1ab158 (patch) | |
tree | 8f675e84e4b6b47a23b9ab01e7ddf3f723600d52 /libavformat | |
parent | d2af93ac160872124b4066a77415eb06007c7326 (diff) |
avformat/matroskaenc: don't write an empty Colour master element
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/matroskaenc.c | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index def8610c58..c94c8a0ca3 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -734,60 +734,73 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, } static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, AVStream *st) { + AVIOContext *dyn_cp; + uint8_t *colorinfo_ptr; int side_data_size = 0; + int ret, colorinfo_size; const uint8_t *side_data = av_stream_get_side_data( st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &side_data_size); - ebml_master colorinfo = start_ebml_master(pb, MATROSKA_ID_VIDEOCOLOR, 0); + + ret = avio_open_dyn_buf(&dyn_cp); + if (ret < 0) + return ret; if (par->color_trc != AVCOL_TRC_UNSPECIFIED && par->color_trc < AVCOL_TRC_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS, + put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS, par->color_trc); } if (par->color_space != AVCOL_SPC_UNSPECIFIED && par->color_space < AVCOL_SPC_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORMATRIXCOEFF, par->color_space); + put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORMATRIXCOEFF, par->color_space); } if (par->color_primaries != AVCOL_PRI_UNSPECIFIED && par->color_primaries < AVCOL_PRI_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORPRIMARIES, par->color_primaries); + put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORPRIMARIES, par->color_primaries); } if (par->color_range != AVCOL_RANGE_UNSPECIFIED && par->color_range < AVCOL_RANGE_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORRANGE, par->color_range); + put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORRANGE, par->color_range); } if (side_data_size == sizeof(AVMasteringDisplayMetadata)) { ebml_master meta_element = start_ebml_master( - pb, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 0); + dyn_cp, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 0); const AVMasteringDisplayMetadata *metadata = (const AVMasteringDisplayMetadata*)side_data; if (metadata->has_primaries) { - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_RX, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_RX, av_q2d(metadata->display_primaries[0][0])); - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_RY, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_RY, av_q2d(metadata->display_primaries[0][1])); - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_GX, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_GX, av_q2d(metadata->display_primaries[1][0])); - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_GY, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_GY, av_q2d(metadata->display_primaries[1][1])); - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_BX, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_BX, av_q2d(metadata->display_primaries[2][0])); - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_BY, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_BY, av_q2d(metadata->display_primaries[2][1])); - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_WHITEX, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_WHITEX, av_q2d(metadata->white_point[0])); - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_WHITEY, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_WHITEY, av_q2d(metadata->white_point[1])); } if (metadata->has_luminance) { - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX, av_q2d(metadata->max_luminance)); - put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN, + put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN, av_q2d(metadata->min_luminance)); } - end_ebml_master(pb, meta_element); + end_ebml_master(dyn_cp, meta_element); } - end_ebml_master(pb, colorinfo); + + colorinfo_size = avio_close_dyn_buf(dyn_cp, &colorinfo_ptr); + if (colorinfo_size) { + ebml_master colorinfo = start_ebml_master(pb, MATROSKA_ID_VIDEOCOLOR, 0); + avio_write(pb, colorinfo_ptr, colorinfo_size); + end_ebml_master(pb, colorinfo); + } + av_free(colorinfo_ptr); return 0; } @@ -1126,7 +1139,9 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space)); } if (s->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) { - mkv_write_video_color(pb, par, st); + ret = mkv_write_video_color(pb, par, st); + if (ret < 0) + return ret; } end_ebml_master(pb, subinfo); break; |