-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
0077-add-remove-dovi-hdr10plus-bsf.patch
185 lines (165 loc) · 6.68 KB
/
0077-add-remove-dovi-hdr10plus-bsf.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
Index: FFmpeg/libavcodec/bsf/h265_metadata.c
===================================================================
--- FFmpeg.orig/libavcodec/bsf/h265_metadata.c
+++ FFmpeg/libavcodec/bsf/h265_metadata.c
@@ -27,6 +27,7 @@
#include "h2645data.h"
#include "hevc.h"
#include "h265_profile_level.h"
+#include "itut35.h"
enum {
LEVEL_UNSET = -2,
@@ -62,6 +63,8 @@ typedef struct H265MetadataContext {
int level;
int level_guess;
int level_warned;
+ int remove_dovi;
+ int remove_hdr10plus;
} H265MetadataContext;
@@ -385,6 +388,37 @@ static int h265_metadata_update_fragment
if (err < 0)
return err;
}
+ if (ctx->remove_dovi) {
+ if (au->units[i].type == HEVC_NAL_UNSPEC62) { // Dolby Vision RPU
+ ff_cbs_delete_unit(au, i);
+ av_log(bsf, AV_LOG_DEBUG, "Removing Dolby Vision RPU\n");
+ }
+ if (au->units[i].type == HEVC_NAL_UNSPEC63) { // Dolby Vision EL
+ ff_cbs_delete_unit(au, i);
+ av_log(bsf, AV_LOG_DEBUG, "Removing Dolby Vision EL\n");
+ }
+ }
+ if (ctx->remove_hdr10plus) {
+ // This implementation is not strictly correct as it does not decode the entire NAL.
+ // There could be multiple SEIs packed within a single NAL, and some of them may not be HDR10+ metadata.
+ // The current implementation simply removes the entire NAL without further inspection.
+ if (au->units[i].type == HEVC_NAL_SEI_PREFIX && au->units[i].data_size > 8 * sizeof(uint8_t)) {
+ uint8_t *nal_sei = au->units[i].data;
+ // This Matches ITU-T T.35 SMPTE ST 2094-40
+ if (nal_sei[0] == 0x4E && nal_sei[1] == 0x01 && nal_sei[2] == 0x04) {
+ if (nal_sei[4] == ITU_T_T35_COUNTRY_CODE_US && nal_sei[6] == ITU_T_T35_PROVIDER_CODE_SMTPE) {
+ // identifier for HDR10+
+ const uint8_t smpte2094_40_provider_oriented_code = 0x01;
+ const uint8_t smpte2094_40_application_identifier = 0x04;
+ if (nal_sei[8] == smpte2094_40_provider_oriented_code && nal_sei[9] == smpte2094_40_application_identifier) {
+ av_log(bsf, AV_LOG_DEBUG, "Found HDR10+ metadata, removing NAL\n");
+ ff_cbs_delete_unit(au, i);
+ }
+ }
+
+ }
+ }
+ }
}
return 0;
@@ -399,6 +433,11 @@ static const CBSBSFType h265_metadata_ty
static int h265_metadata_init(AVBSFContext *bsf)
{
+ if (((H265MetadataContext *)bsf->priv_data)->remove_dovi) {
+ av_packet_side_data_remove(bsf->par_out->coded_side_data,
+ &bsf->par_out->nb_coded_side_data,
+ AV_PKT_DATA_DOVI_CONF);
+ }
return ff_cbs_bsf_generic_init(bsf, &h265_metadata_type);
}
@@ -478,6 +517,13 @@ static const AVOption h265_metadata_opti
{ LEVEL("8.5", 255) },
#undef LEVEL
+ { "remove_dovi", "Remove Dolby Vision EL and RPU",
+ OFFSET(remove_dovi), AV_OPT_TYPE_BOOL,
+ { .i64 = 0 }, 0, 1, FLAGS },
+ { "remove_hdr10plus", "Remove NALs including HDR10+ metadata",
+ OFFSET(remove_hdr10plus), AV_OPT_TYPE_BOOL,
+ { .i64 = 0 }, 0, 1, FLAGS },
+
{ NULL }
};
Index: FFmpeg/libavcodec/bsf/av1_metadata.c
===================================================================
--- FFmpeg.orig/libavcodec/bsf/av1_metadata.c
+++ FFmpeg/libavcodec/bsf/av1_metadata.c
@@ -17,6 +17,7 @@
*/
#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
#include "bsf.h"
@@ -24,6 +25,7 @@
#include "cbs.h"
#include "cbs_bsf.h"
#include "cbs_av1.h"
+#include "itut35.h"
typedef struct AV1MetadataContext {
CBSBSFContext common;
@@ -42,6 +44,9 @@ typedef struct AV1MetadataContext {
int num_ticks_per_picture;
int delete_padding;
+
+ int remove_dovi;
+ int remove_hdr10plus;
} AV1MetadataContext;
@@ -140,6 +145,42 @@ static int av1_metadata_update_fragment(
}
}
+ if (ctx->remove_dovi ||ctx->remove_hdr10plus) {
+ int provider_code, provider_oriented_code, application_identifier;
+ for (i = frag->nb_units - 1; i >= 0; i--) {
+ if (frag->units[i].type == AV1_OBU_METADATA) {
+ AV1RawOBU *obu = frag->units[i].content;
+ AV1RawMetadataITUTT35 *t35 = &obu->obu.metadata.metadata.itut_t35;
+ if (obu->obu.metadata.metadata_type != AV1_METADATA_TYPE_ITUT_T35 ||
+ t35->itu_t_t35_country_code != ITU_T_T35_COUNTRY_CODE_US ||
+ t35->payload_size < 6) {
+ continue;
+ }
+
+ provider_code = AV_RB16(t35->payload);
+
+ if (ctx->remove_dovi && provider_code == ITU_T_T35_PROVIDER_CODE_DOLBY) {
+ provider_oriented_code = AV_RB32(t35->payload + 2);
+ // Dolby Vision RPU
+ if (provider_oriented_code == 0x800) {
+ av_log(bsf, AV_LOG_DEBUG, "Removing Dolby Vision RPU\n");
+ ff_cbs_delete_unit(frag, i);
+ }
+ }
+
+ if (ctx->remove_hdr10plus && provider_code == ITU_T_T35_PROVIDER_CODE_SMTPE) {
+ provider_oriented_code = AV_RB16(t35->payload + 2);
+ application_identifier = AV_RB8(t35->payload + 4);
+ // HDR10+ Metadata
+ if (provider_oriented_code == 0x01 && application_identifier == 0x04) {
+ av_log(bsf, AV_LOG_DEBUG, "Removing HDR10+ Metadata\n");
+ ff_cbs_delete_unit(frag, i);
+ }
+ }
+ }
+ }
+ }
+
return 0;
}
@@ -158,6 +199,12 @@ static int av1_metadata_init(AVBSFContex
.header.obu_type = AV1_OBU_TEMPORAL_DELIMITER,
};
+ if (ctx->remove_dovi) {
+ av_packet_side_data_remove(bsf->par_out->coded_side_data,
+ &bsf->par_out->nb_coded_side_data,
+ AV_PKT_DATA_DOVI_CONF);
+ }
+
return ff_cbs_bsf_generic_init(bsf, &av1_metadata_type);
}
@@ -206,6 +253,13 @@ static const AVOption av1_metadata_optio
OFFSET(delete_padding), AV_OPT_TYPE_BOOL,
{ .i64 = 0 }, 0, 1, FLAGS},
+ { "remove_dovi", "Remove Dolby Vision RPU",
+ OFFSET(remove_dovi), AV_OPT_TYPE_BOOL,
+ { .i64 = 0 }, 0, 1, FLAGS },
+ { "remove_hdr10plus", "Remove HDR10+ metadata",
+ OFFSET(remove_hdr10plus), AV_OPT_TYPE_BOOL,
+ { .i64 = 0 }, 0, 1, FLAGS },
+
{ NULL }
};