1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
21
24 #include "cbs.h"
28
31
33
35
37
42
45
46
50 {
56
69 }
70 }
71 }
72
74 // No sequence header and sequence extension: not an MPEG-2 video
75 // sequence.
76 if (sh && !
ctx->mpeg1_warned) {
78 "header but not a sequence extension: maybe it's "
79 "actually MPEG-1?\n");
80 ctx->mpeg1_warned = 1;
81 }
82 return 0;
83 }
84
85 if (
ctx->display_aspect_ratio.num &&
ctx->display_aspect_ratio.den) {
86 int num, den;
87
89 ctx->display_aspect_ratio.den, 65535);
90
91 if (num == 4 && den == 3)
93 else if (num == 16 && den == 9)
95 else if (num == 221 && den == 100)
97 else
99 }
100
101 if (
ctx->frame_rate.num &&
ctx->frame_rate.den) {
102 int code, ext_n, ext_d;
103
105 &
code, &ext_n, &ext_d, 0);
106
108 se->frame_rate_extension_n = ext_n;
109 se->frame_rate_extension_d = ext_d;
110 }
111
112 if (
ctx->video_format >= 0 ||
113 ctx->colour_primaries >= 0 ||
114 ctx->transfer_characteristics >= 0 ||
115 ctx->matrix_coefficients >= 0) {
116 if (!sde) {
117 int err;
118 ctx->sequence_display_extension.extension_start_code =
120 ctx->sequence_display_extension.extension_start_code_identifier =
122 sde = &
ctx->sequence_display_extension.data.sequence_display;
123
126
127 .colour_description = 0,
128 .colour_primaries = 2,
129 .transfer_characteristics = 2,
130 .matrix_coefficients = 2,
131
132 .display_horizontal_size =
134 .display_vertical_size =
136 };
137
138 err = ff_cbs_insert_unit_content(frag, se_pos + 1,
140 &
ctx->sequence_display_extension,
142 if (err < 0) {
144 "display extension.\n");
145 return err;
146 }
147 }
148
149 if (
ctx->video_format >= 0)
151
152 if (
ctx->colour_primaries >= 0 ||
153 ctx->transfer_characteristics >= 0 ||
154 ctx->matrix_coefficients >= 0) {
156
157 if (
ctx->colour_primaries >= 0)
159
160 if (
ctx->transfer_characteristics >= 0)
162
163 if (
ctx->matrix_coefficients >= 0)
165 }
166 }
167
168 return 0;
169 }
170
173 .fragment_name = "frame",
174 .unit_name = "start code",
176 };
177
179 {
181
182 #define VALIDITY_CHECK(name) do { \
183 if (!ctx->name) { \
184 av_log(bsf, AV_LOG_ERROR, "The value 0 for %s is " \
185 "forbidden.\n", #name); \
186 return AVERROR(EINVAL); \
187 } \
188 } while (0)
192 #undef VALIDITY_CHECK
193
195 }
196
197 #define OFFSET(x) offsetof(MPEG2MetadataContext, x)
198 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
200 { "display_aspect_ratio", "Set display aspect ratio (table 6-3)",
202 { .dbl = 0.0 }, 0, 65535,
FLAGS },
203
204 { "frame_rate", "Set frame rate",
206 { .dbl = 0.0 }, 0, UINT_MAX,
FLAGS },
207
208 { "video_format", "Set video format (table 6-6)",
210 { .i64 = -1 }, -1, 7,
FLAGS },
211 { "colour_primaries", "Set colour primaries (table 6-7)",
213 { .i64 = -1 }, -1, 255,
FLAGS },
214 { "transfer_characteristics", "Set transfer characteristics (table 6-8)",
216 { .i64 = -1 }, -1, 255,
FLAGS },
217 { "matrix_coefficients", "Set matrix coefficients (table 6-9)",
219 { .i64 = -1 }, -1, 255,
FLAGS },
220
222 };
223
229 };
230
233 };
234
236 .
p.
name =
"mpeg2_metadata",
243 };