From 639407f580918393d438cf715e2ffbd5fe7e0288 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sun, 19 Mar 2017 18:57:17 +0100 Subject: [PATCH] HEVC parser: detect and ignore invalid default display window VUI parameters Certain files seem to lack the "default display window" data (well, the flag that signals its presence/absence). Therefore a standards-compliant parser would try to read that flag, but the data read would belong to another flag (the "vui_timing_info_present_flag"). ffmpeg has a heuristic in place for detecting such invalid default display window parameters. This commit implements the same heuristic in mkvmerge. Fixes #1907. --- NEWS.md | 3 +++ src/common/hevc.cpp | 6 +++++- tests/results.txt | 1 + ...est-586h265_invalid_default_display_window_in_sps_vui.rb | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100755 tests/test-586h265_invalid_default_display_window_in_sps_vui.rb diff --git a/NEWS.md b/NEWS.md index 25e1e0c61..ffea27b7d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,9 @@ first key frame as they cannot be decoded properly anyway. See #1908. * mkvmerge: HEVC/h.265 parser: mkvmerge will now drop all frames before the first key frame as they cannot be decoded properly anyway. See #1908. +* mkvmerge: HEVC/h.265 parser: added a workaround for invalid values for the + "default display window" in the VUI parameters of sequence parameter + sets. Fixes #1907. ## Bug fixes diff --git a/src/common/hevc.cpp b/src/common/hevc.cpp index c821b2b0a..bafe76cab 100644 --- a/src/common/hevc.cpp +++ b/src/common/hevc.cpp @@ -857,7 +857,11 @@ vui_parameters_copy(bit_reader_c &r, w.copy_unsigned_golomb(r); // chroma_sample_loc_type_bottom_field } w.copy_bits(3, r); // neutral_chroma_indication_flag, field_seq_flag, frame_field_info_present_flag - if (w.copy_bits(1, r) == 1) { // default_display_window_flag + + if ( (r.get_remaining_bits() >= 68) + && (r.peek_bits(21) == 0x100000)) + w.put_bit(0); // invalid default display window, signal no default_display_window_flag + else if (w.copy_bits(1, r) == 1) { // default_display_window_flag w.copy_unsigned_golomb(r); // def_disp_win_left_offset w.copy_unsigned_golomb(r); // def_disp_win_right_offset w.copy_unsigned_golomb(r); // def_disp_win_top_offset diff --git a/tests/results.txt b/tests/results.txt index 25f4ece0a..661473224 100644 --- a/tests/results.txt +++ b/tests/results.txt @@ -431,3 +431,4 @@ T_582reading_mp4_with_and_without_track_order:3d668751b7ae3247e866a6cad96db6f2-3 T_583dvbsub_four_bytes_codecprivate:4e16c6cb196dc6d60b799de8283498ba-4b457add4290c9cb39b792e2313e4043:passed:20170217-183748:0.078521662 T_584ac_3_misdetected_as_mp3:true-5fa0a9abd94a7f555f519b013a55b980:passed:20170218-123152:0.369584022 T_585h264_wrong_mapping_of_timestamps_to_frames:87acc96e91f17b007ab38b23da8cca1d:passed:20170318-172210:0.580192044 +T_586h265_invalid_default_display_window_in_sps_vui:f49d79d17235b95a154b5d951e48344f:passed:20170319-185708:0.186032079 diff --git a/tests/test-586h265_invalid_default_display_window_in_sps_vui.rb b/tests/test-586h265_invalid_default_display_window_in_sps_vui.rb new file mode 100755 index 000000000..ca3847427 --- /dev/null +++ b/tests/test-586h265_invalid_default_display_window_in_sps_vui.rb @@ -0,0 +1,5 @@ +#!/usr/bin/ruby -w + +# T_586h265_invalid_default_display_window_in_sps_vui +describe "mkvmerge / h.265 with an invalid default display window in the VUI parameters of the sequence parameter sets" +test_merge "data/h265/invalid_default_display_window_in_sps_vui.h265"