FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffprobe.c
Date: 2026-05-16 01:27:51
Exec Total Coverage
Lines: 1410 2017 69.9%
Functions: 67 94 71.3%
Branches: 772 1312 58.8%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2007-2010 Stefano Sabatini
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * simple media prober based on the FFmpeg libraries
24 */
25
26 #include "config.h"
27 #include "libavutil/ffversion.h"
28
29 #include <string.h>
30 #include <math.h>
31
32 #include "libavformat/avformat.h"
33 #include "libavformat/version.h"
34 #include "libavcodec/avcodec.h"
35 #include "libavcodec/version.h"
36 #include "libavutil/ambient_viewing_environment.h"
37 #include "libavutil/avassert.h"
38 #include "libavutil/avstring.h"
39 #include "libavutil/avutil.h"
40 #include "libavutil/bprint.h"
41 #include "libavutil/channel_layout.h"
42 #include "libavutil/display.h"
43 #include "libavutil/film_grain_params.h"
44 #include "libavutil/hdr_dynamic_metadata.h"
45 #include "libavutil/iamf.h"
46 #include "libavutil/mastering_display_metadata.h"
47 #include "libavutil/hdr_dynamic_vivid_metadata.h"
48 #include "libavutil/dovi_meta.h"
49 #include "libavutil/mem.h"
50 #include "libavutil/opt.h"
51 #include "libavutil/pixdesc.h"
52 #include "libavutil/spherical.h"
53 #include "libavutil/stereo3d.h"
54 #include "libavutil/dict.h"
55 #include "libavutil/intreadwrite.h"
56 #include "libavutil/libm.h"
57 #include "libavutil/parseutils.h"
58 #include "libavutil/timecode.h"
59 #include "libavutil/timestamp.h"
60 #include "libavdevice/avdevice.h"
61 #include "libavdevice/version.h"
62 #include "libswscale/swscale.h"
63 #include "libswscale/version.h"
64 #include "libswresample/swresample.h"
65 #include "libswresample/version.h"
66 #include "libavfilter/version.h"
67 #include "textformat/avtextformat.h"
68 #include "cmdutils.h"
69 #include "opt_common.h"
70
71 #include "libavutil/thread.h"
72
73 // attached as opaque_ref to packets/frames
74 typedef struct FrameData {
75 int64_t pkt_pos;
76 int pkt_size;
77 } FrameData;
78
79 typedef struct InputStream {
80 AVStream *st;
81
82 AVCodecContext *dec_ctx;
83 } InputStream;
84
85 typedef struct InputFile {
86 AVFormatContext *fmt_ctx;
87
88 InputStream *streams;
89 int nb_streams;
90 } InputFile;
91
92 const char program_name[] = "ffprobe";
93 const int program_birth_year = 2007;
94
95 static int do_analyze_frames = 0;
96 static int do_bitexact = 0;
97 static int do_count_frames = 0;
98 static int do_count_packets = 0;
99 static int do_read_frames = 0;
100 static int do_read_packets = 0;
101 static int do_show_chapters = 0;
102 static int do_show_error = 0;
103 static int do_show_format = 0;
104 static int do_show_frames = 0;
105 static int do_show_packets = 0;
106 static int do_show_programs = 0;
107 static int do_show_stream_groups = 0;
108 static int do_show_stream_group_components = 0;
109 static int do_show_streams = 0;
110 static int do_show_stream_disposition = 0;
111 static int do_show_stream_group_disposition = 0;
112 static int do_show_data = 0;
113 static int do_show_program_version = 0;
114 static int do_show_library_versions = 0;
115 static int do_show_pixel_formats = 0;
116 static int do_show_pixel_format_flags = 0;
117 static int do_show_pixel_format_components = 0;
118 static int do_show_log = 0;
119
120 static int do_show_chapter_tags = 0;
121 static int do_show_format_tags = 0;
122 static int do_show_frame_tags = 0;
123 static int do_show_program_tags = 0;
124 static int do_show_stream_group_tags = 0;
125 static int do_show_stream_tags = 0;
126 static int do_show_packet_tags = 0;
127
128 static int show_value_unit = 0;
129 static int use_value_prefix = 0;
130 static int use_byte_value_binary_prefix = 0;
131 static int use_value_sexagesimal_format = 0;
132 static int show_private_data = 1;
133
134 static const char *audio_codec_name = NULL;
135 static const char *data_codec_name = NULL;
136 static const char *subtitle_codec_name = NULL;
137 static const char *video_codec_name = NULL;
138
139 #define SHOW_OPTIONAL_FIELDS_AUTO -1
140 #define SHOW_OPTIONAL_FIELDS_NEVER 0
141 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
142 static int show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO;
143
144 static char *output_format;
145 static char *stream_specifier;
146 static char *show_data_hash;
147 static char *data_dump_format;
148
149 typedef struct ReadInterval {
150 int id; ///< identifier
151 int64_t start, end; ///< start, end in second/AV_TIME_BASE units
152 int has_start, has_end;
153 int start_is_offset, end_is_offset;
154 int duration_frames;
155 } ReadInterval;
156
157 static ReadInterval *read_intervals;
158 static int read_intervals_nb = 0;
159
160 static int find_stream_info = 1;
161
162 /* section structure definition */
163
164 typedef enum {
165 SECTION_ID_CHAPTER,
166 SECTION_ID_CHAPTER_TAGS,
167 SECTION_ID_CHAPTERS,
168 SECTION_ID_ERROR,
169 SECTION_ID_FORMAT,
170 SECTION_ID_FORMAT_TAGS,
171 SECTION_ID_FRAME,
172 SECTION_ID_FRAMES,
173 SECTION_ID_FRAME_TAGS,
174 SECTION_ID_FRAME_SIDE_DATA_LIST,
175 SECTION_ID_FRAME_SIDE_DATA,
176 SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST,
177 SECTION_ID_FRAME_SIDE_DATA_TIMECODE,
178 SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST,
179 SECTION_ID_FRAME_SIDE_DATA_COMPONENT,
180 SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST,
181 SECTION_ID_FRAME_SIDE_DATA_PIECE,
182 SECTION_ID_FRAME_LOG,
183 SECTION_ID_FRAME_LOGS,
184 SECTION_ID_LIBRARY_VERSION,
185 SECTION_ID_LIBRARY_VERSIONS,
186 SECTION_ID_PACKET,
187 SECTION_ID_PACKET_TAGS,
188 SECTION_ID_PACKETS,
189 SECTION_ID_PACKETS_AND_FRAMES,
190 SECTION_ID_PACKET_SIDE_DATA_LIST,
191 SECTION_ID_PACKET_SIDE_DATA,
192 SECTION_ID_PIXEL_FORMAT,
193 SECTION_ID_PIXEL_FORMAT_FLAGS,
194 SECTION_ID_PIXEL_FORMAT_COMPONENT,
195 SECTION_ID_PIXEL_FORMAT_COMPONENTS,
196 SECTION_ID_PIXEL_FORMATS,
197 SECTION_ID_PROGRAM_STREAM_DISPOSITION,
198 SECTION_ID_PROGRAM_STREAM_TAGS,
199 SECTION_ID_PROGRAM,
200 SECTION_ID_PROGRAM_STREAMS,
201 SECTION_ID_PROGRAM_STREAM,
202 SECTION_ID_PROGRAM_TAGS,
203 SECTION_ID_PROGRAM_VERSION,
204 SECTION_ID_PROGRAMS,
205 SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION,
206 SECTION_ID_STREAM_GROUP_STREAM_TAGS,
207 SECTION_ID_STREAM_GROUP,
208 SECTION_ID_STREAM_GROUP_COMPONENTS,
209 SECTION_ID_STREAM_GROUP_COMPONENT,
210 SECTION_ID_STREAM_GROUP_SUBCOMPONENTS,
211 SECTION_ID_STREAM_GROUP_SUBCOMPONENT,
212 SECTION_ID_STREAM_GROUP_PIECES,
213 SECTION_ID_STREAM_GROUP_PIECE,
214 SECTION_ID_STREAM_GROUP_SUBPIECES,
215 SECTION_ID_STREAM_GROUP_SUBPIECE,
216 SECTION_ID_STREAM_GROUP_BLOCKS,
217 SECTION_ID_STREAM_GROUP_BLOCK,
218 SECTION_ID_STREAM_GROUP_SIDE_DATA_LIST,
219 SECTION_ID_STREAM_GROUP_SIDE_DATA,
220 SECTION_ID_STREAM_GROUP_STREAMS,
221 SECTION_ID_STREAM_GROUP_STREAM,
222 SECTION_ID_STREAM_GROUP_DISPOSITION,
223 SECTION_ID_STREAM_GROUP_TAGS,
224 SECTION_ID_STREAM_GROUPS,
225 SECTION_ID_ROOT,
226 SECTION_ID_STREAM,
227 SECTION_ID_STREAM_DISPOSITION,
228 SECTION_ID_STREAMS,
229 SECTION_ID_STREAM_TAGS,
230 SECTION_ID_STREAM_SIDE_DATA_LIST,
231 SECTION_ID_STREAM_SIDE_DATA,
232 SECTION_ID_SUBTITLE,
233 } SectionID;
234
235 810 static const char *get_packet_side_data_type(const void *data)
236 {
237 810 const AVPacketSideData *sd = (const AVPacketSideData *)data;
238 810 return av_x_if_null(av_packet_side_data_name(sd->type), "unknown");
239 }
240
241 150 static const char *get_frame_side_data_type(const void *data)
242 {
243 150 const AVFrameSideData *sd = (const AVFrameSideData *)data;
244 150 return av_x_if_null(av_frame_side_data_name(sd->type), "unknown");
245 }
246
247 static const char *get_raw_string_type(const void *data)
248 {
249 return data;
250 }
251
252 static const char *get_stream_group_type(const void *data)
253 {
254 const AVStreamGroup *stg = (const AVStreamGroup *)data;
255 return av_x_if_null(avformat_stream_group_name(stg->type), "unknown");
256 }
257
258 static const AVTextFormatSection sections[] = {
259 [SECTION_ID_CHAPTERS] = { SECTION_ID_CHAPTERS, "chapters", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_CHAPTER, -1 } },
260 [SECTION_ID_CHAPTER] = { SECTION_ID_CHAPTER, "chapter", 0, { SECTION_ID_CHAPTER_TAGS, -1 } },
261 [SECTION_ID_CHAPTER_TAGS] = { SECTION_ID_CHAPTER_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "chapter_tags" },
262 [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "error", 0, { -1 } },
263 [SECTION_ID_FORMAT] = { SECTION_ID_FORMAT, "format", 0, { SECTION_ID_FORMAT_TAGS, -1 } },
264 [SECTION_ID_FORMAT_TAGS] = { SECTION_ID_FORMAT_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "format_tags" },
265 [SECTION_ID_FRAMES] = { SECTION_ID_FRAMES, "frames", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME, SECTION_ID_SUBTITLE, -1 } },
266 [SECTION_ID_FRAME] = { SECTION_ID_FRAME, "frame", 0, { SECTION_ID_FRAME_TAGS, SECTION_ID_FRAME_SIDE_DATA_LIST, SECTION_ID_FRAME_LOGS, -1 } },
267 [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" },
268 [SECTION_ID_FRAME_SIDE_DATA_LIST] ={ SECTION_ID_FRAME_SIDE_DATA_LIST, "side_data_list", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "frame_side_data_list" },
269 [SECTION_ID_FRAME_SIDE_DATA] = { SECTION_ID_FRAME_SIDE_DATA, "side_data", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST, -1 }, .unique_name = "frame_side_data", .element_name = "side_datum", .get_type = get_frame_side_data_type },
270 [SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST] = { SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, "timecodes", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_TIMECODE, -1 } },
271 [SECTION_ID_FRAME_SIDE_DATA_TIMECODE] = { SECTION_ID_FRAME_SIDE_DATA_TIMECODE, "timecode", 0, { -1 } },
272 [SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST] = { SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST, "components", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_COMPONENT, -1 }, .element_name = "component", .unique_name = "frame_side_data_components" },
273 [SECTION_ID_FRAME_SIDE_DATA_COMPONENT] = { SECTION_ID_FRAME_SIDE_DATA_COMPONENT, "component", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST, -1 }, .unique_name = "frame_side_data_component", .element_name = "component_entry", .get_type = get_raw_string_type },
274 [SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST] = { SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST, "pieces", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_PIECE, -1 }, .element_name = "piece", .unique_name = "frame_side_data_pieces" },
275 [SECTION_ID_FRAME_SIDE_DATA_PIECE] = { SECTION_ID_FRAME_SIDE_DATA_PIECE, "piece", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { -1 }, .element_name = "piece_entry", .unique_name = "frame_side_data_piece", .get_type = get_raw_string_type },
276 [SECTION_ID_FRAME_LOGS] = { SECTION_ID_FRAME_LOGS, "logs", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_LOG, -1 } },
277 [SECTION_ID_FRAME_LOG] = { SECTION_ID_FRAME_LOG, "log", 0, { -1 }, },
278 [SECTION_ID_LIBRARY_VERSIONS] = { SECTION_ID_LIBRARY_VERSIONS, "library_versions", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_LIBRARY_VERSION, -1 } },
279 [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } },
280 [SECTION_ID_PACKETS] = { SECTION_ID_PACKETS, "packets", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} },
281 [SECTION_ID_PACKETS_AND_FRAMES] = { SECTION_ID_PACKETS_AND_FRAMES, "packets_and_frames", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE, { SECTION_ID_PACKET, -1} },
282 [SECTION_ID_PACKET] = { SECTION_ID_PACKET, "packet", 0, { SECTION_ID_PACKET_TAGS, SECTION_ID_PACKET_SIDE_DATA_LIST, -1 } },
283 [SECTION_ID_PACKET_TAGS] = { SECTION_ID_PACKET_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "packet_tags" },
284 [SECTION_ID_PACKET_SIDE_DATA_LIST] ={ SECTION_ID_PACKET_SIDE_DATA_LIST, "side_data_list", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "packet_side_data_list" },
285 [SECTION_ID_PACKET_SIDE_DATA] = { SECTION_ID_PACKET_SIDE_DATA, "side_data", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { -1 }, .unique_name = "packet_side_data", .element_name = "side_datum", .get_type = get_packet_side_data_type },
286 [SECTION_ID_PIXEL_FORMATS] = { SECTION_ID_PIXEL_FORMATS, "pixel_formats", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_PIXEL_FORMAT, -1 } },
287 [SECTION_ID_PIXEL_FORMAT] = { SECTION_ID_PIXEL_FORMAT, "pixel_format", 0, { SECTION_ID_PIXEL_FORMAT_FLAGS, SECTION_ID_PIXEL_FORMAT_COMPONENTS, -1 } },
288 [SECTION_ID_PIXEL_FORMAT_FLAGS] = { SECTION_ID_PIXEL_FORMAT_FLAGS, "flags", 0, { -1 }, .unique_name = "pixel_format_flags" },
289 [SECTION_ID_PIXEL_FORMAT_COMPONENTS] = { SECTION_ID_PIXEL_FORMAT_COMPONENTS, "components", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, {SECTION_ID_PIXEL_FORMAT_COMPONENT, -1 }, .unique_name = "pixel_format_components" },
290 [SECTION_ID_PIXEL_FORMAT_COMPONENT] = { SECTION_ID_PIXEL_FORMAT_COMPONENT, "component", 0, { -1 } },
291 [SECTION_ID_PROGRAM_STREAM_DISPOSITION] = { SECTION_ID_PROGRAM_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "program_stream_disposition" },
292 [SECTION_ID_PROGRAM_STREAM_TAGS] = { SECTION_ID_PROGRAM_STREAM_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_stream_tags" },
293 [SECTION_ID_PROGRAM] = { SECTION_ID_PROGRAM, "program", 0, { SECTION_ID_PROGRAM_TAGS, SECTION_ID_PROGRAM_STREAMS, -1 } },
294 [SECTION_ID_PROGRAM_STREAMS] = { SECTION_ID_PROGRAM_STREAMS, "streams", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM_STREAM, -1 }, .unique_name = "program_streams" },
295 [SECTION_ID_PROGRAM_STREAM] = { SECTION_ID_PROGRAM_STREAM, "stream", 0, { SECTION_ID_PROGRAM_STREAM_DISPOSITION, SECTION_ID_PROGRAM_STREAM_TAGS, -1 }, .unique_name = "program_stream" },
296 [SECTION_ID_PROGRAM_TAGS] = { SECTION_ID_PROGRAM_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_tags" },
297 [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
298 [SECTION_ID_PROGRAMS] = { SECTION_ID_PROGRAMS, "programs", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM, -1 } },
299 [SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION] = { SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_group_stream_disposition" },
300 [SECTION_ID_STREAM_GROUP_STREAM_TAGS] = { SECTION_ID_STREAM_GROUP_STREAM_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_group_stream_tags" },
301 [SECTION_ID_STREAM_GROUP] = { SECTION_ID_STREAM_GROUP, "stream_group", 0, { SECTION_ID_STREAM_GROUP_TAGS, SECTION_ID_STREAM_GROUP_DISPOSITION, SECTION_ID_STREAM_GROUP_COMPONENTS, SECTION_ID_STREAM_GROUP_STREAMS, -1 } },
302 [SECTION_ID_STREAM_GROUP_COMPONENTS] = { SECTION_ID_STREAM_GROUP_COMPONENTS, "components", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_COMPONENT, -1 }, .element_name = "component", .unique_name = "stream_group_components" },
303 [SECTION_ID_STREAM_GROUP_COMPONENT] = { SECTION_ID_STREAM_GROUP_COMPONENT, "component", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { SECTION_ID_STREAM_GROUP_SIDE_DATA_LIST, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS, -1 }, .unique_name = "stream_group_component", .element_name = "component_entry", .get_type = get_stream_group_type },
304 [SECTION_ID_STREAM_GROUP_SUBCOMPONENTS] = { SECTION_ID_STREAM_GROUP_SUBCOMPONENTS, "subcomponents", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_SUBCOMPONENT, -1 }, .element_name = "component" },
305 [SECTION_ID_STREAM_GROUP_SUBCOMPONENT] = { SECTION_ID_STREAM_GROUP_SUBCOMPONENT, "subcomponent", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { SECTION_ID_STREAM_GROUP_PIECES, -1 }, .element_name = "subcomponent_entry", .get_type = get_raw_string_type },
306 [SECTION_ID_STREAM_GROUP_PIECES] = { SECTION_ID_STREAM_GROUP_PIECES, "pieces", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_PIECE, -1 }, .element_name = "piece", .unique_name = "stream_group_pieces" },
307 [SECTION_ID_STREAM_GROUP_PIECE] = { SECTION_ID_STREAM_GROUP_PIECE, "piece", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { SECTION_ID_STREAM_GROUP_SUBPIECES, -1 }, .unique_name = "stream_group_piece", .element_name = "piece_entry", .get_type = get_raw_string_type },
308 [SECTION_ID_STREAM_GROUP_SUBPIECES] = { SECTION_ID_STREAM_GROUP_SUBPIECES, "subpieces", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_SUBPIECE, -1 }, .element_name = "subpiece" },
309 [SECTION_ID_STREAM_GROUP_SUBPIECE] = { SECTION_ID_STREAM_GROUP_SUBPIECE, "subpiece", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { SECTION_ID_STREAM_GROUP_BLOCKS, -1 }, .element_name = "subpiece_entry", .get_type = get_raw_string_type },
310 [SECTION_ID_STREAM_GROUP_BLOCKS] = { SECTION_ID_STREAM_GROUP_BLOCKS, "blocks", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_BLOCK, -1 }, .element_name = "block" },
311 [SECTION_ID_STREAM_GROUP_BLOCK] = { SECTION_ID_STREAM_GROUP_BLOCK, "block", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS|AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE, { -1 }, .element_name = "block_entry", .get_type = get_raw_string_type },
312 [SECTION_ID_STREAM_GROUP_SIDE_DATA_LIST] = { SECTION_ID_STREAM_GROUP_SIDE_DATA_LIST, "side_data_list", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "stream_group_side_data_list" },
313 [SECTION_ID_STREAM_GROUP_SIDE_DATA] = { SECTION_ID_STREAM_GROUP_SIDE_DATA, "side_data", AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE|AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .unique_name = "stream_group_side_data", .element_name = "side_datum", .get_type = get_packet_side_data_type },
314 [SECTION_ID_STREAM_GROUP_STREAMS] = { SECTION_ID_STREAM_GROUP_STREAMS, "streams", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP_STREAM, -1 }, .unique_name = "stream_group_streams" },
315 [SECTION_ID_STREAM_GROUP_STREAM] = { SECTION_ID_STREAM_GROUP_STREAM, "stream", 0, { SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION, SECTION_ID_STREAM_GROUP_STREAM_TAGS, -1 }, .unique_name = "stream_group_stream" },
316 [SECTION_ID_STREAM_GROUP_DISPOSITION] = { SECTION_ID_STREAM_GROUP_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_group_disposition" },
317 [SECTION_ID_STREAM_GROUP_TAGS] = { SECTION_ID_STREAM_GROUP_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_group_tags" },
318 [SECTION_ID_STREAM_GROUPS] = { SECTION_ID_STREAM_GROUPS, "stream_groups", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_GROUP, -1 } },
319 [SECTION_ID_ROOT] = { SECTION_ID_ROOT, "root", AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER,
320 { SECTION_ID_CHAPTERS, SECTION_ID_FORMAT, SECTION_ID_FRAMES, SECTION_ID_PROGRAMS, SECTION_ID_STREAM_GROUPS, SECTION_ID_STREAMS,
321 SECTION_ID_PACKETS, SECTION_ID_ERROR, SECTION_ID_PROGRAM_VERSION, SECTION_ID_LIBRARY_VERSIONS,
322 SECTION_ID_PIXEL_FORMATS, -1} },
323 [SECTION_ID_STREAMS] = { SECTION_ID_STREAMS, "streams", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM, -1 } },
324 [SECTION_ID_STREAM] = { SECTION_ID_STREAM, "stream", 0, { SECTION_ID_STREAM_DISPOSITION, SECTION_ID_STREAM_TAGS, SECTION_ID_STREAM_SIDE_DATA_LIST, -1 } },
325 [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" },
326 [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" },
327 [SECTION_ID_STREAM_SIDE_DATA_LIST] ={ SECTION_ID_STREAM_SIDE_DATA_LIST, "side_data_list", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "stream_side_data_list" },
328 [SECTION_ID_STREAM_SIDE_DATA] = { SECTION_ID_STREAM_SIDE_DATA, "side_data", AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE|AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .unique_name = "stream_side_data", .element_name = "side_datum", .get_type = get_packet_side_data_type },
329 [SECTION_ID_SUBTITLE] = { SECTION_ID_SUBTITLE, "subtitle", 0, { -1 } },
330 };
331
332 typedef struct EntrySelection {
333 int show_all_entries;
334 AVDictionary *entries_to_show;
335 } EntrySelection;
336
337 static EntrySelection selected_entries[FF_ARRAY_ELEMS(sections)] = { 0 };
338
339 static const OptionDef *options;
340
341 /* FFprobe context */
342 static const char *input_filename;
343 static const char *print_input_filename;
344 static const AVInputFormat *iformat = NULL;
345 static const char *output_filename = NULL;
346
347 static const char unit_second_str[] = "s" ;
348 static const char unit_hertz_str[] = "Hz" ;
349 static const char unit_byte_str[] = "byte" ;
350 static const char unit_bit_per_second_str[] = "bit/s";
351
352 static unsigned int nb_streams;
353 static uint64_t *nb_streams_packets;
354 static uint64_t *nb_streams_frames;
355 static int *selected_streams;
356 static int *streams_with_closed_captions;
357 static int *streams_with_film_grain;
358
359 static AVMutex log_mutex = AV_MUTEX_INITIALIZER;
360
361 typedef struct LogBuffer {
362 char *context_name;
363 int log_level;
364 char *log_message;
365 AVClassCategory category;
366 char *parent_name;
367 AVClassCategory parent_category;
368 }LogBuffer;
369
370 static LogBuffer *log_buffer;
371 static int log_buffer_size;
372
373 157928 static int is_key_selected_callback(AVTextFormatContext *tctx, const char *key)
374 {
375 157928 const AVTextFormatSection *section = tctx->section[tctx->level];
376 157928 const EntrySelection *selection = &selected_entries[section - sections];
377
378
4/4
✓ Branch 0 taken 92649 times.
✓ Branch 1 taken 65279 times.
✓ Branch 3 taken 18237 times.
✓ Branch 4 taken 74412 times.
157928 return selection->show_all_entries || av_dict_get(selection->entries_to_show, key, NULL, 0);
379 }
380
381 static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
382 {
383 AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
384 va_list vl2;
385 char line[1024];
386 static int print_prefix = 1;
387 void *new_log_buffer;
388
389 va_copy(vl2, vl);
390 av_log_default_callback(ptr, level, fmt, vl);
391 av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
392 va_end(vl2);
393
394 #if HAVE_THREADS
395 ff_mutex_lock(&log_mutex);
396
397 new_log_buffer = av_realloc_array(log_buffer, log_buffer_size + 1, sizeof(*log_buffer));
398 if (new_log_buffer) {
399 char *msg;
400 int i;
401
402 log_buffer = new_log_buffer;
403 memset(&log_buffer[log_buffer_size], 0, sizeof(log_buffer[log_buffer_size]));
404 log_buffer[log_buffer_size].context_name= avc ? av_strdup(avc->item_name(ptr)) : NULL;
405 if (avc) {
406 if (avc->get_category) log_buffer[log_buffer_size].category = avc->get_category(ptr);
407 else log_buffer[log_buffer_size].category = avc->category;
408 }
409 log_buffer[log_buffer_size].log_level = level;
410 msg = log_buffer[log_buffer_size].log_message = av_strdup(line);
411 for (i=strlen(msg) - 1; i>=0 && msg[i] == '\n'; i--) {
412 msg[i] = 0;
413 }
414 if (avc && avc->parent_log_context_offset) {
415 AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
416 avc->parent_log_context_offset);
417 if (parent && *parent) {
418 log_buffer[log_buffer_size].parent_name = av_strdup((*parent)->item_name(parent));
419 log_buffer[log_buffer_size].parent_category =
420 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
421 }
422 }
423 log_buffer_size ++;
424 }
425
426 ff_mutex_unlock(&log_mutex);
427 #endif
428 }
429
430
431 #define print_fmt(k, f, ...) do { \
432 av_bprint_clear(&pbuf); \
433 av_bprintf(&pbuf, f, __VA_ARGS__); \
434 avtext_print_string(tfc, k, pbuf.str, 0); \
435 } while (0)
436
437 #define print_list_fmt(k, f, n, m, ...) do { \
438 av_bprint_clear(&pbuf); \
439 for (unsigned int idx = 0; idx < n; idx++) { \
440 for (unsigned int idx2 = 0; idx2 < m; idx2++) { \
441 if (idx > 0 || idx2 > 0) \
442 av_bprint_chars(&pbuf, ' ', 1); \
443 av_bprintf(&pbuf, f, __VA_ARGS__); \
444 } \
445 } \
446 avtext_print_string(tfc, k, pbuf.str, 0); \
447 } while (0)
448
449 #define print_int(k, v) avtext_print_integer(tfc, k, v, 0)
450 #define print_q(k, v, s) avtext_print_rational(tfc, k, v, s)
451 #define print_str(k, v) avtext_print_string(tfc, k, v, 0)
452 #define print_str_opt(k, v) avtext_print_string(tfc, k, v, AV_TEXTFORMAT_PRINT_STRING_OPTIONAL)
453 #define print_str_validate(k, v) avtext_print_string(tfc, k, v, AV_TEXTFORMAT_PRINT_STRING_VALIDATE)
454 #define print_time(k, v, tb) avtext_print_time(tfc, k, v, tb, 0)
455 #define print_ts(k, v) avtext_print_ts(tfc, k, v, 0)
456 #define print_duration_time(k, v, tb) avtext_print_time(tfc, k, v, tb, 1)
457 #define print_duration_ts(k, v) avtext_print_ts(tfc, k, v, 1)
458 #define print_val(k, v, u) avtext_print_unit_integer(tfc, k, v, u)
459
460 101 static void print_integers(AVTextFormatContext *tfc, const char *key,
461 const void *data, int size, const char *format,
462 int columns, int bytes, int offset_add)
463 {
464 AVBPrint bp;
465 101 unsigned offset = 0;
466
467 101 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
468 101 av_bprint_chars(&bp, '\n', 1);
469
2/2
✓ Branch 0 taken 303 times.
✓ Branch 1 taken 101 times.
404 while (size) {
470 303 av_bprintf(&bp, "%08x: ", offset);
471
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 303 times.
1212 for (int i = 0, l = FFMIN(size, columns); i < l; i++) {
472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 909 times.
909 if (bytes == 1) av_bprintf(&bp, format, *(const uint8_t*)data);
473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 909 times.
909 else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
474
1/2
✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
909 else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
475 909 data = (const char*)data + bytes;
476 909 size--;
477 }
478 303 av_bprint_chars(&bp, '\n', 1);
479 303 offset += offset_add;
480 }
481 101 avtext_print_string(tfc, key, bp.str, 0);
482 101 }
483
484 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
485 { \
486 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
487 if (ret < 0) \
488 goto end; \
489 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
490 }
491
492 1409 static inline int show_tags(AVTextFormatContext *tfc, AVDictionary *tags, int section_id)
493 {
494 1409 const AVDictionaryEntry *tag = NULL;
495 1409 int ret = 0;
496
497
2/2
✓ Branch 0 taken 698 times.
✓ Branch 1 taken 711 times.
1409 if (!tags)
498 698 return 0;
499 711 avtext_print_section_header(tfc, NULL, section_id);
500
501
2/2
✓ Branch 1 taken 3342 times.
✓ Branch 2 taken 711 times.
4053 while ((tag = av_dict_iterate(tags, tag))) {
502
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3342 times.
3342 if ((ret = print_str_validate(tag->key, tag->value)) < 0)
503 break;
504 }
505 711 avtext_print_section_footer(tfc);
506
507 711 return ret;
508 }
509
510 101 static void print_displaymatrix(AVTextFormatContext *tfc, const int32_t matrix[9])
511 {
512 101 double rotation = av_display_rotation_get(matrix);
513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 101 times.
101 if (isnan(rotation))
514 rotation = 0;
515 101 print_integers(tfc, "displaymatrix", matrix, 9, " %11d", 3, 4, 1);
516 101 print_int("rotation", rotation);
517 101 }
518
519 30 static void print_mastering_display_metadata(AVTextFormatContext *tfc,
520 const AVMasteringDisplayMetadata *metadata)
521 {
522
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (metadata->has_primaries) {
523 30 print_q("red_x", metadata->display_primaries[0][0], '/');
524 30 print_q("red_y", metadata->display_primaries[0][1], '/');
525 30 print_q("green_x", metadata->display_primaries[1][0], '/');
526 30 print_q("green_y", metadata->display_primaries[1][1], '/');
527 30 print_q("blue_x", metadata->display_primaries[2][0], '/');
528 30 print_q("blue_y", metadata->display_primaries[2][1], '/');
529
530 30 print_q("white_point_x", metadata->white_point[0], '/');
531 30 print_q("white_point_y", metadata->white_point[1], '/');
532 }
533
534
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (metadata->has_luminance) {
535 30 print_q("min_luminance", metadata->min_luminance, '/');
536 30 print_q("max_luminance", metadata->max_luminance, '/');
537 }
538 30 }
539
540 29 static void print_context_light_level(AVTextFormatContext *tfc,
541 const AVContentLightMetadata *metadata)
542 {
543 29 print_int("max_content", metadata->MaxCLL);
544 29 print_int("max_average", metadata->MaxFALL);
545 29 }
546
547 2 static void print_dovi_metadata(AVTextFormatContext *tfc, const AVDOVIMetadata *dovi)
548 {
549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!dovi)
550 return;
551
552 {
553 2 const AVDOVIRpuDataHeader *hdr = av_dovi_get_header(dovi);
554 2 const AVDOVIDataMapping *mapping = av_dovi_get_mapping(dovi);
555 2 const AVDOVIColorMetadata *color = av_dovi_get_color(dovi);
556 AVBPrint pbuf;
557
558 2 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
559
560 // header
561 2 print_int("rpu_type", hdr->rpu_type);
562 2 print_int("rpu_format", hdr->rpu_format);
563 2 print_int("vdr_rpu_profile", hdr->vdr_rpu_profile);
564 2 print_int("vdr_rpu_level", hdr->vdr_rpu_level);
565 2 print_int("chroma_resampling_explicit_filter_flag",
566 hdr->chroma_resampling_explicit_filter_flag);
567 2 print_int("coef_data_type", hdr->coef_data_type);
568 2 print_int("coef_log2_denom", hdr->coef_log2_denom);
569 2 print_int("vdr_rpu_normalized_idc", hdr->vdr_rpu_normalized_idc);
570 2 print_int("bl_video_full_range_flag", hdr->bl_video_full_range_flag);
571 2 print_int("bl_bit_depth", hdr->bl_bit_depth);
572 2 print_int("el_bit_depth", hdr->el_bit_depth);
573 2 print_int("vdr_bit_depth", hdr->vdr_bit_depth);
574 2 print_int("spatial_resampling_filter_flag",
575 hdr->spatial_resampling_filter_flag);
576 2 print_int("el_spatial_resampling_filter_flag",
577 hdr->el_spatial_resampling_filter_flag);
578 2 print_int("disable_residual_flag", hdr->disable_residual_flag);
579
580 // data mapping values
581 2 print_int("vdr_rpu_id", mapping->vdr_rpu_id);
582 2 print_int("mapping_color_space", mapping->mapping_color_space);
583 2 print_int("mapping_chroma_format_idc",
584 mapping->mapping_chroma_format_idc);
585
586 2 print_int("nlq_method_idc", mapping->nlq_method_idc);
587
1/3
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
2 switch (mapping->nlq_method_idc) {
588 2 case AV_DOVI_NLQ_NONE:
589 2 print_str("nlq_method_idc_name", "none");
590 2 break;
591 case AV_DOVI_NLQ_LINEAR_DZ:
592 print_str("nlq_method_idc_name", "linear_dz");
593 break;
594 default:
595 print_str("nlq_method_idc_name", "unknown");
596 break;
597 }
598
599 2 print_int("num_x_partitions", mapping->num_x_partitions);
600 2 print_int("num_y_partitions", mapping->num_y_partitions);
601
602 2 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST);
603
604
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (int c = 0; c < 3; c++) {
605 6 const AVDOVIReshapingCurve *curve = &mapping->curves[c];
606 6 avtext_print_section_header(tfc, "Reshaping curve", SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
607
608
7/8
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 26 times.
✓ Branch 8 taken 26 times.
✓ Branch 9 taken 26 times.
✓ Branch 10 taken 6 times.
58 print_list_fmt("pivots", "%"PRIu16, curve->num_pivots, 1, curve->pivots[idx]);
609
610 6 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST);
611
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 6 times.
26 for (int i = 0; i < curve->num_pivots - 1; i++) {
612 AVBPrint piece_buf;
613
614 20 av_bprint_init(&piece_buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
615
2/3
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
20 switch (curve->mapping_idc[i]) {
616 16 case AV_DOVI_MAPPING_POLYNOMIAL:
617 16 av_bprintf(&piece_buf, "Polynomial");
618 16 break;
619 4 case AV_DOVI_MAPPING_MMR:
620 4 av_bprintf(&piece_buf, "MMR");
621 4 break;
622 default:
623 av_bprintf(&piece_buf, "Unknown");
624 break;
625 }
626 20 av_bprintf(&piece_buf, " mapping");
627
628 20 avtext_print_section_header(tfc, piece_buf.str, SECTION_ID_FRAME_SIDE_DATA_PIECE);
629 20 print_int("mapping_idc", curve->mapping_idc[i]);
630
2/3
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
20 switch (curve->mapping_idc[i]) {
631 16 case AV_DOVI_MAPPING_POLYNOMIAL:
632 16 print_str("mapping_idc_name", "polynomial");
633 16 print_int("poly_order", curve->poly_order[i]);
634
7/8
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 48 times.
✓ Branch 8 taken 48 times.
✓ Branch 9 taken 48 times.
✓ Branch 10 taken 16 times.
112 print_list_fmt("poly_coef", "%"PRIi64,
635 curve->poly_order[i] + 1, 1,
636 curve->poly_coef[i][idx]);
637 16 break;
638 4 case AV_DOVI_MAPPING_MMR:
639 4 print_str("mapping_idc_name", "mmr");
640 4 print_int("mmr_order", curve->mmr_order[i]);
641 4 print_int("mmr_constant", curve->mmr_constant[i]);
642
8/8
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 84 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 12 times.
✓ Branch 10 taken 4 times.
100 print_list_fmt("mmr_coef", "%"PRIi64,
643 curve->mmr_order[i], 7,
644 curve->mmr_coef[i][idx][idx2]);
645 4 break;
646 default:
647 print_str("mapping_idc_name", "unknown");
648 break;
649 }
650
651 // SECTION_ID_FRAME_SIDE_DATA_PIECE
652 20 avtext_print_section_footer(tfc);
653 }
654
655 // SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST
656 6 avtext_print_section_footer(tfc);
657
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (mapping->nlq_method_idc != AV_DOVI_NLQ_NONE) {
659 const AVDOVINLQParams *nlq = &mapping->nlq[c];
660 print_int("nlq_offset", nlq->nlq_offset);
661 print_int("vdr_in_max", nlq->vdr_in_max);
662
663 switch (mapping->nlq_method_idc) {
664 case AV_DOVI_NLQ_LINEAR_DZ:
665 print_int("linear_deadzone_slope", nlq->linear_deadzone_slope);
666 print_int("linear_deadzone_threshold", nlq->linear_deadzone_threshold);
667 break;
668 }
669 }
670
671 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
672 6 avtext_print_section_footer(tfc);
673 }
674
675 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
676 2 avtext_print_section_footer(tfc);
677
678 // color metadata
679 2 print_int("dm_metadata_id", color->dm_metadata_id);
680 2 print_int("scene_refresh_flag", color->scene_refresh_flag);
681
7/8
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✓ Branch 9 taken 18 times.
✓ Branch 10 taken 2 times.
38 print_list_fmt("ycc_to_rgb_matrix", "%d/%d",
682 FF_ARRAY_ELEMS(color->ycc_to_rgb_matrix), 1,
683 color->ycc_to_rgb_matrix[idx].num,
684 color->ycc_to_rgb_matrix[idx].den);
685
7/8
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 2 times.
14 print_list_fmt("ycc_to_rgb_offset", "%d/%d",
686 FF_ARRAY_ELEMS(color->ycc_to_rgb_offset), 1,
687 color->ycc_to_rgb_offset[idx].num,
688 color->ycc_to_rgb_offset[idx].den);
689
7/8
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✓ Branch 9 taken 18 times.
✓ Branch 10 taken 2 times.
38 print_list_fmt("rgb_to_lms_matrix", "%d/%d",
690 FF_ARRAY_ELEMS(color->rgb_to_lms_matrix), 1,
691 color->rgb_to_lms_matrix[idx].num,
692 color->rgb_to_lms_matrix[idx].den);
693 2 print_int("signal_eotf", color->signal_eotf);
694 2 print_int("signal_eotf_param0", color->signal_eotf_param0);
695 2 print_int("signal_eotf_param1", color->signal_eotf_param1);
696 2 print_int("signal_eotf_param2", color->signal_eotf_param2);
697 2 print_int("signal_bit_depth", color->signal_bit_depth);
698 2 print_int("signal_color_space", color->signal_color_space);
699 2 print_int("signal_chroma_format", color->signal_chroma_format);
700 2 print_int("signal_full_range_flag", color->signal_full_range_flag);
701 2 print_int("source_min_pq", color->source_min_pq);
702 2 print_int("source_max_pq", color->source_max_pq);
703 2 print_int("source_diagonal", color->source_diagonal);
704
705 2 av_bprint_finalize(&pbuf, NULL);
706 }
707 }
708
709 4 static void print_dynamic_hdr10_plus(AVTextFormatContext *tfc, const AVDynamicHDRPlus *metadata)
710 {
711
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!metadata)
712 return;
713 4 print_int("application version", metadata->application_version);
714 4 print_int("num_windows", metadata->num_windows);
715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 for (int n = 1; n < metadata->num_windows; n++) {
716 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
717 print_q("window_upper_left_corner_x",
718 params->window_upper_left_corner_x,'/');
719 print_q("window_upper_left_corner_y",
720 params->window_upper_left_corner_y,'/');
721 print_q("window_lower_right_corner_x",
722 params->window_lower_right_corner_x,'/');
723 print_q("window_lower_right_corner_y",
724 params->window_lower_right_corner_y,'/');
725 print_q("window_upper_left_corner_x",
726 params->window_upper_left_corner_x,'/');
727 print_q("window_upper_left_corner_y",
728 params->window_upper_left_corner_y,'/');
729 print_int("center_of_ellipse_x",
730 params->center_of_ellipse_x ) ;
731 print_int("center_of_ellipse_y",
732 params->center_of_ellipse_y );
733 print_int("rotation_angle",
734 params->rotation_angle);
735 print_int("semimajor_axis_internal_ellipse",
736 params->semimajor_axis_internal_ellipse);
737 print_int("semimajor_axis_external_ellipse",
738 params->semimajor_axis_external_ellipse);
739 print_int("semiminor_axis_external_ellipse",
740 params->semiminor_axis_external_ellipse);
741 print_int("overlap_process_option",
742 params->overlap_process_option);
743 }
744 4 print_q("targeted_system_display_maximum_luminance",
745 metadata->targeted_system_display_maximum_luminance,'/');
746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (metadata->targeted_system_display_actual_peak_luminance_flag) {
747 print_int("num_rows_targeted_system_display_actual_peak_luminance",
748 metadata->num_rows_targeted_system_display_actual_peak_luminance);
749 print_int("num_cols_targeted_system_display_actual_peak_luminance",
750 metadata->num_cols_targeted_system_display_actual_peak_luminance);
751 for (int i = 0; i < metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
752 for (int j = 0; j < metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
753 print_q("targeted_system_display_actual_peak_luminance",
754 metadata->targeted_system_display_actual_peak_luminance[i][j],'/');
755 }
756 }
757 }
758
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (int n = 0; n < metadata->num_windows; n++) {
759 4 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
760
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
16 for (int i = 0; i < 3; i++) {
761 12 print_q("maxscl",params->maxscl[i],'/');
762 }
763 4 print_q("average_maxrgb",
764 params->average_maxrgb,'/');
765 4 print_int("num_distribution_maxrgb_percentiles",
766 params->num_distribution_maxrgb_percentiles);
767
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 4 times.
40 for (int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
768 36 print_int("distribution_maxrgb_percentage",
769 params->distribution_maxrgb[i].percentage);
770 36 print_q("distribution_maxrgb_percentile",
771 params->distribution_maxrgb[i].percentile,'/');
772 }
773 4 print_q("fraction_bright_pixels",
774 params->fraction_bright_pixels,'/');
775 }
776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (metadata->mastering_display_actual_peak_luminance_flag) {
777 print_int("num_rows_mastering_display_actual_peak_luminance",
778 metadata->num_rows_mastering_display_actual_peak_luminance);
779 print_int("num_cols_mastering_display_actual_peak_luminance",
780 metadata->num_cols_mastering_display_actual_peak_luminance);
781 for (int i = 0; i < metadata->num_rows_mastering_display_actual_peak_luminance; i++) {
782 for (int j = 0; j < metadata->num_cols_mastering_display_actual_peak_luminance; j++) {
783 print_q("mastering_display_actual_peak_luminance",
784 metadata->mastering_display_actual_peak_luminance[i][j],'/');
785 }
786 }
787 }
788
789
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (int n = 0; n < metadata->num_windows; n++) {
790 4 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
791
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (params->tone_mapping_flag) {
792 4 print_q("knee_point_x", params->knee_point_x,'/');
793 4 print_q("knee_point_y", params->knee_point_y,'/');
794 4 print_int("num_bezier_curve_anchors",
795 params->num_bezier_curve_anchors );
796
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 4 times.
40 for (int i = 0; i < params->num_bezier_curve_anchors; i++) {
797 36 print_q("bezier_curve_anchors",
798 params->bezier_curve_anchors[i],'/');
799 }
800 }
801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (params->color_saturation_mapping_flag) {
802 print_q("color_saturation_weight",
803 params->color_saturation_weight,'/');
804 }
805 }
806 }
807
808 static void print_dynamic_hdr_smpte2094_app5(AVTextFormatContext *tfc, const AVDynamicHDRSmpte2094App5 *metadata)
809 {
810 if (!metadata)
811 return;
812 print_int("application_version", metadata->application_version);
813 print_int("minimum_application_version", metadata->minimum_application_version);
814 print_int("has_custom_hdr_reference_white_flag", metadata->has_custom_hdr_reference_white_flag);
815 print_int("has_adaptive_tone_map_flag", metadata->has_adaptive_tone_map_flag);
816
817 if (metadata->has_custom_hdr_reference_white_flag)
818 print_int("hdr_reference_white", metadata->hdr_reference_white);
819
820 if (!metadata->has_adaptive_tone_map_flag)
821 return;
822
823 print_int("baseline_hdr_headroom", metadata->baseline_hdr_headroom);
824 print_int("use_reference_white_tone_mapping_flag", metadata->use_reference_white_tone_mapping_flag);
825
826 if (metadata->use_reference_white_tone_mapping_flag)
827 return;
828
829 print_int("num_alternate_images", metadata->num_alternate_images);
830 print_int("gain_application_space_chromaticities_flag", metadata->gain_application_space_chromaticities_flag);
831 print_int("has_common_component_mix_params_flag", metadata->has_common_component_mix_params_flag);
832 print_int("has_common_curve_params_flag", metadata->has_common_curve_params_flag);
833
834 if (metadata->gain_application_space_chromaticities_flag == 3) {
835 for (int i = 0; i < 8; i++)
836 print_int("gain_application_space_chromaticities", metadata->gain_application_space_chromaticities[i]);
837 }
838
839 for (int a = 0; a < metadata->num_alternate_images; a++) {
840 print_int("alternate_hdr_headroom", metadata->alternate_hdr_headrooms[a]);
841
842 print_int("component_mixing_type", metadata->component_mixing_type[a]);
843 if (metadata->component_mixing_type[a] == 3) {
844 for (int k = 0; k < 6; k++) {
845 print_int("has_component_mixing_coefficient_flag", metadata->has_component_mixing_coefficient_flag[a][k]);
846 if (metadata->has_component_mixing_coefficient_flag[a][k])
847 print_int("component_mixing_coefficient", metadata->component_mixing_coefficient[a][k]);
848 }
849 }
850
851 print_int("gain_curve_num_control_points_minus_1", metadata->gain_curve_num_control_points_minus_1[a]);
852 print_int("gain_curve_use_pchip_slope_flag", metadata->gain_curve_use_pchip_slope_flag[a]);
853 for (int c = 0; c <= metadata->gain_curve_num_control_points_minus_1[a]; c++)
854 print_int("gain_curve_control_point_x", metadata->gain_curve_control_points_x[a][c]);
855 for (int c = 0; c <= metadata->gain_curve_num_control_points_minus_1[a]; c++)
856 print_int("gain_curve_control_point_y", metadata->gain_curve_control_points_y[a][c]);
857 if (!metadata->gain_curve_use_pchip_slope_flag[a]) {
858 for (int c = 0; c <= metadata->gain_curve_num_control_points_minus_1[a]; c++)
859 print_int("gain_curve_control_point_theta", metadata->gain_curve_control_points_theta[a][c]);
860 }
861 }
862 }
863
864 1 static void print_dynamic_hdr_vivid(AVTextFormatContext *tfc, const AVDynamicHDRVivid *metadata)
865 {
866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!metadata)
867 return;
868 1 print_int("system_start_code", metadata->system_start_code);
869 1 print_int("num_windows", metadata->num_windows);
870
871
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (int n = 0; n < metadata->num_windows; n++) {
872 1 const AVHDRVividColorTransformParams *params = &metadata->params[n];
873
874 1 print_q("minimum_maxrgb", params->minimum_maxrgb, '/');
875 1 print_q("average_maxrgb", params->average_maxrgb, '/');
876 1 print_q("variance_maxrgb", params->variance_maxrgb, '/');
877 1 print_q("maximum_maxrgb", params->maximum_maxrgb, '/');
878 }
879
880
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (int n = 0; n < metadata->num_windows; n++) {
881 1 const AVHDRVividColorTransformParams *params = &metadata->params[n];
882
883 1 print_int("tone_mapping_mode_flag", params->tone_mapping_mode_flag);
884
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (params->tone_mapping_mode_flag) {
885 1 print_int("tone_mapping_param_num", params->tone_mapping_param_num);
886
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < params->tone_mapping_param_num; i++) {
887 2 const AVHDRVividColorToneMappingParams *tm_params = &params->tm_params[i];
888
889 2 print_q("targeted_system_display_maximum_luminance",
890 tm_params->targeted_system_display_maximum_luminance, '/');
891 2 print_int("base_enable_flag", tm_params->base_enable_flag);
892
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (tm_params->base_enable_flag) {
893 2 print_q("base_param_m_p", tm_params->base_param_m_p, '/');
894 2 print_q("base_param_m_m", tm_params->base_param_m_m, '/');
895 2 print_q("base_param_m_a", tm_params->base_param_m_a, '/');
896 2 print_q("base_param_m_b", tm_params->base_param_m_b, '/');
897 2 print_q("base_param_m_n", tm_params->base_param_m_n, '/');
898
899 2 print_int("base_param_k1", tm_params->base_param_k1);
900 2 print_int("base_param_k2", tm_params->base_param_k2);
901 2 print_int("base_param_k3", tm_params->base_param_k3);
902 2 print_int("base_param_Delta_enable_mode",
903 tm_params->base_param_Delta_enable_mode);
904 2 print_q("base_param_Delta", tm_params->base_param_Delta, '/');
905 }
906 2 print_int("3Spline_enable_flag", tm_params->three_Spline_enable_flag);
907
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (tm_params->three_Spline_enable_flag) {
908 2 print_int("3Spline_num", tm_params->three_Spline_num);
909
910
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (int j = 0; j < tm_params->three_Spline_num; j++) {
911 2 const AVHDRVivid3SplineParams *three_spline = &tm_params->three_spline[j];
912 2 print_int("3Spline_TH_mode", three_spline->th_mode);
913
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (three_spline->th_mode == 0 || three_spline->th_mode == 2)
914 2 print_q("3Spline_TH_enable_MB", three_spline->th_enable_mb, '/');
915 2 print_q("3Spline_TH_enable", three_spline->th_enable, '/');
916 2 print_q("3Spline_TH_Delta1", three_spline->th_delta1, '/');
917 2 print_q("3Spline_TH_Delta2", three_spline->th_delta2, '/');
918 2 print_q("3Spline_enable_Strength", three_spline->enable_strength, '/');
919 }
920 }
921 }
922 }
923
924 1 print_int("color_saturation_mapping_flag", params->color_saturation_mapping_flag);
925
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (params->color_saturation_mapping_flag) {
926 1 print_int("color_saturation_num", params->color_saturation_num);
927
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < params->color_saturation_num; i++) {
928 2 print_q("color_saturation_gain", params->color_saturation_gain[i], '/');
929 }
930 }
931 }
932 }
933
934 4 static void print_ambient_viewing_environment(AVTextFormatContext *tfc,
935 const AVAmbientViewingEnvironment *env)
936 {
937
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!env)
938 return;
939
940 4 print_q("ambient_illuminance", env->ambient_illuminance, '/');
941 4 print_q("ambient_light_x", env->ambient_light_x, '/');
942 4 print_q("ambient_light_y", env->ambient_light_y, '/');
943 }
944
945 static void print_film_grain_params(AVTextFormatContext *tfc,
946 const AVFilmGrainParams *fgp)
947 {
948 const char *color_range, *color_primaries, *color_trc, *color_space;
949 const char *const film_grain_type_names[] = {
950 [AV_FILM_GRAIN_PARAMS_NONE] = "none",
951 [AV_FILM_GRAIN_PARAMS_AV1] = "av1",
952 [AV_FILM_GRAIN_PARAMS_H274] = "h274",
953 };
954
955 AVBPrint pbuf;
956 if (!fgp || fgp->type >= FF_ARRAY_ELEMS(film_grain_type_names))
957 return;
958
959 color_range = av_color_range_name(fgp->color_range);
960 color_primaries = av_color_primaries_name(fgp->color_primaries);
961 color_trc = av_color_transfer_name(fgp->color_trc);
962 color_space = av_color_space_name(fgp->color_space);
963
964 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
965 print_str("type", film_grain_type_names[fgp->type]);
966 print_fmt("seed", "%"PRIu64, fgp->seed);
967 print_int("width", fgp->width);
968 print_int("height", fgp->height);
969 print_int("subsampling_x", fgp->subsampling_x);
970 print_int("subsampling_y", fgp->subsampling_y);
971 print_str("color_range", color_range ? color_range : "unknown");
972 print_str("color_primaries", color_primaries ? color_primaries : "unknown");
973 print_str("color_trc", color_trc ? color_trc : "unknown");
974 print_str("color_space", color_space ? color_space : "unknown");
975
976 switch (fgp->type) {
977 case AV_FILM_GRAIN_PARAMS_NONE:
978 break;
979 case AV_FILM_GRAIN_PARAMS_AV1: {
980 const AVFilmGrainAOMParams *aom = &fgp->codec.aom;
981 const int num_ar_coeffs_y = 2 * aom->ar_coeff_lag * (aom->ar_coeff_lag + 1);
982 const int num_ar_coeffs_uv = num_ar_coeffs_y + !!aom->num_y_points;
983 print_int("chroma_scaling_from_luma", aom->chroma_scaling_from_luma);
984 print_int("scaling_shift", aom->scaling_shift);
985 print_int("ar_coeff_lag", aom->ar_coeff_lag);
986 print_int("ar_coeff_shift", aom->ar_coeff_shift);
987 print_int("grain_scale_shift", aom->grain_scale_shift);
988 print_int("overlap_flag", aom->overlap_flag);
989 print_int("limit_output_range", aom->limit_output_range);
990
991 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST);
992
993 if (aom->num_y_points) {
994 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
995
996 print_int("bit_depth_luma", fgp->bit_depth_luma);
997 print_list_fmt("y_points_value", "%"PRIu8, aom->num_y_points, 1, aom->y_points[idx][0]);
998 print_list_fmt("y_points_scaling", "%"PRIu8, aom->num_y_points, 1, aom->y_points[idx][1]);
999 print_list_fmt("ar_coeffs_y", "%"PRId8, num_ar_coeffs_y, 1, aom->ar_coeffs_y[idx]);
1000
1001 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
1002 avtext_print_section_footer(tfc);
1003 }
1004
1005 for (unsigned uv = 0; uv < 2; uv++) {
1006 if (!aom->num_uv_points[uv] && !aom->chroma_scaling_from_luma)
1007 continue;
1008
1009 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
1010
1011 print_int("bit_depth_chroma", fgp->bit_depth_chroma);
1012 print_list_fmt("uv_points_value", "%"PRIu8, aom->num_uv_points[uv], 1, aom->uv_points[uv][idx][0]);
1013 print_list_fmt("uv_points_scaling", "%"PRIu8, aom->num_uv_points[uv], 1, aom->uv_points[uv][idx][1]);
1014 print_list_fmt("ar_coeffs_uv", "%"PRId8, num_ar_coeffs_uv, 1, aom->ar_coeffs_uv[uv][idx]);
1015 print_int("uv_mult", aom->uv_mult[uv]);
1016 print_int("uv_mult_luma", aom->uv_mult_luma[uv]);
1017 print_int("uv_offset", aom->uv_offset[uv]);
1018
1019 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
1020 avtext_print_section_footer(tfc);
1021 }
1022
1023 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
1024 avtext_print_section_footer(tfc);
1025 break;
1026 }
1027 case AV_FILM_GRAIN_PARAMS_H274: {
1028 const AVFilmGrainH274Params *h274 = &fgp->codec.h274;
1029 print_int("model_id", h274->model_id);
1030 print_int("blending_mode_id", h274->blending_mode_id);
1031 print_int("log2_scale_factor", h274->log2_scale_factor);
1032
1033 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST);
1034
1035 for (int c = 0; c < 3; c++) {
1036 if (!h274->component_model_present[c])
1037 continue;
1038
1039 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
1040 print_int(c ? "bit_depth_chroma" : "bit_depth_luma", c ? fgp->bit_depth_chroma : fgp->bit_depth_luma);
1041
1042 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST);
1043 for (int i = 0; i < h274->num_intensity_intervals[c]; i++) {
1044
1045 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_PIECE);
1046 print_int("intensity_interval_lower_bound", h274->intensity_interval_lower_bound[c][i]);
1047 print_int("intensity_interval_upper_bound", h274->intensity_interval_upper_bound[c][i]);
1048 print_list_fmt("comp_model_value", "%"PRId16, h274->num_model_values[c], 1, h274->comp_model_value[c][i][idx]);
1049
1050 // SECTION_ID_FRAME_SIDE_DATA_PIECE
1051 avtext_print_section_footer(tfc);
1052 }
1053
1054 // SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST
1055 avtext_print_section_footer(tfc);
1056
1057 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
1058 avtext_print_section_footer(tfc);
1059 }
1060
1061 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
1062 avtext_print_section_footer(tfc);
1063 break;
1064 }
1065 }
1066
1067 av_bprint_finalize(&pbuf, NULL);
1068 }
1069
1070 1015 static void print_pkt_side_data(AVTextFormatContext *tfc,
1071 int width,
1072 int height,
1073 const AVPacketSideData *sd,
1074 SectionID id_data)
1075 {
1076 1015 const char *name = av_packet_side_data_name(sd->type);
1077
1078 1015 avtext_print_section_header(tfc, sd, id_data);
1079
1/2
✓ Branch 0 taken 1015 times.
✗ Branch 1 not taken.
1015 print_str("side_data_type", name ? name : "unknown");
1080
3/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1006 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
1015 if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1081 9 print_displaymatrix(tfc, (const int32_t*)sd->data);
1082
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 997 times.
1006 } else if (sd->type == AV_PKT_DATA_STEREO3D) {
1083 9 const AVStereo3D *stereo = (AVStereo3D *)sd->data;
1084 9 print_str("type", av_stereo3d_type_name(stereo->type));
1085 9 print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
1086 9 print_str("view", av_stereo3d_view_name(stereo->view));
1087 9 print_str("primary_eye", av_stereo3d_primary_eye_name(stereo->primary_eye));
1088 9 print_int("baseline", stereo->baseline);
1089 9 print_q("horizontal_disparity_adjustment", stereo->horizontal_disparity_adjustment, '/');
1090 9 print_q("horizontal_field_of_view", stereo->horizontal_field_of_view, '/');
1091
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 993 times.
997 } else if (sd->type == AV_PKT_DATA_SPHERICAL) {
1092 4 const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
1093 4 print_str("projection", av_spherical_projection_name(spherical->projection));
1094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
1095 print_int("padding", spherical->padding);
1096
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 } else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
1097 size_t l, t, r, b;
1098 4 av_spherical_tile_bounds(spherical, width, height,
1099 &l, &t, &r, &b);
1100 4 print_int("bound_left", l);
1101 4 print_int("bound_top", t);
1102 4 print_int("bound_right", r);
1103 4 print_int("bound_bottom", b);
1104 }
1105
1106 4 print_int("yaw", (double) spherical->yaw / (1 << 16));
1107 4 print_int("pitch", (double) spherical->pitch / (1 << 16));
1108 4 print_int("roll", (double) spherical->roll / (1 << 16));
1109
3/4
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 953 times.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
993 } else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
1110 40 print_int("skip_samples", AV_RL32(sd->data));
1111 40 print_int("discard_padding", AV_RL32(sd->data + 4));
1112 40 print_int("skip_reason", AV_RL8(sd->data + 8));
1113 40 print_int("discard_reason", AV_RL8(sd->data + 9));
1114
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 947 times.
953 } else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
1115 6 print_mastering_display_metadata(tfc, (AVMasteringDisplayMetadata *)sd->data);
1116
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 942 times.
947 } else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
1117 5 print_context_light_level(tfc, (AVContentLightMetadata *)sd->data);
1118
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 940 times.
942 } else if (sd->type == AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
1119 2 print_ambient_viewing_environment(
1120 2 tfc, (const AVAmbientViewingEnvironment *)sd->data);
1121
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 938 times.
940 } else if (sd->type == AV_PKT_DATA_DYNAMIC_HDR10_PLUS) {
1122 2 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
1123 2 print_dynamic_hdr10_plus(tfc, metadata);
1124
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 936 times.
938 } else if (sd->type == AV_PKT_DATA_DOVI_CONF) {
1125 2 AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord *)sd->data;
1126 2 const char *comp = "unknown";
1127 2 print_int("dv_version_major", dovi->dv_version_major);
1128 2 print_int("dv_version_minor", dovi->dv_version_minor);
1129 2 print_int("dv_profile", dovi->dv_profile);
1130 2 print_int("dv_level", dovi->dv_level);
1131 2 print_int("rpu_present_flag", dovi->rpu_present_flag);
1132 2 print_int("el_present_flag", dovi->el_present_flag);
1133 2 print_int("bl_present_flag", dovi->bl_present_flag);
1134 2 print_int("dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id);
1135
1/5
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 switch (dovi->dv_md_compression)
1136 {
1137 2 case AV_DOVI_COMPRESSION_NONE: comp = "none"; break;
1138 case AV_DOVI_COMPRESSION_LIMITED: comp = "limited"; break;
1139 case AV_DOVI_COMPRESSION_RESERVED: comp = "reserved"; break;
1140 case AV_DOVI_COMPRESSION_EXTENDED: comp = "extended"; break;
1141 }
1142 2 print_str("dv_md_compression", comp);
1143
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 932 times.
936 } else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
1144 4 enum AVAudioServiceType *t = (enum AVAudioServiceType *)sd->data;
1145 4 print_int("service_type", *t);
1146
2/2
✓ Branch 0 taken 762 times.
✓ Branch 1 taken 170 times.
932 } else if (sd->type == AV_PKT_DATA_MPEGTS_STREAM_ID) {
1147 762 print_int("id", *sd->data);
1148
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 161 times.
170 } else if (sd->type == AV_PKT_DATA_CPB_PROPERTIES) {
1149 9 const AVCPBProperties *prop = (AVCPBProperties *)sd->data;
1150 9 print_int("max_bitrate", prop->max_bitrate);
1151 9 print_int("min_bitrate", prop->min_bitrate);
1152 9 print_int("avg_bitrate", prop->avg_bitrate);
1153 9 print_int("buffer_size", prop->buffer_size);
1154 9 print_int("vbv_delay", prop->vbv_delay);
1155
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 8 times.
161 } else if (sd->type == AV_PKT_DATA_WEBVTT_IDENTIFIER ||
1156
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 137 times.
153 sd->type == AV_PKT_DATA_WEBVTT_SETTINGS) {
1157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (do_show_data)
1158 avtext_print_data(tfc, "data", sd->data, sd->size);
1159 24 avtext_print_data_hash(tfc, "data_hash", sd->data, sd->size);
1160
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 134 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
137 } else if (sd->type == AV_PKT_DATA_FRAME_CROPPING && sd->size >= sizeof(uint32_t) * 4) {
1161 3 print_int("crop_top", AV_RL32(sd->data));
1162 3 print_int("crop_bottom", AV_RL32(sd->data + 4));
1163 3 print_int("crop_left", AV_RL32(sd->data + 8));
1164 3 print_int("crop_right", AV_RL32(sd->data + 12));
1165
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 134 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
134 } else if (sd->type == AV_PKT_DATA_AFD && sd->size > 0) {
1166 print_int("active_format", *sd->data);
1167
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 133 times.
134 } else if (sd->type == AV_PKT_DATA_EXIF) {
1168 1 print_int("size", sd->size);
1169
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
133 } else if (sd->type == AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL && sd->size >= 8) {
1170 print_int("block_additional_id", AV_RB64(sd->data));
1171 if (do_show_data)
1172 avtext_print_data(tfc, "block_additional_data", sd->data + 8, sd->size - 8);
1173 }
1174 1015 }
1175
1176 511 static void print_private_data(AVTextFormatContext *tfc, void *priv_data)
1177 {
1178 511 const AVOption *opt = NULL;
1179
2/2
✓ Branch 1 taken 3908 times.
✓ Branch 2 taken 511 times.
4419 while (opt = av_opt_next(priv_data, opt)) {
1180 uint8_t *str;
1181
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 250 times.
3908 if (!(opt->flags & AV_OPT_FLAG_EXPORT)) continue;
1182
1/2
✓ Branch 1 taken 250 times.
✗ Branch 2 not taken.
250 if (av_opt_get(priv_data, opt->name, 0, &str) >= 0) {
1183 250 print_str(opt->name, str);
1184 250 av_free(str);
1185 }
1186 }
1187 511 }
1188
1189 799 static void print_pixel_format(AVTextFormatContext *tfc, enum AVPixelFormat pix_fmt)
1190 {
1191 799 const char *s = av_get_pix_fmt_name(pix_fmt);
1192 enum AVPixelFormat swapped_pix_fmt;
1193
1194
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 796 times.
799 if (!s) {
1195 3 print_str_opt("pix_fmt", "unknown");
1196
4/4
✓ Branch 0 taken 764 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 740 times.
✓ Branch 3 taken 24 times.
1560 } else if (!do_bitexact ||
1197 764 (swapped_pix_fmt = av_pix_fmt_swap_endianness(pix_fmt)) == AV_PIX_FMT_NONE) {
1198 772 print_str ("pix_fmt", s);
1199 } else {
1200 24 const char *s2 = av_get_pix_fmt_name(swapped_pix_fmt);
1201 char buf[128];
1202 24 size_t i = 0;
1203
1204
4/6
✓ Branch 0 taken 233 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 209 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 209 times.
✗ Branch 5 not taken.
233 while (s[i] && s[i] == s2[i] && i < sizeof(buf) - 1) {
1205 209 buf[i] = s[i];
1206 209 i++;
1207 }
1208 24 buf[i] = '\0';
1209
1210 24 print_str ("pix_fmt", buf);
1211 }
1212 799 }
1213
1214 799 static void print_color_range(AVTextFormatContext *tfc, enum AVColorRange color_range)
1215 {
1216 799 const char *val = av_color_range_name(color_range);
1217
3/4
✓ Branch 0 taken 799 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 453 times.
✓ Branch 3 taken 346 times.
799 if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
1218 453 print_str_opt("color_range", "unknown");
1219 } else {
1220 346 print_str("color_range", val);
1221 }
1222 799 }
1223
1224 799 static void print_color_space(AVTextFormatContext *tfc, enum AVColorSpace color_space)
1225 {
1226 799 const char *val = av_color_space_name(color_space);
1227
3/4
✓ Branch 0 taken 799 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 569 times.
✓ Branch 3 taken 230 times.
799 if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
1228 569 print_str_opt("color_space", "unknown");
1229 } else {
1230 230 print_str("color_space", val);
1231 }
1232 799 }
1233
1234 799 static void print_primaries(AVTextFormatContext *tfc, enum AVColorPrimaries color_primaries)
1235 {
1236 799 const char *val = av_color_primaries_name(color_primaries);
1237
3/4
✓ Branch 0 taken 799 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 593 times.
✓ Branch 3 taken 206 times.
799 if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
1238 593 print_str_opt("color_primaries", "unknown");
1239 } else {
1240 206 print_str("color_primaries", val);
1241 }
1242 799 }
1243
1244 799 static void print_color_trc(AVTextFormatContext *tfc, enum AVColorTransferCharacteristic color_trc)
1245 {
1246 799 const char *val = av_color_transfer_name(color_trc);
1247
3/4
✓ Branch 0 taken 799 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 592 times.
✓ Branch 3 taken 207 times.
799 if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
1248 592 print_str_opt("color_transfer", "unknown");
1249 } else {
1250 207 print_str("color_transfer", val);
1251 }
1252 799 }
1253
1254 799 static void print_chroma_location(AVTextFormatContext *tfc, enum AVChromaLocation chroma_location)
1255 {
1256 799 const char *val = av_chroma_location_name(chroma_location);
1257
3/4
✓ Branch 0 taken 799 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 455 times.
✓ Branch 3 taken 344 times.
799 if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
1258 455 print_str_opt("chroma_location", "unspecified");
1259 } else {
1260 344 print_str("chroma_location", val);
1261 }
1262 799 }
1263
1264 674 static void print_alpha_mode(AVTextFormatContext *tfc, enum AVAlphaMode alpha_mode)
1265 {
1266 674 const char *val = av_alpha_mode_name(alpha_mode);
1267
3/4
✓ Branch 0 taken 674 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 673 times.
✓ Branch 3 taken 1 times.
674 if (!val || alpha_mode == AVALPHA_MODE_UNSPECIFIED) {
1268 673 print_str_opt("alpha_mode", "unspecified");
1269 } else {
1270 1 print_str("alpha_mode", val);
1271 }
1272 674 }
1273
1274 6543 static void clear_log(int need_lock)
1275 {
1276 int i;
1277
1278
1/2
✓ Branch 0 taken 6543 times.
✗ Branch 1 not taken.
6543 if (need_lock)
1279 6543 ff_mutex_lock(&log_mutex);
1280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6543 times.
6543 for (i=0; i<log_buffer_size; i++) {
1281 av_freep(&log_buffer[i].context_name);
1282 av_freep(&log_buffer[i].parent_name);
1283 av_freep(&log_buffer[i].log_message);
1284 }
1285 6543 log_buffer_size = 0;
1286
1/2
✓ Branch 0 taken 6543 times.
✗ Branch 1 not taken.
6543 if(need_lock)
1287 6543 ff_mutex_unlock(&log_mutex);
1288 6543 }
1289
1290 static int show_log(AVTextFormatContext *tfc, int section_ids, int section_id, int log_level)
1291 {
1292 int i;
1293 ff_mutex_lock(&log_mutex);
1294 if (!log_buffer_size) {
1295 ff_mutex_unlock(&log_mutex);
1296 return 0;
1297 }
1298 avtext_print_section_header(tfc, NULL, section_ids);
1299
1300 for (i=0; i<log_buffer_size; i++) {
1301 if (log_buffer[i].log_level <= log_level) {
1302 avtext_print_section_header(tfc, NULL, section_id);
1303 print_str("context", log_buffer[i].context_name);
1304 print_int("level", log_buffer[i].log_level);
1305 print_int("category", log_buffer[i].category);
1306 if (log_buffer[i].parent_name) {
1307 print_str("parent_context", log_buffer[i].parent_name);
1308 print_int("parent_category", log_buffer[i].parent_category);
1309 } else {
1310 print_str_opt("parent_context", "N/A");
1311 print_str_opt("parent_category", "N/A");
1312 }
1313 print_str("message", log_buffer[i].log_message);
1314 avtext_print_section_footer(tfc);
1315 }
1316 }
1317 clear_log(0);
1318 ff_mutex_unlock(&log_mutex);
1319
1320 avtext_print_section_footer(tfc);
1321
1322 return 0;
1323 }
1324
1325 5866 static void show_packet(AVTextFormatContext *tfc, InputFile *ifile, AVPacket *pkt, int packet_idx)
1326 {
1327 5866 AVStream *st = ifile->streams[pkt->stream_index].st;
1328 AVBPrint pbuf;
1329 const char *s;
1330
1331 5866 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
1332
1333 5866 avtext_print_section_header(tfc, NULL, SECTION_ID_PACKET);
1334
1335 5866 s = av_get_media_type_string(st->codecpar->codec_type);
1336
1/2
✓ Branch 0 taken 5866 times.
✗ Branch 1 not taken.
5866 if (s) print_str ("codec_type", s);
1337 else print_str_opt("codec_type", "unknown");
1338 5866 print_int("stream_index", pkt->stream_index);
1339 5866 print_ts ("pts", pkt->pts);
1340 5866 print_time("pts_time", pkt->pts, &st->time_base);
1341 5866 print_ts ("dts", pkt->dts);
1342 5866 print_time("dts_time", pkt->dts, &st->time_base);
1343 5866 print_duration_ts("duration", pkt->duration);
1344 5866 print_duration_time("duration_time", pkt->duration, &st->time_base);
1345 5866 print_val("size", pkt->size, unit_byte_str);
1346
2/2
✓ Branch 0 taken 5753 times.
✓ Branch 1 taken 113 times.
5866 if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos);
1347 113 else print_str_opt("pos", "N/A");
1348
6/6
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5861 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 5860 times.
✓ Branch 5 taken 4823 times.
✓ Branch 6 taken 1043 times.
5866 print_fmt("flags", "%c%c%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_',
1349 pkt->flags & AV_PKT_FLAG_DISCARD ? 'D' : '_',
1350 pkt->flags & AV_PKT_FLAG_CORRUPT ? 'C' : '_');
1351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5866 times.
5866 if (do_show_data)
1352 avtext_print_data(tfc, "data", pkt->data, pkt->size);
1353 5866 avtext_print_data_hash(tfc, "data_hash", pkt->data, pkt->size);
1354
1355
2/2
✓ Branch 0 taken 961 times.
✓ Branch 1 taken 4905 times.
5866 if (pkt->side_data_elems) {
1356 size_t size;
1357 const uint8_t *side_metadata;
1358
1359 961 side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
1360
4/6
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 830 times.
✓ Branch 2 taken 131 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 131 times.
✗ Branch 5 not taken.
961 if (side_metadata && size && do_show_packet_tags) {
1361 131 AVDictionary *dict = NULL;
1362
1/2
✓ Branch 1 taken 131 times.
✗ Branch 2 not taken.
131 if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
1363 131 show_tags(tfc, dict, SECTION_ID_PACKET_TAGS);
1364 131 av_dict_free(&dict);
1365 }
1366
1367 961 avtext_print_section_header(tfc, NULL, SECTION_ID_PACKET_SIDE_DATA_LIST);
1368
2/2
✓ Branch 0 taken 961 times.
✓ Branch 1 taken 961 times.
1922 for (int i = 0; i < pkt->side_data_elems; i++) {
1369 961 print_pkt_side_data(tfc, st->codecpar->width, st->codecpar->height, &pkt->side_data[i],
1370 SECTION_ID_PACKET_SIDE_DATA);
1371 961 avtext_print_section_footer(tfc);
1372 }
1373 961 avtext_print_section_footer(tfc);
1374 }
1375
1376 5866 avtext_print_section_footer(tfc);
1377
1378 5866 av_bprint_finalize(&pbuf, NULL);
1379 5866 fflush(stdout);
1380 5866 }
1381
1382 static void show_subtitle(AVTextFormatContext *tfc, AVSubtitle *sub, AVStream *stream,
1383 AVFormatContext *fmt_ctx)
1384 {
1385 AVBPrint pbuf;
1386
1387 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
1388
1389 avtext_print_section_header(tfc, NULL, SECTION_ID_SUBTITLE);
1390
1391 print_str ("media_type", "subtitle");
1392 print_ts ("pts", sub->pts);
1393 print_time("pts_time", sub->pts, &AV_TIME_BASE_Q);
1394 print_int ("format", sub->format);
1395 print_int ("start_display_time", sub->start_display_time);
1396 print_int ("end_display_time", sub->end_display_time);
1397 print_int ("num_rects", sub->num_rects);
1398
1399 avtext_print_section_footer(tfc);
1400
1401 av_bprint_finalize(&pbuf, NULL);
1402 fflush(stdout);
1403 }
1404
1405 static void print_iamf_param_definition(AVTextFormatContext *tfc, const char *name,
1406 const AVIAMFParamDefinition *param, SectionID section_id);
1407
1408 280 static void print_frame_side_data(AVTextFormatContext *tfc,
1409 const AVFrame *frame,
1410 const AVStream *stream)
1411 {
1412 280 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_LIST);
1413
1414
2/2
✓ Branch 0 taken 431 times.
✓ Branch 1 taken 280 times.
711 for (int i = 0; i < frame->nb_side_data; i++) {
1415 431 const AVFrameSideData *sd = frame->side_data[i];
1416 const char *name;
1417
1418 431 avtext_print_section_header(tfc, sd, SECTION_ID_FRAME_SIDE_DATA);
1419 431 name = av_frame_side_data_name(sd->type);
1420
1/2
✓ Branch 0 taken 431 times.
✗ Branch 1 not taken.
431 print_str("side_data_type", name ? name : "unknown");
1421
3/4
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 339 times.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
431 if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1422 92 print_displaymatrix(tfc, (const int32_t*)sd->data);
1423
3/4
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 272 times.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
339 } else if (sd->type == AV_FRAME_DATA_AFD && sd->size > 0) {
1424 67 print_int("active_format", *sd->data);
1425
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 272 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
272 } else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
1426 char tcbuf[AV_TIMECODE_STR_SIZE];
1427 av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
1428 print_str("timecode", tcbuf);
1429
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 251 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
293 } else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
1430 21 uint32_t *tc = (uint32_t*)sd->data;
1431 21 int m = FFMIN(tc[0],3);
1432 21 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST);
1433
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 21 times.
42 for (int j = 1; j <= m ; j++) {
1434 char tcbuf[AV_TIMECODE_STR_SIZE];
1435 21 av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
1436 21 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_TIMECODE);
1437 21 print_str("value", tcbuf);
1438 21 avtext_print_section_footer(tfc);
1439 }
1440 21 avtext_print_section_footer(tfc);
1441
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 227 times.
251 } else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
1442 24 print_mastering_display_metadata(tfc, (AVMasteringDisplayMetadata *)sd->data);
1443
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 225 times.
227 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
1444 2 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
1445 2 print_dynamic_hdr10_plus(tfc, metadata);
1446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 225 times.
225 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5) {
1447 AVDynamicHDRSmpte2094App5 *metadata = (AVDynamicHDRSmpte2094App5 *)sd->data;
1448 print_dynamic_hdr_smpte2094_app5(tfc, metadata);
1449
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 201 times.
225 } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
1450 24 print_context_light_level(tfc, (AVContentLightMetadata *)sd->data);
1451
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 198 times.
201 } else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
1452 3 const AVDictionaryEntry *tag = av_dict_get(sd->metadata, "name", NULL, AV_DICT_MATCH_CASE);
1453
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (tag)
1454 2 print_str(tag->key, tag->value);
1455 3 print_int("size", sd->size);
1456
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 196 times.
198 } else if (sd->type == AV_FRAME_DATA_DOVI_METADATA) {
1457 2 print_dovi_metadata(tfc, (const AVDOVIMetadata *)sd->data);
1458
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 195 times.
196 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_VIVID) {
1459 1 AVDynamicHDRVivid *metadata = (AVDynamicHDRVivid *)sd->data;
1460 1 print_dynamic_hdr_vivid(tfc, metadata);
1461
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 193 times.
195 } else if (sd->type == AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
1462 2 print_ambient_viewing_environment(tfc, (const AVAmbientViewingEnvironment *)sd->data);
1463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 193 times.
193 } else if (sd->type == AV_FRAME_DATA_FILM_GRAIN_PARAMS) {
1464 AVFilmGrainParams *fgp = (AVFilmGrainParams *)sd->data;
1465 print_film_grain_params(tfc, fgp);
1466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 193 times.
193 } else if (sd->type == AV_FRAME_DATA_VIEW_ID) {
1467 print_int("view_id", *(int*)sd->data);
1468
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 185 times.
193 } else if (sd->type == AV_FRAME_DATA_EXIF) {
1469 8 print_int("size", sd->size);
1470
1/2
✓ Branch 0 taken 185 times.
✗ Branch 1 not taken.
185 } else if (sd->type == AV_FRAME_DATA_IAMF_MIX_GAIN_PARAM ||
1471
1/2
✓ Branch 0 taken 185 times.
✗ Branch 1 not taken.
185 sd->type == AV_FRAME_DATA_IAMF_DEMIXING_INFO_PARAM ||
1472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 185 times.
185 sd->type == AV_FRAME_DATA_IAMF_RECON_GAIN_INFO_PARAM) {
1473 const AVIAMFParamDefinition *param = (AVIAMFParamDefinition *)sd->data;
1474 print_iamf_param_definition(tfc, NULL, param, SECTION_ID_FRAME_SIDE_DATA);
1475 }
1476 431 avtext_print_section_footer(tfc);
1477 }
1478 280 avtext_print_section_footer(tfc);
1479 280 }
1480
1481 3249 static void show_frame(AVTextFormatContext *tfc, AVFrame *frame, AVStream *stream,
1482 AVFormatContext *fmt_ctx)
1483 {
1484
1/2
✓ Branch 0 taken 3249 times.
✗ Branch 1 not taken.
3249 FrameData *fd = frame->opaque_ref ? (FrameData*)frame->opaque_ref->data : NULL;
1485 AVBPrint pbuf;
1486 char val_str[128];
1487 const char *s;
1488
1489 3249 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
1490
1491 3249 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME);
1492
1493 3249 s = av_get_media_type_string(stream->codecpar->codec_type);
1494
1/2
✓ Branch 0 taken 3249 times.
✗ Branch 1 not taken.
3249 if (s) print_str ("media_type", s);
1495 else print_str_opt("media_type", "unknown");
1496 3249 print_int("stream_index", stream->index);
1497 3249 print_int("key_frame", !!(frame->flags & AV_FRAME_FLAG_KEY));
1498 3249 print_ts ("pts", frame->pts);
1499 3249 print_time("pts_time", frame->pts, &stream->time_base);
1500 3249 print_ts ("pkt_dts", frame->pkt_dts);
1501 3249 print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
1502 3249 print_ts ("best_effort_timestamp", frame->best_effort_timestamp);
1503 3249 print_time("best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
1504 3249 print_duration_ts ("duration", frame->duration);
1505 3249 print_duration_time("duration_time", frame->duration, &stream->time_base);
1506
3/4
✓ Branch 0 taken 3249 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2562 times.
✓ Branch 3 taken 687 times.
3249 if (fd && fd->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, fd->pkt_pos);
1507 687 else print_str_opt("pkt_pos", "N/A");
1508
2/4
✓ Branch 0 taken 3249 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3249 times.
✗ Branch 3 not taken.
3249 if (fd && fd->pkt_size != -1) print_val ("pkt_size", fd->pkt_size, unit_byte_str);
1509 else print_str_opt("pkt_size", "N/A");
1510
1511
2/3
✓ Branch 0 taken 674 times.
✓ Branch 1 taken 2575 times.
✗ Branch 2 not taken.
3249 switch (stream->codecpar->codec_type) {
1512 AVRational sar;
1513
1514 674 case AVMEDIA_TYPE_VIDEO:
1515 674 print_int("width", frame->width);
1516 674 print_int("height", frame->height);
1517 674 print_int("crop_top", frame->crop_top);
1518 674 print_int("crop_bottom", frame->crop_bottom);
1519 674 print_int("crop_left", frame->crop_left);
1520 674 print_int("crop_right", frame->crop_right);
1521 674 print_pixel_format(tfc, frame->format);
1522 674 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
1523
2/2
✓ Branch 0 taken 601 times.
✓ Branch 1 taken 73 times.
674 if (sar.num) {
1524 601 print_q("sample_aspect_ratio", sar, ':');
1525 } else {
1526 73 print_str_opt("sample_aspect_ratio", "N/A");
1527 }
1528 674 print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
1529 674 print_int("interlaced_frame", !!(frame->flags & AV_FRAME_FLAG_INTERLACED));
1530 674 print_int("top_field_first", !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST));
1531 674 print_int("lossless", !!(frame->flags & AV_FRAME_FLAG_LOSSLESS));
1532 674 print_int("repeat_pict", frame->repeat_pict);
1533
1534 674 print_color_range(tfc, frame->color_range);
1535 674 print_color_space(tfc, frame->colorspace);
1536 674 print_primaries(tfc, frame->color_primaries);
1537 674 print_color_trc(tfc, frame->color_trc);
1538 674 print_chroma_location(tfc, frame->chroma_location);
1539 674 print_alpha_mode(tfc, frame->alpha_mode);
1540 674 break;
1541
1542 2575 case AVMEDIA_TYPE_AUDIO:
1543 2575 s = av_get_sample_fmt_name(frame->format);
1544
1/2
✓ Branch 0 taken 2575 times.
✗ Branch 1 not taken.
2575 if (s) print_str ("sample_fmt", s);
1545 else print_str_opt("sample_fmt", "unknown");
1546 2575 print_int("nb_samples", frame->nb_samples);
1547 2575 print_int("channels", frame->ch_layout.nb_channels);
1548
2/2
✓ Branch 0 taken 2352 times.
✓ Branch 1 taken 223 times.
2575 if (frame->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
1549 2352 av_channel_layout_describe(&frame->ch_layout, val_str, sizeof(val_str));
1550 2352 print_str ("channel_layout", val_str);
1551 } else
1552 223 print_str_opt("channel_layout", "unknown");
1553 2575 break;
1554 }
1555
2/2
✓ Branch 0 taken 1111 times.
✓ Branch 1 taken 2138 times.
3249 if (do_show_frame_tags)
1556 1111 show_tags(tfc, frame->metadata, SECTION_ID_FRAME_TAGS);
1557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3249 times.
3249 if (do_show_log)
1558 show_log(tfc, SECTION_ID_FRAME_LOGS, SECTION_ID_FRAME_LOG, do_show_log);
1559
2/2
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 2969 times.
3249 if (frame->nb_side_data)
1560 280 print_frame_side_data(tfc, frame, stream);
1561
1562 3249 avtext_print_section_footer(tfc);
1563
1564 3249 av_bprint_finalize(&pbuf, NULL);
1565 3249 fflush(stdout);
1566 3249 }
1567
1568 6543 static av_always_inline int process_frame(AVTextFormatContext *tfc,
1569 InputFile *ifile,
1570 AVFrame *frame, const AVPacket *pkt,
1571 int *packet_new)
1572 {
1573 6543 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
1574 6543 AVCodecContext *dec_ctx = ifile->streams[pkt->stream_index].dec_ctx;
1575 6543 AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar;
1576 AVSubtitle sub;
1577 6543 int ret = 0, got_frame = 0;
1578
1579 6543 clear_log(1);
1580
2/2
✓ Branch 0 taken 6537 times.
✓ Branch 1 taken 6 times.
6543 if (dec_ctx) {
1581
1/3
✓ Branch 0 taken 6537 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
6537 switch (par->codec_type) {
1582 6537 case AVMEDIA_TYPE_VIDEO:
1583 case AVMEDIA_TYPE_AUDIO:
1584
2/2
✓ Branch 0 taken 3323 times.
✓ Branch 1 taken 3214 times.
6537 if (*packet_new) {
1585 3323 ret = avcodec_send_packet(dec_ctx, pkt);
1586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3323 times.
3323 if (ret == AVERROR(EAGAIN)) {
1587 ret = 0;
1588
4/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 3286 times.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 2 times.
3323 } else if (ret >= 0 || ret == AVERROR_EOF) {
1589 3321 ret = 0;
1590 3321 *packet_new = 0;
1591 }
1592 }
1593
2/2
✓ Branch 0 taken 6535 times.
✓ Branch 1 taken 2 times.
6537 if (ret >= 0) {
1594 6535 ret = avcodec_receive_frame(dec_ctx, frame);
1595
2/2
✓ Branch 0 taken 3249 times.
✓ Branch 1 taken 3286 times.
6535 if (ret >= 0) {
1596 3249 got_frame = 1;
1597
3/4
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 3206 times.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
3286 } else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
1598 3286 ret = 0;
1599 }
1600 }
1601 6537 break;
1602
1603 case AVMEDIA_TYPE_SUBTITLE:
1604 if (*packet_new)
1605 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
1606 *packet_new = 0;
1607 break;
1608 default:
1609 *packet_new = 0;
1610 }
1611 } else {
1612 6 *packet_new = 0;
1613 }
1614
1615
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6541 times.
6543 if (ret < 0)
1616 2 return ret;
1617
2/2
✓ Branch 0 taken 3249 times.
✓ Branch 1 taken 3292 times.
6541 if (got_frame) {
1618 3249 int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
1619 3249 nb_streams_frames[pkt->stream_index]++;
1620
1/2
✓ Branch 0 taken 3249 times.
✗ Branch 1 not taken.
3249 if (do_show_frames)
1621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3249 times.
3249 if (is_sub)
1622 show_subtitle(tfc, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
1623 else
1624 3249 show_frame(tfc, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);
1625
1626
2/4
✓ Branch 0 taken 3249 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3249 times.
3249 if (!is_sub && do_analyze_frames) {
1627 for (int i = 0; i < frame->nb_side_data; i++) {
1628 if (frame->side_data[i]->type == AV_FRAME_DATA_A53_CC)
1629 streams_with_closed_captions[pkt->stream_index] = 1;
1630 else if (frame->side_data[i]->type == AV_FRAME_DATA_FILM_GRAIN_PARAMS)
1631 streams_with_film_grain[pkt->stream_index] = 1;
1632 }
1633 }
1634
1635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3249 times.
3249 if (is_sub)
1636 avsubtitle_free(&sub);
1637 }
1638
3/4
✓ Branch 0 taken 3292 times.
✓ Branch 1 taken 3249 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3292 times.
6541 return got_frame || *packet_new;
1639 }
1640
1641 122 static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
1642 {
1643 122 av_log(log_ctx, log_level, "id:%d", interval->id);
1644
1645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 122 times.
122 if (interval->has_start) {
1646 av_log(log_ctx, log_level, " start:%s%s", interval->start_is_offset ? "+" : "",
1647 av_ts2timestr(interval->start, &AV_TIME_BASE_Q));
1648 } else {
1649 122 av_log(log_ctx, log_level, " start:N/A");
1650 }
1651
1652
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 114 times.
122 if (interval->has_end) {
1653
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 av_log(log_ctx, log_level, " end:%s", interval->end_is_offset ? "+" : "");
1654
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (interval->duration_frames)
1655 2 av_log(log_ctx, log_level, "#%"PRId64, interval->end);
1656 else
1657 6 av_log(log_ctx, log_level, "%s", av_ts2timestr(interval->end, &AV_TIME_BASE_Q));
1658 } else {
1659 114 av_log(log_ctx, log_level, " end:N/A");
1660 }
1661
1662 122 av_log(log_ctx, log_level, "\n");
1663 122 }
1664
1665 118 static int read_interval_packets(AVTextFormatContext *tfc, InputFile *ifile,
1666 const ReadInterval *interval, int64_t *cur_ts)
1667 {
1668 118 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
1669 118 AVPacket *pkt = NULL;
1670 118 AVFrame *frame = NULL;
1671 118 int ret = 0, i = 0, frame_count = 0;
1672 118 int64_t start = -INT64_MAX, end = interval->end;
1673
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
118 int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
1674
1675 118 av_log(NULL, AV_LOG_VERBOSE, "Processing read interval ");
1676 118 log_read_interval(interval, NULL, AV_LOG_VERBOSE);
1677
1678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118 times.
118 if (interval->has_start) {
1679 int64_t target;
1680 if (interval->start_is_offset) {
1681 if (*cur_ts == AV_NOPTS_VALUE) {
1682 av_log(NULL, AV_LOG_ERROR,
1683 "Could not seek to relative position since current "
1684 "timestamp is not defined\n");
1685 ret = AVERROR(EINVAL);
1686 goto end;
1687 }
1688 target = *cur_ts + interval->start;
1689 } else {
1690 target = interval->start;
1691 }
1692
1693 av_log(NULL, AV_LOG_VERBOSE, "Seeking to read interval start point %s\n",
1694 av_ts2timestr(target, &AV_TIME_BASE_Q));
1695 if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
1696 av_log(NULL, AV_LOG_ERROR, "Could not seek to position %"PRId64": %s\n",
1697 interval->start, av_err2str(ret));
1698 goto end;
1699 }
1700 }
1701
1702 118 frame = av_frame_alloc();
1703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118 times.
118 if (!frame) {
1704 ret = AVERROR(ENOMEM);
1705 goto end;
1706 }
1707 118 pkt = av_packet_alloc();
1708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118 times.
118 if (!pkt) {
1709 ret = AVERROR(ENOMEM);
1710 goto end;
1711 }
1712
2/2
✓ Branch 1 taken 8897 times.
✓ Branch 2 taken 114 times.
9011 while (!av_read_frame(fmt_ctx, pkt)) {
1713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8897 times.
8897 if (fmt_ctx->nb_streams > nb_streams) {
1714 REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams);
1715 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);
1716 REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams);
1717 REALLOCZ_ARRAY_STREAM(streams_with_closed_captions, nb_streams, fmt_ctx->nb_streams);
1718 REALLOCZ_ARRAY_STREAM(streams_with_film_grain, nb_streams, fmt_ctx->nb_streams);
1719 nb_streams = fmt_ctx->nb_streams;
1720 }
1721
2/2
✓ Branch 0 taken 8811 times.
✓ Branch 1 taken 86 times.
8897 if (selected_streams[pkt->stream_index]) {
1722 8811 AVRational tb = ifile->streams[pkt->stream_index].st->time_base;
1723
2/2
✓ Branch 0 taken 8718 times.
✓ Branch 1 taken 93 times.
8811 int64_t pts = pkt->pts != AV_NOPTS_VALUE ? pkt->pts : pkt->dts;
1724
1725
2/2
✓ Branch 0 taken 8718 times.
✓ Branch 1 taken 93 times.
8811 if (pts != AV_NOPTS_VALUE)
1726 8718 *cur_ts = av_rescale_q(pts, tb, AV_TIME_BASE_Q);
1727
1728
4/4
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 8607 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 92 times.
8811 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
1729 112 start = *cur_ts;
1730 112 has_start = 1;
1731 }
1732
1733
6/6
✓ Branch 0 taken 8719 times.
✓ Branch 1 taken 92 times.
✓ Branch 2 taken 8703 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8702 times.
8811 if (has_start && !has_end && interval->end_is_offset) {
1734 1 end = start + interval->end;
1735 1 has_end = 1;
1736 }
1737
1738
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8808 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
8811 if (interval->end_is_offset && interval->duration_frames) {
1739
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (frame_count >= interval->end)
1740 4 break;
1741
5/6
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 8794 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 11 times.
8808 } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
1742 3 break;
1743 }
1744
1745 8807 frame_count++;
1746
2/2
✓ Branch 0 taken 5866 times.
✓ Branch 1 taken 2941 times.
8807 if (do_read_packets) {
1747
1/2
✓ Branch 0 taken 5866 times.
✗ Branch 1 not taken.
5866 if (do_show_packets)
1748 5866 show_packet(tfc, ifile, pkt, i++);
1749 5866 nb_streams_packets[pkt->stream_index]++;
1750 }
1751
2/2
✓ Branch 0 taken 3208 times.
✓ Branch 1 taken 5599 times.
8807 if (do_read_frames) {
1752 3208 int packet_new = 1;
1753 FrameData *fd;
1754
1755 3208 pkt->opaque_ref = av_buffer_allocz(sizeof(*fd));
1756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3208 times.
3208 if (!pkt->opaque_ref) {
1757 ret = AVERROR(ENOMEM);
1758 goto end;
1759 }
1760 3208 fd = (FrameData*)pkt->opaque_ref->data;
1761 3208 fd->pkt_pos = pkt->pos;
1762 3208 fd->pkt_size = pkt->size;
1763
1764
2/2
✓ Branch 1 taken 3214 times.
✓ Branch 2 taken 3208 times.
6422 while (process_frame(tfc, ifile, frame, pkt, &packet_new) > 0);
1765 }
1766 }
1767 8893 av_packet_unref(pkt);
1768 }
1769 118 av_packet_unref(pkt);
1770 //Flush remaining frames that are cached in the decoder
1771
2/2
✓ Branch 0 taken 163 times.
✓ Branch 1 taken 118 times.
281 for (int i = 0; i < ifile->nb_streams; i++) {
1772 163 pkt->stream_index = i;
1773
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 77 times.
163 if (do_read_frames) {
1774
2/2
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 86 times.
121 while (process_frame(tfc, ifile, frame, pkt, &(int){1}) > 0);
1775 }
1776 }
1777
1778 118 end:
1779 118 av_frame_free(&frame);
1780 118 av_packet_free(&pkt);
1781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118 times.
118 if (ret < 0) {
1782 av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval ");
1783 log_read_interval(interval, NULL, AV_LOG_ERROR);
1784 }
1785 118 return ret;
1786 }
1787
1788 static void flush_buffers(InputFile *ifile)
1789 {
1790 int i;
1791
1792 if (!do_read_frames)
1793 return;
1794 for (i = 0; i < ifile->nb_streams; i++) {
1795 if (ifile->streams[i].dec_ctx)
1796 avcodec_flush_buffers(ifile->streams[i].dec_ctx);
1797 }
1798 }
1799
1800 118 static int read_packets(AVTextFormatContext *tfc, InputFile *ifile)
1801 {
1802 118 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
1803 118 int ret = 0;
1804 118 int64_t cur_ts = fmt_ctx->start_time;
1805
1806
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 4 times.
118 if (read_intervals_nb == 0) {
1807 114 ReadInterval interval = (ReadInterval) { .has_start = 0, .has_end = 0 };
1808 114 ret = read_interval_packets(tfc, ifile, &interval, &cur_ts);
1809 } else {
1810
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (int i = 0; i < read_intervals_nb; i++) {
1811 /* flushing buffers can reset parts of the private context which may be
1812 * read by show_streams(), so only flush between each read_interval */
1813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (i)
1814 flush_buffers(ifile);
1815 4 ret = read_interval_packets(tfc, ifile, &read_intervals[i], &cur_ts);
1816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0)
1817 break;
1818 }
1819 }
1820
1821 118 return ret;
1822 }
1823
1824 291 static void print_dispositions(AVTextFormatContext *tfc, uint32_t disposition, SectionID section_id)
1825 {
1826 291 avtext_print_section_header(tfc, NULL, section_id);
1827
2/2
✓ Branch 0 taken 9312 times.
✓ Branch 1 taken 291 times.
9603 for (unsigned i = 0; i < sizeof(disposition) * CHAR_BIT; i++) {
1828 9312 const char *disposition_str = av_disposition_to_string(1U << i);
1829
1830
2/2
✓ Branch 0 taken 5529 times.
✓ Branch 1 taken 3783 times.
9312 if (disposition_str)
1831 5529 print_int(disposition_str, !!(disposition & (1U << i)));
1832 }
1833 291 avtext_print_section_footer(tfc);
1834 291 }
1835
1836 #define IN_PROGRAM 1
1837 #define IN_STREAM_GROUP 2
1838
1839 399 static int show_stream(AVTextFormatContext *tfc, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int container)
1840 {
1841 399 AVStream *stream = ist->st;
1842 AVCodecParameters *par;
1843 AVCodecContext *dec_ctx;
1844 char val_str[128];
1845 const char *s;
1846 AVRational sar, dar;
1847 AVBPrint pbuf;
1848 const AVCodecDescriptor *cd;
1849 399 const SectionID section_header[] = {
1850 SECTION_ID_STREAM,
1851 SECTION_ID_PROGRAM_STREAM,
1852 SECTION_ID_STREAM_GROUP_STREAM,
1853 };
1854 399 const SectionID section_disposition[] = {
1855 SECTION_ID_STREAM_DISPOSITION,
1856 SECTION_ID_PROGRAM_STREAM_DISPOSITION,
1857 SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION,
1858 };
1859 399 const SectionID section_tags[] = {
1860 SECTION_ID_STREAM_TAGS,
1861 SECTION_ID_PROGRAM_STREAM_TAGS,
1862 SECTION_ID_STREAM_GROUP_STREAM_TAGS,
1863 };
1864 399 int ret = 0;
1865 399 const char *profile = NULL;
1866
1867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 399 times.
399 av_assert0(container < FF_ARRAY_ELEMS(section_header));
1868
1869 399 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
1870
1871 399 avtext_print_section_header(tfc, NULL, section_header[container]);
1872
1873 399 print_int("index", stream->index);
1874
1875 399 par = stream->codecpar;
1876 399 dec_ctx = ist->dec_ctx;
1877
2/2
✓ Branch 1 taken 396 times.
✓ Branch 2 taken 3 times.
399 if (cd = avcodec_descriptor_get(par->codec_id)) {
1878 396 print_str("codec_name", cd->name);
1879
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 384 times.
396 if (!do_bitexact) {
1880
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 print_str("codec_long_name",
1881 cd->long_name ? cd->long_name : "unknown");
1882 }
1883 } else {
1884 3 print_str_opt("codec_name", "unknown");
1885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!do_bitexact) {
1886 print_str_opt("codec_long_name", "unknown");
1887 }
1888 }
1889
1890
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 387 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 1 times.
399 if (!do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
1891 11 print_str("profile", profile);
1892 else {
1893
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 269 times.
388 if (par->profile != AV_PROFILE_UNKNOWN) {
1894 char profile_num[12];
1895 119 snprintf(profile_num, sizeof(profile_num), "%d", par->profile);
1896 119 print_str("profile", profile_num);
1897 } else
1898 269 print_str_opt("profile", "unknown");
1899 }
1900
1901 399 s = av_get_media_type_string(par->codec_type);
1902
1/2
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
399 if (s) print_str ("codec_type", s);
1903 else print_str_opt("codec_type", "unknown");
1904
1905 /* print AVI/FourCC tag */
1906 399 print_str("codec_tag_string", av_fourcc2str(par->codec_tag));
1907 399 print_fmt("codec_tag", "0x%04"PRIx32, par->codec_tag);
1908
1909 399 av_bprint_clear(&pbuf);
1910
2/2
✓ Branch 1 taken 236 times.
✓ Branch 2 taken 163 times.
399 if (!av_mime_codec_str(par, stream->avg_frame_rate, &pbuf))
1911 236 print_str("mime_codec_string", pbuf.str);
1912
1913
4/4
✓ Branch 0 taken 125 times.
✓ Branch 1 taken 260 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 7 times.
399 switch (par->codec_type) {
1914 125 case AVMEDIA_TYPE_VIDEO:
1915 125 print_int("width", par->width);
1916 125 print_int("height", par->height);
1917
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 10 times.
125 if (dec_ctx) {
1918 115 print_int("coded_width", dec_ctx->coded_width);
1919 115 print_int("coded_height", dec_ctx->coded_height);
1920
1921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (do_analyze_frames) {
1922 print_int("closed_captions", streams_with_closed_captions[stream->index]);
1923 print_int("film_grain", streams_with_film_grain[stream->index]);
1924 }
1925 }
1926 125 print_int("has_b_frames", par->video_delay);
1927 125 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
1928
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 49 times.
125 if (sar.num) {
1929 76 print_q("sample_aspect_ratio", sar, ':');
1930 76 av_reduce(&dar.num, &dar.den,
1931 76 (int64_t) par->width * sar.num,
1932 76 (int64_t) par->height * sar.den,
1933 1024*1024);
1934 76 print_q("display_aspect_ratio", dar, ':');
1935 } else {
1936 49 print_str_opt("sample_aspect_ratio", "N/A");
1937 49 print_str_opt("display_aspect_ratio", "N/A");
1938 }
1939 125 print_pixel_format(tfc, par->format);
1940 125 print_int("level", par->level);
1941
1942 125 print_color_range(tfc, par->color_range);
1943 125 print_color_space(tfc, par->color_space);
1944 125 print_color_trc(tfc, par->color_trc);
1945 125 print_primaries(tfc, par->color_primaries);
1946 125 print_chroma_location(tfc, par->chroma_location);
1947
1948
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 93 times.
125 if (par->field_order == AV_FIELD_PROGRESSIVE)
1949 32 print_str("field_order", "progressive");
1950
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 84 times.
93 else if (par->field_order == AV_FIELD_TT)
1951 9 print_str("field_order", "tt");
1952
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 83 times.
84 else if (par->field_order == AV_FIELD_BB)
1953 1 print_str("field_order", "bb");
1954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 else if (par->field_order == AV_FIELD_TB)
1955 print_str("field_order", "tb");
1956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 else if (par->field_order == AV_FIELD_BT)
1957 print_str("field_order", "bt");
1958 else
1959 83 print_str_opt("field_order", "unknown");
1960
1961
4/4
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 91 times.
125 if (dec_ctx && do_read_frames)
1962 24 print_int("refs", dec_ctx->refs);
1963 125 break;
1964
1965 260 case AVMEDIA_TYPE_AUDIO:
1966 260 s = av_get_sample_fmt_name(par->format);
1967
1/2
✓ Branch 0 taken 260 times.
✗ Branch 1 not taken.
260 if (s) print_str ("sample_fmt", s);
1968 else print_str_opt("sample_fmt", "unknown");
1969 260 print_val("sample_rate", par->sample_rate, unit_hertz_str);
1970 260 print_int("channels", par->ch_layout.nb_channels);
1971
1972
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 26 times.
260 if (par->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
1973 234 av_channel_layout_describe(&par->ch_layout, val_str, sizeof(val_str));
1974 234 print_str ("channel_layout", val_str);
1975 } else {
1976 26 print_str_opt("channel_layout", "unknown");
1977 }
1978
1979 260 print_int("bits_per_sample", av_get_bits_per_sample(par->codec_id));
1980
1981 260 print_int("initial_padding", par->initial_padding);
1982 260 break;
1983
1984 7 case AVMEDIA_TYPE_SUBTITLE:
1985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (par->width)
1986 print_int("width", par->width);
1987 else
1988 7 print_str_opt("width", "N/A");
1989
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (par->height)
1990 print_int("height", par->height);
1991 else
1992 7 print_str_opt("height", "N/A");
1993 7 break;
1994 }
1995
1996
2/2
✓ Branch 0 taken 396 times.
✓ Branch 1 taken 3 times.
399 if (show_private_data) {
1997
4/4
✓ Branch 0 taken 377 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 309 times.
✓ Branch 3 taken 68 times.
396 if (dec_ctx && dec_ctx->codec->priv_class)
1998 309 print_private_data(tfc, dec_ctx->priv_data);
1999
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 194 times.
396 if (fmt_ctx->iformat->priv_class)
2000 202 print_private_data(tfc, fmt_ctx->priv_data);
2001 }
2002
2003
2/2
✓ Branch 0 taken 254 times.
✓ Branch 1 taken 145 times.
399 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
2004 145 else print_str_opt("id", "N/A");
2005 399 print_q("r_frame_rate", stream->r_frame_rate, '/');
2006 399 print_q("avg_frame_rate", stream->avg_frame_rate, '/');
2007 399 print_q("time_base", stream->time_base, '/');
2008 399 print_ts ("start_pts", stream->start_time);
2009 399 print_time("start_time", stream->start_time, &stream->time_base);
2010 399 print_ts ("duration_ts", stream->duration);
2011 399 print_time("duration", stream->duration, &stream->time_base);
2012
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 313 times.
399 if (par->bit_rate > 0) print_val ("bit_rate", par->bit_rate, unit_bit_per_second_str);
2013 313 else print_str_opt("bit_rate", "N/A");
2014
3/4
✓ Branch 0 taken 380 times.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 380 times.
399 if (dec_ctx && dec_ctx->rc_max_rate > 0)
2015 print_val ("max_bit_rate", dec_ctx->rc_max_rate, unit_bit_per_second_str);
2016 else
2017 399 print_str_opt("max_bit_rate", "N/A");
2018
4/4
✓ Branch 0 taken 380 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 203 times.
✓ Branch 3 taken 177 times.
399 if (dec_ctx && dec_ctx->bits_per_raw_sample > 0) print_fmt("bits_per_raw_sample", "%d", dec_ctx->bits_per_raw_sample);
2019 196 else print_str_opt("bits_per_raw_sample", "N/A");
2020
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 347 times.
399 if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
2021 347 else print_str_opt("nb_frames", "N/A");
2022
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 363 times.
399 if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
2023 363 else print_str_opt("nb_read_frames", "N/A");
2024
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 310 times.
399 if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
2025 310 else print_str_opt("nb_read_packets", "N/A");
2026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 399 times.
399 if (do_show_data)
2027 avtext_print_data(tfc, "extradata", par->extradata,
2028 par->extradata_size);
2029
2030
2/2
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 131 times.
399 if (par->extradata_size > 0) {
2031 268 print_int("extradata_size", par->extradata_size);
2032 268 avtext_print_data_hash(tfc, "extradata_hash", par->extradata,
2033 par->extradata_size);
2034 }
2035
2036 /* Print disposition information */
2037
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 121 times.
399 if (do_show_stream_disposition) {
2038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 278 times.
278 av_assert0(container < FF_ARRAY_ELEMS(section_disposition));
2039 278 print_dispositions(tfc, stream->disposition, section_disposition[container]);
2040 }
2041
2042
2/2
✓ Branch 0 taken 97 times.
✓ Branch 1 taken 302 times.
399 if (do_show_stream_tags) {
2043
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 97 times.
97 av_assert0(container < FF_ARRAY_ELEMS(section_tags));
2044 97 ret = show_tags(tfc, stream->metadata, section_tags[container]);
2045 }
2046
2047
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 360 times.
399 if (stream->codecpar->nb_coded_side_data) {
2048 39 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_SIDE_DATA_LIST);
2049
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 39 times.
93 for (int i = 0; i < stream->codecpar->nb_coded_side_data; i++) {
2050 54 print_pkt_side_data(tfc, stream->codecpar->width, stream->codecpar->height, &stream->codecpar->coded_side_data[i],
2051 SECTION_ID_STREAM_SIDE_DATA);
2052 54 avtext_print_section_footer(tfc);
2053 }
2054 39 avtext_print_section_footer(tfc);
2055 }
2056
2057 399 avtext_print_section_footer(tfc);
2058 399 av_bprint_finalize(&pbuf, NULL);
2059 399 fflush(stdout);
2060
2061 399 return ret;
2062 }
2063
2064 124 static int show_streams(AVTextFormatContext *tfc, InputFile *ifile)
2065 {
2066 124 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2067 124 int ret = 0;
2068
2069 124 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAMS);
2070
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 124 times.
358 for (int i = 0; i < ifile->nb_streams; i++)
2071
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 10 times.
234 if (selected_streams[i]) {
2072 224 ret = show_stream(tfc, fmt_ctx, i, &ifile->streams[i], 0);
2073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 224 times.
224 if (ret < 0)
2074 break;
2075 }
2076 124 avtext_print_section_footer(tfc);
2077
2078 124 return ret;
2079 }
2080
2081 6 static int show_program(AVTextFormatContext *tfc, InputFile *ifile, AVProgram *program)
2082 {
2083 6 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2084 6 int ret = 0;
2085
2086 6 avtext_print_section_header(tfc, NULL, SECTION_ID_PROGRAM);
2087 6 print_int("program_id", program->id);
2088 6 print_int("program_num", program->program_num);
2089 6 print_int("nb_streams", program->nb_stream_indexes);
2090 6 print_int("pmt_pid", program->pmt_pid);
2091 6 print_int("pcr_pid", program->pcr_pid);
2092
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (do_show_program_tags)
2093 ret = show_tags(tfc, program->metadata, SECTION_ID_PROGRAM_TAGS);
2094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ret < 0)
2095 goto end;
2096
2097 6 avtext_print_section_header(tfc, NULL, SECTION_ID_PROGRAM_STREAMS);
2098
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6 times.
21 for (unsigned i = 0; i < program->nb_stream_indexes; i++) {
2099
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1 times.
15 if (selected_streams[program->stream_index[i]]) {
2100 14 ret = show_stream(tfc, fmt_ctx, program->stream_index[i], &ifile->streams[program->stream_index[i]], IN_PROGRAM);
2101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (ret < 0)
2102 break;
2103 }
2104 }
2105 6 avtext_print_section_footer(tfc);
2106
2107 6 end:
2108 6 avtext_print_section_footer(tfc);
2109 6 return ret;
2110 }
2111
2112 88 static int show_programs(AVTextFormatContext *tfc, InputFile *ifile)
2113 {
2114 88 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2115 88 int ret = 0;
2116
2117 88 avtext_print_section_header(tfc, NULL, SECTION_ID_PROGRAMS);
2118
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 88 times.
94 for (unsigned i = 0; i < fmt_ctx->nb_programs; i++) {
2119 6 AVProgram *program = fmt_ctx->programs[i];
2120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!program)
2121 continue;
2122 6 ret = show_program(tfc, ifile, program);
2123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ret < 0)
2124 break;
2125 }
2126 88 avtext_print_section_footer(tfc);
2127 88 return ret;
2128 }
2129
2130 3 static void print_tile_grid_params(AVTextFormatContext *tfc, const AVStreamGroup *stg,
2131 const AVStreamGroupTileGrid *tile_grid)
2132 {
2133 3 avtext_print_section_header(tfc, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
2134 3 print_int("nb_tiles", tile_grid->nb_tiles);
2135 3 print_int("coded_width", tile_grid->coded_width);
2136 3 print_int("coded_height", tile_grid->coded_height);
2137 3 print_int("horizontal_offset", tile_grid->horizontal_offset);
2138 3 print_int("vertical_offset", tile_grid->vertical_offset);
2139 3 print_int("width", tile_grid->width);
2140 3 print_int("height", tile_grid->height);
2141 3 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
2142
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 for (unsigned i = 0; i < tile_grid->nb_tiles; i++) {
2143 8 avtext_print_section_header(tfc, "tile_offset", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2144 8 print_int("stream_index", tile_grid->offsets[i].idx);
2145 8 print_int("tile_horizontal_offset", tile_grid->offsets[i].horizontal);
2146 8 print_int("tile_vertical_offset", tile_grid->offsets[i].vertical);
2147 8 avtext_print_section_footer(tfc);
2148 }
2149 3 avtext_print_section_footer(tfc);
2150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (tile_grid->nb_coded_side_data) {
2151 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SIDE_DATA_LIST);
2152 for (int i = 0; i < tile_grid->nb_coded_side_data; i++) {
2153 print_pkt_side_data(tfc, tile_grid->width, tile_grid->height, &tile_grid->coded_side_data[i],
2154 SECTION_ID_STREAM_GROUP_SIDE_DATA);
2155 avtext_print_section_footer(tfc);
2156 }
2157 avtext_print_section_footer(tfc);
2158 }
2159 3 avtext_print_section_footer(tfc);
2160 3 }
2161
2162 46 static void print_iamf_param_definition(AVTextFormatContext *tfc, const char *name,
2163 const AVIAMFParamDefinition *param, SectionID section_id)
2164 {
2165 SectionID subsection_id, parameter_section_id;
2166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (section_id == SECTION_ID_FRAME_SIDE_DATA)
2167 subsection_id = SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST;
2168 else {
2169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 av_assert0(sections[section_id].children_ids[0] != -1);
2170 46 subsection_id = sections[section_id].children_ids[0];
2171 }
2172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 av_assert0(sections[subsection_id].children_ids[0] != -1);
2173 46 parameter_section_id = sections[subsection_id].children_ids[0];
2174
2175 // When printing as part of side-data, skip opening a section
2176
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if (section_id != SECTION_ID_FRAME_SIDE_DATA)
2177 46 avtext_print_section_header(tfc, "IAMF Param Definition", section_id);
2178
2179
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if (name)
2180 46 print_str("name", name);
2181 46 print_int("nb_subblocks", param->nb_subblocks);
2182 46 print_int("type", param->type);
2183 46 print_int("parameter_id", param->parameter_id);
2184 46 print_int("parameter_rate", param->parameter_rate);
2185 46 print_int("duration", param->duration);
2186 46 print_int("constant_subblock_duration", param->constant_subblock_duration);
2187
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 37 times.
46 if (param->nb_subblocks > 0)
2188 9 avtext_print_section_header(tfc, NULL, subsection_id);
2189
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 46 times.
55 for (unsigned i = 0; i < param->nb_subblocks; i++) {
2190 9 const void *subblock = av_iamf_param_definition_get_subblock(param, i);
2191
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
9 switch(param->type) {
2192 case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: {
2193 const AVIAMFMixGain *mix = subblock;
2194 avtext_print_section_header(tfc, "IAMF Mix Gain Parameters", parameter_section_id);
2195 print_int("subblock_duration", mix->subblock_duration);
2196 print_int("animation_type", mix->animation_type);
2197 print_q("start_point_value", mix->start_point_value, '/');
2198 print_q("end_point_value", mix->end_point_value, '/');
2199 print_q("control_point_value", mix->control_point_value, '/');
2200 print_q("control_point_relative_time", mix->control_point_relative_time, '/');
2201 avtext_print_section_footer(tfc); // parameter_section_id
2202 break;
2203 }
2204 7 case AV_IAMF_PARAMETER_DEFINITION_DEMIXING: {
2205 7 const AVIAMFDemixingInfo *demix = subblock;
2206 7 avtext_print_section_header(tfc, "IAMF Demixing Info", parameter_section_id);
2207 7 print_int("subblock_duration", demix->subblock_duration);
2208 7 print_int("dmixp_mode", demix->dmixp_mode);
2209 7 avtext_print_section_footer(tfc); // parameter_section_id
2210 7 break;
2211 }
2212 2 case AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN: {
2213 2 const AVIAMFReconGain *recon = subblock;
2214 2 avtext_print_section_header(tfc, "IAMF Recon Gain", parameter_section_id);
2215 2 print_int("subblock_duration", recon->subblock_duration);
2216 2 avtext_print_section_footer(tfc); // parameter_section_id
2217 2 break;
2218 }
2219 }
2220 }
2221
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 37 times.
46 if (param->nb_subblocks > 0)
2222 9 avtext_print_section_footer(tfc); // subsection_id
2223
2224
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if (section_id != SECTION_ID_FRAME_SIDE_DATA)
2225 46 avtext_print_section_footer(tfc); // section_id
2226 46 }
2227
2228 17 static void print_iamf_audio_element_params(AVTextFormatContext *tfc, const AVStreamGroup *stg,
2229 const AVIAMFAudioElement *audio_element)
2230 {
2231 AVBPrint pbuf;
2232
2233 17 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2234
2235 17 avtext_print_section_header(tfc, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
2236 17 print_int("nb_layers", audio_element->nb_layers);
2237 17 print_int("audio_element_type", audio_element->audio_element_type);
2238 17 print_int("default_w", audio_element->default_w);
2239 17 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
2240
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 17 times.
51 for (unsigned i = 0; i < audio_element->nb_layers; i++) {
2241 34 const AVIAMFLayer *layer = audio_element->layers[i];
2242 char val_str[128];
2243 34 avtext_print_section_header(tfc, "IAMF Audio Layer", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2244 34 av_channel_layout_describe(&layer->ch_layout, val_str, sizeof(val_str));
2245 34 print_str("channel_layout", val_str);
2246
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 5 times.
34 if (audio_element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_CHANNEL) {
2247 29 print_int("output_gain_flags", layer->output_gain_flags);
2248 29 print_q("output_gain", layer->output_gain, '/');
2249
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 } else if (audio_element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE) {
2250 5 print_int("ambisonics_mode", layer->ambisonics_mode);
2251
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 if (layer->ambisonics_mode == AV_IAMF_AMBISONICS_MODE_PROJECTION)
2252
7/8
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 48 times.
✓ Branch 8 taken 48 times.
✓ Branch 9 taken 48 times.
✓ Branch 10 taken 3 times.
99 print_list_fmt("demixing_matrix", "%d/%d", layer->nb_demixing_matrix, 1, layer->demixing_matrix[idx].num,
2253 layer->demixing_matrix[idx].den);
2254 }
2255 34 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
2256 }
2257
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 10 times.
17 if (audio_element->demixing_info)
2258 7 print_iamf_param_definition(tfc, "demixing_info", audio_element->demixing_info,
2259 SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2260
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 15 times.
17 if (audio_element->recon_gain_info)
2261 2 print_iamf_param_definition(tfc, "recon_gain_info", audio_element->recon_gain_info,
2262 SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2263 17 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENTS
2264 17 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_COMPONENT
2265
2266 17 av_bprint_finalize(&pbuf, NULL);
2267 17 }
2268
2269 18 static void print_iamf_submix_params(AVTextFormatContext *tfc, const AVIAMFSubmix *submix)
2270 {
2271 18 avtext_print_section_header(tfc, "IAMF Submix", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2272 18 print_int("nb_elements", submix->nb_elements);
2273 18 print_int("nb_layouts", submix->nb_layouts);
2274 18 print_q("default_mix_gain", submix->default_mix_gain, '/');
2275 18 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_PIECES);
2276
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 18 times.
37 for (unsigned i = 0; i < submix->nb_elements; i++) {
2277 19 const AVIAMFSubmixElement *element = submix->elements[i];
2278 19 avtext_print_section_header(tfc, "IAMF Submix Element", SECTION_ID_STREAM_GROUP_PIECE);
2279 19 print_int("stream_id", element->audio_element_id);
2280 19 print_q("default_mix_gain", element->default_mix_gain, '/');
2281 19 print_int("headphones_rendering_mode", element->headphones_rendering_mode);
2282 19 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SUBPIECES);
2283
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 if (element->annotations) {
2284 19 const AVDictionaryEntry *annotation = NULL;
2285 19 avtext_print_section_header(tfc, "IAMF Annotations", SECTION_ID_STREAM_GROUP_SUBPIECE);
2286
2/2
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 19 times.
38 while (annotation = av_dict_iterate(element->annotations, annotation))
2287 19 print_str(annotation->key, annotation->value);
2288 19 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBPIECE
2289 }
2290
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 if (element->element_mix_config)
2291 19 print_iamf_param_definition(tfc, "element_mix_config", element->element_mix_config,
2292 SECTION_ID_STREAM_GROUP_SUBPIECE);
2293 19 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBPIECES
2294 19 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_PIECE
2295 }
2296
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (submix->output_mix_config)
2297 18 print_iamf_param_definition(tfc, "output_mix_config", submix->output_mix_config,
2298 SECTION_ID_STREAM_GROUP_PIECE);
2299
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for (unsigned i = 0; i < submix->nb_layouts; i++) {
2300 36 const AVIAMFSubmixLayout *layout = submix->layouts[i];
2301 char val_str[128];
2302 36 avtext_print_section_header(tfc, "IAMF Submix Layout", SECTION_ID_STREAM_GROUP_PIECE);
2303 36 av_channel_layout_describe(&layout->sound_system, val_str, sizeof(val_str));
2304 36 print_str("sound_system", val_str);
2305 36 print_q("integrated_loudness", layout->integrated_loudness, '/');
2306 36 print_q("digital_peak", layout->digital_peak, '/');
2307 36 print_q("true_peak", layout->true_peak, '/');
2308 36 print_q("dialogue_anchored_loudness", layout->dialogue_anchored_loudness, '/');
2309 36 print_q("album_anchored_loudness", layout->album_anchored_loudness, '/');
2310 36 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_PIECE
2311 }
2312 18 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_PIECES
2313 18 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
2314 18 }
2315
2316 16 static void print_iamf_mix_presentation_params(AVTextFormatContext *tfc, const AVStreamGroup *stg,
2317 const AVIAMFMixPresentation *mix_presentation)
2318 {
2319 16 avtext_print_section_header(tfc, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
2320 16 print_int("nb_submixes", mix_presentation->nb_submixes);
2321 16 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
2322
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (mix_presentation->annotations) {
2323 16 const AVDictionaryEntry *annotation = NULL;
2324 16 avtext_print_section_header(tfc, "IAMF Annotations", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2325
2/2
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 16 times.
32 while (annotation = av_dict_iterate(mix_presentation->annotations, annotation))
2326 16 print_str(annotation->key, annotation->value);
2327 16 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
2328 }
2329
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 16 times.
34 for (unsigned i = 0; i < mix_presentation->nb_submixes; i++)
2330 18 print_iamf_submix_params(tfc, mix_presentation->submixes[i]);
2331 16 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENTS
2332 16 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_COMPONENT
2333 16 }
2334
2335 36 static void print_stream_group_params(AVTextFormatContext *tfc, AVStreamGroup *stg)
2336 {
2337 36 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_COMPONENTS);
2338
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 33 times.
36 if (stg->type == AV_STREAM_GROUP_PARAMS_TILE_GRID)
2339 3 print_tile_grid_params(tfc, stg, stg->params.tile_grid);
2340
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 16 times.
33 else if (stg->type == AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT)
2341 17 print_iamf_audio_element_params(tfc, stg, stg->params.iamf_audio_element);
2342
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 else if (stg->type == AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION)
2343 16 print_iamf_mix_presentation_params(tfc, stg, stg->params.iamf_mix_presentation);
2344 36 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_COMPONENTS
2345 36 }
2346
2347 39 static int show_stream_group(AVTextFormatContext *tfc, InputFile *ifile, AVStreamGroup *stg)
2348 {
2349 39 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2350 AVBPrint pbuf;
2351 39 int ret = 0;
2352
2353 39 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2354 39 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP);
2355 39 print_int("index", stg->index);
2356
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%"PRIx64, stg->id);
2357 else print_str_opt("id", "N/A");
2358 39 print_int("nb_streams", stg->nb_streams);
2359
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 if (stg->type != AV_STREAM_GROUP_PARAMS_NONE)
2360 39 print_str("type", av_x_if_null(avformat_stream_group_name(stg->type), "unknown"));
2361 else
2362 print_str_opt("type", "unknown");
2363
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 3 times.
39 if (do_show_stream_group_components)
2364 36 print_stream_group_params(tfc, stg);
2365
2366 /* Print disposition information */
2367
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 26 times.
39 if (do_show_stream_group_disposition)
2368 13 print_dispositions(tfc, stg->disposition, SECTION_ID_STREAM_GROUP_DISPOSITION);
2369
2370
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 26 times.
39 if (do_show_stream_group_tags)
2371 13 ret = show_tags(tfc, stg->metadata, SECTION_ID_STREAM_GROUP_TAGS);
2372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 if (ret < 0)
2373 goto end;
2374
2375 39 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_STREAMS);
2376
2/2
✓ Branch 0 taken 161 times.
✓ Branch 1 taken 39 times.
200 for (unsigned i = 0; i < stg->nb_streams; i++) {
2377
1/2
✓ Branch 0 taken 161 times.
✗ Branch 1 not taken.
161 if (selected_streams[stg->streams[i]->index]) {
2378 161 ret = show_stream(tfc, fmt_ctx, stg->streams[i]->index, &ifile->streams[stg->streams[i]->index], IN_STREAM_GROUP);
2379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 161 times.
161 if (ret < 0)
2380 break;
2381 }
2382 }
2383 39 avtext_print_section_footer(tfc);
2384
2385 39 end:
2386 39 av_bprint_finalize(&pbuf, NULL);
2387 39 avtext_print_section_footer(tfc);
2388 39 return ret;
2389 }
2390
2391 106 static int show_stream_groups(AVTextFormatContext *tfc, InputFile *ifile)
2392 {
2393 106 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2394 106 int ret = 0;
2395
2396 106 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUPS);
2397
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 106 times.
145 for (unsigned i = 0; i < fmt_ctx->nb_stream_groups; i++) {
2398 39 AVStreamGroup *stg = fmt_ctx->stream_groups[i];
2399
2400 39 ret = show_stream_group(tfc, ifile, stg);
2401
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 if (ret < 0)
2402 break;
2403 }
2404 106 avtext_print_section_footer(tfc);
2405 106 return ret;
2406 }
2407
2408 5 static int show_chapters(AVTextFormatContext *tfc, InputFile *ifile)
2409 {
2410 5 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2411 5 int ret = 0;
2412
2413 5 avtext_print_section_header(tfc, NULL, SECTION_ID_CHAPTERS);
2414
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 5 times.
27 for (unsigned i = 0; i < fmt_ctx->nb_chapters; i++) {
2415 22 AVChapter *chapter = fmt_ctx->chapters[i];
2416
2417 22 avtext_print_section_header(tfc, NULL, SECTION_ID_CHAPTER);
2418 22 print_int("id", chapter->id);
2419 22 print_q ("time_base", chapter->time_base, '/');
2420 22 print_int("start", chapter->start);
2421 22 print_time("start_time", chapter->start, &chapter->time_base);
2422 22 print_int("end", chapter->end);
2423 22 print_time("end_time", chapter->end, &chapter->time_base);
2424
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (do_show_chapter_tags)
2425 22 ret = show_tags(tfc, chapter->metadata, SECTION_ID_CHAPTER_TAGS);
2426 22 avtext_print_section_footer(tfc);
2427 }
2428 5 avtext_print_section_footer(tfc);
2429
2430 5 return ret;
2431 }
2432
2433 43 static int show_format(AVTextFormatContext *tfc, InputFile *ifile)
2434 {
2435 43 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2436
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
2437 43 int ret = 0;
2438
2439 43 avtext_print_section_header(tfc, NULL, SECTION_ID_FORMAT);
2440 43 print_str_validate("filename", fmt_ctx->url);
2441 43 print_int("nb_streams", fmt_ctx->nb_streams);
2442 43 print_int("nb_programs", fmt_ctx->nb_programs);
2443 43 print_int("nb_stream_groups", fmt_ctx->nb_stream_groups);
2444 43 print_str("format_name", fmt_ctx->iformat->name);
2445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (!do_bitexact) {
2446 if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
2447 else print_str_opt("format_long_name", "unknown");
2448 }
2449 43 print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
2450 43 print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
2451
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 if (size >= 0) print_val ("size", size, unit_byte_str);
2452 else print_str_opt("size", "N/A");
2453
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 1 times.
43 if (fmt_ctx->bit_rate > 0) print_val ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
2454 1 else print_str_opt("bit_rate", "N/A");
2455 43 print_int("probe_score", fmt_ctx->probe_score);
2456
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 8 times.
43 if (do_show_format_tags)
2457 35 ret = show_tags(tfc, fmt_ctx->metadata, SECTION_ID_FORMAT_TAGS);
2458
2459 43 avtext_print_section_footer(tfc);
2460 43 fflush(stdout);
2461 43 return ret;
2462 }
2463
2464 static void show_error(AVTextFormatContext *tfc, int err)
2465 {
2466 avtext_print_section_header(tfc, NULL, SECTION_ID_ERROR);
2467 print_int("code", err);
2468 print_str("string", av_err2str(err));
2469 avtext_print_section_footer(tfc);
2470 }
2471
2472 824 static int get_decoder_by_name(const char *codec_name, const AVCodec **codec)
2473 {
2474
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if (codec_name == NULL)
2475 824 return 0;
2476
2477 *codec = avcodec_find_decoder_by_name(codec_name);
2478 if (*codec == NULL) {
2479 av_log(NULL, AV_LOG_ERROR,
2480 "No codec could be found with name '%s'\n", codec_name);
2481 return AVERROR(EINVAL);
2482 }
2483 return 0;
2484 }
2485
2486 206 static int set_decoders(AVFormatContext *fmt_ctx)
2487 {
2488 int ret;
2489
2490 #define GET_DECODER(type_) \
2491 ret = get_decoder_by_name(type_##_codec_name, &fmt_ctx->type_##_codec); \
2492 if (ret < 0) return ret;
2493
2494
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 GET_DECODER(audio);
2495
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 GET_DECODER(data);
2496
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 GET_DECODER(subtitle);
2497
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 GET_DECODER(video);
2498 206 return 0;
2499 }
2500
2501 391 static const AVCodec *get_decoder_for_stream(AVFormatContext *fmt_ctx, AVStream *stream)
2502 {
2503 391 const AVCodec *codec = NULL;
2504
5/5
✓ Branch 0 taken 167 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 2 times.
391 switch (stream->codecpar->codec_type) {
2505 167 case AVMEDIA_TYPE_VIDEO: codec = fmt_ctx->video_codec; break;
2506 200 case AVMEDIA_TYPE_AUDIO: codec = fmt_ctx->audio_codec; break;
2507 9 case AVMEDIA_TYPE_SUBTITLE: codec = fmt_ctx->subtitle_codec; break;
2508 13 case AVMEDIA_TYPE_DATA: codec = fmt_ctx->data_codec; break;
2509 }
2510
2511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 391 times.
391 if (codec != NULL)
2512 return codec;
2513
2514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 391 times.
391 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
2515 av_log(NULL, AV_LOG_WARNING,
2516 "Failed to probe codec for input stream %d\n", stream->index);
2517 return NULL;
2518 }
2519
2520 391 codec = avcodec_find_decoder(stream->codecpar->codec_id);
2521
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 368 times.
391 if (codec == NULL) {
2522 23 av_log(NULL, AV_LOG_WARNING,
2523 "Unsupported codec with id %d for input stream %d\n",
2524 23 stream->codecpar->codec_id, stream->index);
2525 23 return NULL;
2526 }
2527
2528 368 return codec;
2529 }
2530
2531 206 static int open_input_file(InputFile *ifile, const char *filename,
2532 const char *print_filename)
2533 {
2534 int err;
2535 206 AVFormatContext *fmt_ctx = NULL;
2536 206 const AVDictionaryEntry *t = NULL;
2537 206 int scan_all_pmts_set = 0;
2538
2539 206 fmt_ctx = avformat_alloc_context();
2540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (!fmt_ctx)
2541 return AVERROR(ENOMEM);
2542
2543 206 err = set_decoders(fmt_ctx);
2544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (err < 0)
2545 return err;
2546
1/2
✓ Branch 1 taken 206 times.
✗ Branch 2 not taken.
206 if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2547 206 av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
2548 206 scan_all_pmts_set = 1;
2549 }
2550
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 if ((err = avformat_open_input(&fmt_ctx, filename,
2551 iformat, &format_opts)) < 0) {
2552 print_error(filename, err);
2553 return err;
2554 }
2555
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 190 times.
206 if (print_filename) {
2556 16 av_freep(&fmt_ctx->url);
2557 16 fmt_ctx->url = av_strdup(print_filename);
2558 }
2559 206 ifile->fmt_ctx = fmt_ctx;
2560
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if (scan_all_pmts_set)
2561 206 av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2562
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 while ((t = av_dict_iterate(format_opts, t)))
2563 av_log(NULL, AV_LOG_WARNING, "Option %s skipped - not known to demuxer.\n", t->key);
2564
2565
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if (find_stream_info) {
2566 AVDictionary **opts;
2567 206 int orig_nb_streams = fmt_ctx->nb_streams;
2568
2569 206 err = setup_find_stream_info_opts(fmt_ctx, codec_opts, &opts);
2570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (err < 0)
2571 return err;
2572
2573 206 err = avformat_find_stream_info(fmt_ctx, opts);
2574
2575
2/2
✓ Branch 0 taken 369 times.
✓ Branch 1 taken 206 times.
575 for (int i = 0; i < orig_nb_streams; i++)
2576 369 av_dict_free(&opts[i]);
2577 206 av_freep(&opts);
2578
2579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (err < 0) {
2580 print_error(filename, err);
2581 return err;
2582 }
2583 }
2584
2585 206 av_dump_format(fmt_ctx, 0, filename, 0);
2586
2587 206 ifile->streams = av_calloc(fmt_ctx->nb_streams, sizeof(*ifile->streams));
2588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (!ifile->streams)
2589 exit(1);
2590 206 ifile->nb_streams = fmt_ctx->nb_streams;
2591
2592 /* bind a decoder to each input stream */
2593
2/2
✓ Branch 0 taken 391 times.
✓ Branch 1 taken 206 times.
597 for (unsigned i = 0; i < fmt_ctx->nb_streams; i++) {
2594 391 InputStream *ist = &ifile->streams[i];
2595 391 AVStream *stream = fmt_ctx->streams[i];
2596 const AVCodec *codec;
2597
2598 391 ist->st = stream;
2599
2600 391 codec = get_decoder_for_stream(fmt_ctx, stream);
2601
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 368 times.
391 if (!codec)
2602 23 continue;
2603
2604 {
2605 AVDictionary *opts;
2606
2607 368 err = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
2608 fmt_ctx, stream, codec, &opts, NULL);
2609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 368 times.
368 if (err < 0)
2610 exit(1);
2611
2612 368 ist->dec_ctx = avcodec_alloc_context3(codec);
2613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 368 times.
368 if (!ist->dec_ctx)
2614 exit(1);
2615
2616 368 err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
2617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 368 times.
368 if (err < 0)
2618 exit(1);
2619
2620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 368 times.
368 if (do_show_log) {
2621 // For logging it is needed to disable at least frame threads as otherwise
2622 // the log information would need to be reordered and matches up to contexts and frames
2623 // That is in fact possible but not trivial
2624 av_dict_set(&codec_opts, "threads", "1", 0);
2625 }
2626
2627 368 av_dict_set(&opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
2628
2629 368 ist->dec_ctx->pkt_timebase = stream->time_base;
2630
2631
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 368 times.
368 if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) {
2632 av_log(NULL, AV_LOG_WARNING, "Could not open codec for input stream %d\n",
2633 stream->index);
2634 exit(1);
2635 }
2636
2637
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 368 times.
368 if ((t = av_dict_iterate(opts, NULL))) {
2638 av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
2639 t->key, stream->index);
2640 return AVERROR_OPTION_NOT_FOUND;
2641 }
2642 }
2643 }
2644
2645 206 ifile->fmt_ctx = fmt_ctx;
2646 206 return 0;
2647 }
2648
2649 206 static void close_input_file(InputFile *ifile)
2650 {
2651
2652 /* close decoder for each stream */
2653
2/2
✓ Branch 0 taken 391 times.
✓ Branch 1 taken 206 times.
597 for (int i = 0; i < ifile->nb_streams; i++)
2654 391 avcodec_free_context(&ifile->streams[i].dec_ctx);
2655
2656 206 av_freep(&ifile->streams);
2657 206 ifile->nb_streams = 0;
2658
2659 206 avformat_close_input(&ifile->fmt_ctx);
2660 206 }
2661
2662 206 static int probe_file(AVTextFormatContext *tfc, const char *filename,
2663 const char *print_filename)
2664 {
2665 206 InputFile ifile = { 0 };
2666 int ret;
2667 int section_id;
2668
2669
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
206 do_analyze_frames = do_analyze_frames && do_show_streams;
2670
4/6
✓ Branch 0 taken 148 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 148 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 148 times.
206 do_read_frames = do_show_frames || do_count_frames || do_analyze_frames;
2671
3/4
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 71 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 135 times.
206 do_read_packets = do_show_packets || do_count_packets;
2672
2673 206 ret = open_input_file(&ifile, filename, print_filename);
2674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (ret < 0)
2675 goto end;
2676
2677 #define CHECK_END if (ret < 0) goto end
2678
2679 206 nb_streams = ifile.fmt_ctx->nb_streams;
2680
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);
2681
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);
2682
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams);
2683
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 REALLOCZ_ARRAY_STREAM(streams_with_closed_captions,0,ifile.fmt_ctx->nb_streams);
2684
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 REALLOCZ_ARRAY_STREAM(streams_with_film_grain,0,ifile.fmt_ctx->nb_streams);
2685
2686
2/2
✓ Branch 0 taken 391 times.
✓ Branch 1 taken 206 times.
597 for (unsigned i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
2687
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 340 times.
391 if (stream_specifier) {
2688 51 ret = avformat_match_stream_specifier(ifile.fmt_ctx,
2689 51 ifile.fmt_ctx->streams[i],
2690 stream_specifier);
2691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 CHECK_END;
2692 else
2693 51 selected_streams[i] = ret;
2694 51 ret = 0;
2695 } else {
2696 340 selected_streams[i] = 1;
2697 }
2698
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 372 times.
391 if (!selected_streams[i])
2699 19 ifile.fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
2700 }
2701
2702
4/4
✓ Branch 0 taken 148 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 88 times.
206 if (do_read_frames || do_read_packets) {
2703
4/4
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 47 times.
118 if (do_show_frames && do_show_packets &&
2704
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
11 tfc->formatter->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT)
2705 5 section_id = SECTION_ID_PACKETS_AND_FRAMES;
2706
4/4
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 6 times.
113 else if (do_show_packets && !do_show_frames)
2707 60 section_id = SECTION_ID_PACKETS;
2708 else // (!do_show_packets && do_show_frames)
2709 53 section_id = SECTION_ID_FRAMES;
2710
3/4
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
118 if (do_show_frames || do_show_packets)
2711 118 avtext_print_section_header(tfc, NULL, section_id);
2712 118 ret = read_packets(tfc, &ifile);
2713
3/4
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
118 if (do_show_frames || do_show_packets)
2714 118 avtext_print_section_footer(tfc);
2715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118 times.
118 CHECK_END;
2716 }
2717
2718
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 118 times.
206 if (do_show_programs) {
2719 88 ret = show_programs(tfc, &ifile);
2720
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
88 CHECK_END;
2721 }
2722
2723
2/2
✓ Branch 0 taken 106 times.
✓ Branch 1 taken 100 times.
206 if (do_show_stream_groups) {
2724 106 ret = show_stream_groups(tfc, &ifile);
2725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 CHECK_END;
2726 }
2727
2728
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 82 times.
206 if (do_show_streams) {
2729 124 ret = show_streams(tfc, &ifile);
2730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 124 times.
124 CHECK_END;
2731 }
2732
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 201 times.
206 if (do_show_chapters) {
2733 5 ret = show_chapters(tfc, &ifile);
2734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 CHECK_END;
2735 }
2736
2/2
✓ Branch 0 taken 163 times.
✓ Branch 1 taken 43 times.
206 if (do_show_format) {
2737 43 ret = show_format(tfc, &ifile);
2738
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 CHECK_END;
2739 }
2740
2741 206 end:
2742
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if (ifile.fmt_ctx)
2743 206 close_input_file(&ifile);
2744 206 av_freep(&nb_streams_frames);
2745 206 av_freep(&nb_streams_packets);
2746 206 av_freep(&selected_streams);
2747 206 av_freep(&streams_with_closed_captions);
2748 206 av_freep(&streams_with_film_grain);
2749 206 av_freep(&audio_codec_name);
2750 206 av_freep(&data_codec_name);
2751 206 av_freep(&subtitle_codec_name);
2752 206 av_freep(&video_codec_name);
2753
2754 206 return ret;
2755 }
2756
2757 static void show_usage(void)
2758 {
2759 av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
2760 av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] INPUT_FILE\n", program_name);
2761 av_log(NULL, AV_LOG_INFO, "\n");
2762 }
2763
2764 static void ffprobe_show_program_version(AVTextFormatContext *tfc)
2765 {
2766 AVBPrint pbuf;
2767 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2768
2769 avtext_print_section_header(tfc, NULL, SECTION_ID_PROGRAM_VERSION);
2770 print_str("version", FFMPEG_VERSION);
2771 print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
2772 program_birth_year, CONFIG_THIS_YEAR);
2773 print_str("compiler_ident", CC_IDENT);
2774 print_str("configuration", FFMPEG_CONFIGURATION);
2775 avtext_print_section_footer(tfc);
2776
2777 av_bprint_finalize(&pbuf, NULL);
2778 }
2779
2780 #define SHOW_LIB_VERSION(libname, LIBNAME) \
2781 do { \
2782 if (CONFIG_##LIBNAME) { \
2783 unsigned int version = libname##_version(); \
2784 avtext_print_section_header(tfc, NULL, SECTION_ID_LIBRARY_VERSION); \
2785 print_str("name", "lib" #libname); \
2786 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
2787 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
2788 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
2789 print_int("version", version); \
2790 print_str("ident", LIB##LIBNAME##_IDENT); \
2791 avtext_print_section_footer(tfc); \
2792 } \
2793 } while (0)
2794
2795 static void ffprobe_show_library_versions(AVTextFormatContext *tfc)
2796 {
2797 avtext_print_section_header(tfc, NULL, SECTION_ID_LIBRARY_VERSIONS);
2798 SHOW_LIB_VERSION(avutil, AVUTIL);
2799 SHOW_LIB_VERSION(avcodec, AVCODEC);
2800 SHOW_LIB_VERSION(avformat, AVFORMAT);
2801 SHOW_LIB_VERSION(avdevice, AVDEVICE);
2802 SHOW_LIB_VERSION(avfilter, AVFILTER);
2803 SHOW_LIB_VERSION(swscale, SWSCALE);
2804 SHOW_LIB_VERSION(swresample, SWRESAMPLE);
2805 avtext_print_section_footer(tfc);
2806 }
2807
2808 #define PRINT_PIX_FMT_FLAG(flagname, name) \
2809 do { \
2810 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
2811 } while (0)
2812
2813 static void ffprobe_show_pixel_formats(AVTextFormatContext *tfc)
2814 {
2815 const AVPixFmtDescriptor *pixdesc = NULL;
2816 int i, n;
2817
2818 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMATS);
2819 while (pixdesc = av_pix_fmt_desc_next(pixdesc)) {
2820 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMAT);
2821 print_str("name", pixdesc->name);
2822 print_int("nb_components", pixdesc->nb_components);
2823 if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
2824 print_int ("log2_chroma_w", pixdesc->log2_chroma_w);
2825 print_int ("log2_chroma_h", pixdesc->log2_chroma_h);
2826 } else {
2827 print_str_opt("log2_chroma_w", "N/A");
2828 print_str_opt("log2_chroma_h", "N/A");
2829 }
2830 n = av_get_bits_per_pixel(pixdesc);
2831 if (n) print_int ("bits_per_pixel", n);
2832 else print_str_opt("bits_per_pixel", "N/A");
2833 if (do_show_pixel_format_flags) {
2834 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMAT_FLAGS);
2835 PRINT_PIX_FMT_FLAG(BE, "big_endian");
2836 PRINT_PIX_FMT_FLAG(PAL, "palette");
2837 PRINT_PIX_FMT_FLAG(BITSTREAM, "bitstream");
2838 PRINT_PIX_FMT_FLAG(HWACCEL, "hwaccel");
2839 PRINT_PIX_FMT_FLAG(PLANAR, "planar");
2840 PRINT_PIX_FMT_FLAG(RGB, "rgb");
2841 PRINT_PIX_FMT_FLAG(ALPHA, "alpha");
2842 avtext_print_section_footer(tfc);
2843 }
2844 if (do_show_pixel_format_components && (pixdesc->nb_components > 0)) {
2845 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMAT_COMPONENTS);
2846 for (i = 0; i < pixdesc->nb_components; i++) {
2847 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMAT_COMPONENT);
2848 print_int("index", i + 1);
2849 print_int("bit_depth", pixdesc->comp[i].depth);
2850 avtext_print_section_footer(tfc);
2851 }
2852 avtext_print_section_footer(tfc);
2853 }
2854 avtext_print_section_footer(tfc);
2855 }
2856 avtext_print_section_footer(tfc);
2857 }
2858
2859 static int opt_show_optional_fields(void *optctx, const char *opt, const char *arg)
2860 {
2861 if (!av_strcasecmp(arg, "always")) show_optional_fields = SHOW_OPTIONAL_FIELDS_ALWAYS;
2862 else if (!av_strcasecmp(arg, "never")) show_optional_fields = SHOW_OPTIONAL_FIELDS_NEVER;
2863 else if (!av_strcasecmp(arg, "auto")) show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO;
2864
2865 if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto")) {
2866 double num;
2867 int ret = parse_number("show_optional_fields", arg, OPT_TYPE_INT,
2868 SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS, &num);
2869 if (ret < 0)
2870 return ret;
2871 show_optional_fields = num;
2872 }
2873 return 0;
2874 }
2875
2876 15 static int opt_format(void *optctx, const char *opt, const char *arg)
2877 {
2878 15 iformat = av_find_input_format(arg);
2879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (!iformat) {
2880 av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
2881 return AVERROR(EINVAL);
2882 }
2883 15 return 0;
2884 }
2885
2886 1728 static inline void mark_section_show_entries(SectionID section_id,
2887 int show_all_entries, AVDictionary *entries)
2888 {
2889 1728 EntrySelection *selection = &selected_entries[section_id];
2890
2891 1728 selection->show_all_entries = show_all_entries;
2892
2/2
✓ Branch 0 taken 1352 times.
✓ Branch 1 taken 376 times.
1728 if (show_all_entries) {
2893 1352 const AVTextFormatSection *section = &sections[section_id];
2894
2/2
✓ Branch 0 taken 1056 times.
✓ Branch 1 taken 1352 times.
2408 for (const int *id = section->children_ids; *id != -1; id++)
2895 1056 mark_section_show_entries(*id, show_all_entries, entries);
2896 } else {
2897 376 av_dict_copy(&selection->entries_to_show, entries, 0);
2898 }
2899 1728 }
2900
2901 380 static int match_section(const char *section_name,
2902 int show_all_entries, AVDictionary *entries)
2903 {
2904 380 int ret = 0;
2905
2906
2/2
✓ Branch 0 taken 25840 times.
✓ Branch 1 taken 380 times.
26220 for (unsigned i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
2907 25840 const struct AVTextFormatSection *section = &sections[i];
2908
2/2
✓ Branch 0 taken 25471 times.
✓ Branch 1 taken 369 times.
25840 if (!strcmp(section_name, section->name) ||
2909
4/4
✓ Branch 0 taken 13120 times.
✓ Branch 1 taken 12351 times.
✓ Branch 2 taken 190 times.
✓ Branch 3 taken 12930 times.
25471 (section->unique_name && !strcmp(section_name, section->unique_name))) {
2910 559 av_log(NULL, AV_LOG_DEBUG,
2911 "'%s' matches section with unique name '%s'\n", section_name,
2912 559 (char *)av_x_if_null(section->unique_name, section->name));
2913 559 ret++;
2914 559 mark_section_show_entries(section->id, show_all_entries, entries);
2915 }
2916 }
2917 380 return ret;
2918 }
2919
2920 158 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
2921 {
2922 158 const char *p = arg;
2923 158 int ret = 0;
2924
2925
2/2
✓ Branch 0 taken 380 times.
✓ Branch 1 taken 158 times.
538 while (*p) {
2926 380 AVDictionary *entries = NULL;
2927 380 char *section_name = av_get_token(&p, "=:");
2928 380 int show_all_entries = 0;
2929
2930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 380 times.
380 if (!section_name) {
2931 av_log(NULL, AV_LOG_ERROR,
2932 "Missing section name for option '%s'\n", opt);
2933 return AVERROR(EINVAL);
2934 }
2935
2936
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 170 times.
380 if (*p == '=') {
2937 210 p++;
2938
4/4
✓ Branch 0 taken 628 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 478 times.
✓ Branch 3 taken 150 times.
898 while (*p && *p != ':') {
2939 478 char *entry = av_get_token(&p, ",:");
2940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 478 times.
478 if (!entry)
2941 break;
2942 478 av_log(NULL, AV_LOG_VERBOSE,
2943 "Adding '%s' to the entries to show in section '%s'\n",
2944 entry, section_name);
2945 478 av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
2946
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 268 times.
478 if (*p == ',')
2947 268 p++;
2948 }
2949 } else {
2950 170 show_all_entries = 1;
2951 }
2952
2953 380 ret = match_section(section_name, show_all_entries, entries);
2954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 380 times.
380 if (ret == 0) {
2955 av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
2956 ret = AVERROR(EINVAL);
2957 }
2958 380 av_dict_free(&entries);
2959 380 av_free(section_name);
2960
2961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 380 times.
380 if (ret <= 0)
2962 break;
2963
2/2
✓ Branch 0 taken 222 times.
✓ Branch 1 taken 158 times.
380 if (*p)
2964 222 p++;
2965 }
2966
2967 158 return ret;
2968 }
2969
2970 206 static int opt_input_file(void *optctx, const char *arg)
2971 {
2972
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (input_filename) {
2973 av_log(NULL, AV_LOG_ERROR,
2974 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
2975 arg, input_filename);
2976 return AVERROR(EINVAL);
2977 }
2978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (!strcmp(arg, "-"))
2979 arg = "fd:";
2980 206 input_filename = av_strdup(arg);
2981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (!input_filename)
2982 return AVERROR(ENOMEM);
2983
2984 206 return 0;
2985 }
2986
2987 10 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
2988 {
2989 10 opt_input_file(optctx, arg);
2990 10 return 0;
2991 }
2992
2993 static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
2994 {
2995 if (output_filename) {
2996 av_log(NULL, AV_LOG_ERROR,
2997 "Argument '%s' provided as output filename, but '%s' was already specified.\n",
2998 arg, output_filename);
2999 return AVERROR(EINVAL);
3000 }
3001 if (!strcmp(arg, "-"))
3002 arg = "fd:";
3003 output_filename = av_strdup(arg);
3004 if (!output_filename)
3005 return AVERROR(ENOMEM);
3006
3007 return 0;
3008 }
3009
3010 16 static int opt_print_filename(void *optctx, const char *opt, const char *arg)
3011 {
3012 16 av_freep(&print_input_filename);
3013 16 print_input_filename = av_strdup(arg);
3014
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 return print_input_filename ? 0 : AVERROR(ENOMEM);
3015 }
3016
3017 void show_help_default(const char *opt, const char *arg)
3018 {
3019 av_log_set_callback(log_callback_help);
3020 show_usage();
3021 show_help_options(options, "Main options:", 0, 0);
3022 printf("\n");
3023
3024 show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
3025 show_help_children(avcodec_get_class(), AV_OPT_FLAG_DECODING_PARAM);
3026 }
3027
3028 /**
3029 * Parse interval specification, according to the format:
3030 * INTERVAL ::= [START|+START_OFFSET][%[END|+END_OFFSET]]
3031 * INTERVALS ::= INTERVAL[,INTERVALS]
3032 */
3033 4 static int parse_read_interval(const char *interval_spec,
3034 ReadInterval *interval)
3035 {
3036 4 int ret = 0;
3037 4 char *next, *p, *spec = av_strdup(interval_spec);
3038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!spec)
3039 return AVERROR(ENOMEM);
3040
3041
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!*spec) {
3042 av_log(NULL, AV_LOG_ERROR, "Invalid empty interval specification\n");
3043 ret = AVERROR(EINVAL);
3044 goto end;
3045 }
3046
3047 4 p = spec;
3048 4 next = strchr(spec, '%');
3049
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (next)
3050 4 *next++ = 0;
3051
3052 /* parse first part */
3053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (*p) {
3054 interval->has_start = 1;
3055
3056 if (*p == '+') {
3057 interval->start_is_offset = 1;
3058 p++;
3059 } else {
3060 interval->start_is_offset = 0;
3061 }
3062
3063 ret = av_parse_time(&interval->start, p, 1);
3064 if (ret < 0) {
3065 av_log(NULL, AV_LOG_ERROR, "Invalid interval start specification '%s'\n", p);
3066 goto end;
3067 }
3068 } else {
3069 4 interval->has_start = 0;
3070 }
3071
3072 /* parse second part */
3073 4 p = next;
3074
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 if (p && *p) {
3075 int64_t us;
3076 4 interval->has_end = 1;
3077
3078
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (*p == '+') {
3079 1 interval->end_is_offset = 1;
3080 1 p++;
3081 } else {
3082 3 interval->end_is_offset = 0;
3083 }
3084
3085
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
4 if (interval->end_is_offset && *p == '#') {
3086 long long int lli;
3087 char *tail;
3088 1 interval->duration_frames = 1;
3089 1 p++;
3090 1 lli = strtoll(p, &tail, 10);
3091
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (*tail || lli < 0) {
3092 av_log(NULL, AV_LOG_ERROR,
3093 "Invalid or negative value '%s' for duration number of frames\n", p);
3094 goto end;
3095 }
3096 1 interval->end = lli;
3097 } else {
3098 3 interval->duration_frames = 0;
3099 3 ret = av_parse_time(&us, p, 1);
3100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0) {
3101 av_log(NULL, AV_LOG_ERROR, "Invalid interval end/duration specification '%s'\n", p);
3102 goto end;
3103 }
3104 3 interval->end = us;
3105 }
3106 } else {
3107 interval->has_end = 0;
3108 }
3109
3110 4 end:
3111 4 av_free(spec);
3112 4 return ret;
3113 }
3114
3115 4 static int parse_read_intervals(const char *intervals_spec)
3116 {
3117 int ret, n, i;
3118 4 char *p, *spec = av_strdup(intervals_spec);
3119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!spec)
3120 return AVERROR(ENOMEM);
3121
3122 /* preparse specification, get number of intervals */
3123
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 4 times.
23 for (n = 0, p = spec; *p; p++)
3124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
19 if (*p == ',')
3125 n++;
3126 4 n++;
3127
3128 4 read_intervals = av_malloc_array(n, sizeof(*read_intervals));
3129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!read_intervals) {
3130 ret = AVERROR(ENOMEM);
3131 goto end;
3132 }
3133 4 read_intervals_nb = n;
3134
3135 /* parse intervals */
3136 4 p = spec;
3137
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (i = 0; p; i++) {
3138 char *next;
3139
3140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 av_assert0(i < read_intervals_nb);
3141 4 next = strchr(p, ',');
3142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (next)
3143 *next++ = 0;
3144
3145 4 read_intervals[i].id = i;
3146 4 ret = parse_read_interval(p, &read_intervals[i]);
3147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0) {
3148 av_log(NULL, AV_LOG_ERROR, "Error parsing read interval #%d '%s'\n",
3149 i, p);
3150 goto end;
3151 }
3152 4 av_log(NULL, AV_LOG_VERBOSE, "Parsed log interval ");
3153 4 log_read_interval(&read_intervals[i], NULL, AV_LOG_VERBOSE);
3154 4 p = next;
3155 }
3156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 av_assert0(i == read_intervals_nb);
3157
3158 4 end:
3159 4 av_free(spec);
3160 4 return ret;
3161 }
3162
3163 4 static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
3164 {
3165 4 return parse_read_intervals(arg);
3166 }
3167
3168 static int opt_pretty(void *optctx, const char *opt, const char *arg)
3169 {
3170 show_value_unit = 1;
3171 use_value_prefix = 1;
3172 use_byte_value_binary_prefix = 1;
3173 use_value_sexagesimal_format = 1;
3174 return 0;
3175 }
3176
3177 static void print_section(SectionID id, int level)
3178 {
3179 const int *pid;
3180 const struct AVTextFormatSection *section = &sections[id];
3181 printf("%c%c%c%c",
3182 section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
3183 section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY ? 'A' : '.',
3184 section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS ? 'V' : '.',
3185 section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE ? 'T' : '.');
3186 printf("%*c %s", level * 4, ' ', section->name);
3187 if (section->unique_name)
3188 printf("/%s", section->unique_name);
3189 printf("\n");
3190
3191 for (pid = section->children_ids; *pid != -1; pid++)
3192 print_section(*pid, level+1);
3193 }
3194
3195 static int opt_sections(void *optctx, const char *opt, const char *arg)
3196 {
3197 printf("Sections:\n"
3198 "W... = Section is a wrapper (contains other sections, no local entries)\n"
3199 ".A.. = Section contains an array of elements of the same type\n"
3200 "..V. = Section may contain a variable number of fields with variable keys\n"
3201 "...T = Section contain a unique type\n"
3202 "FLAGS NAME/UNIQUE_NAME\n"
3203 "----\n");
3204 print_section(SECTION_ID_ROOT, 0);
3205 return 0;
3206 }
3207
3208 static int opt_codec(void *optctx, const char *opt, const char *arg)
3209 {
3210 const char *spec = strchr(opt, ':');
3211 const char **name;
3212 if (!spec) {
3213 av_log(NULL, AV_LOG_ERROR,
3214 "No media specifier was specified for '%s' in option '%s'. Use -%s:<media_spec> "
3215 "where <media_spec> can be one of: 'a' (audio), 'v' (video), 's' (subtitle), 'd' (data)\n",
3216 arg, opt, opt);
3217 return AVERROR(EINVAL);
3218 }
3219 spec++;
3220
3221 switch (spec[0]) {
3222 case 'a' : name = &audio_codec_name; break;
3223 case 'd' : name = &data_codec_name; break;
3224 case 's' : name = &subtitle_codec_name; break;
3225 case 'v' : name = &video_codec_name; break;
3226 default:
3227 av_log(NULL, AV_LOG_ERROR,
3228 "Invalid media specifier '%s' in option '%s'. "
3229 "Must be one of: 'a' (audio), 'v' (video), 's' (subtitle), 'd' (data)\n", spec, opt);
3230 return AVERROR(EINVAL);
3231 }
3232
3233 av_freep(name);
3234 *name = av_strdup(arg);
3235 return *name ? 0 : AVERROR(ENOMEM);
3236 }
3237
3238 static int opt_show_versions(void *optctx, const char *opt, const char *arg)
3239 {
3240 mark_section_show_entries(SECTION_ID_PROGRAM_VERSION, 1, NULL);
3241 mark_section_show_entries(SECTION_ID_LIBRARY_VERSION, 1, NULL);
3242 return 0;
3243 }
3244
3245 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3246 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3247 { \
3248 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3249 return 0; \
3250 }
3251
3252 4 DEFINE_OPT_SHOW_SECTION(chapters, CHAPTERS)
3253 DEFINE_OPT_SHOW_SECTION(error, ERROR)
3254 16 DEFINE_OPT_SHOW_SECTION(format, FORMAT)
3255 32 DEFINE_OPT_SHOW_SECTION(frames, FRAMES)
3256 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS)
3257 35 DEFINE_OPT_SHOW_SECTION(packets, PACKETS)
3258 DEFINE_OPT_SHOW_SECTION(pixel_formats, PIXEL_FORMATS)
3259 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION)
3260 26 DEFINE_OPT_SHOW_SECTION(streams, STREAMS)
3261 DEFINE_OPT_SHOW_SECTION(programs, PROGRAMS)
3262 DEFINE_OPT_SHOW_SECTION(stream_groups, STREAM_GROUPS)
3263
3264 static const OptionDef real_options[] = {
3265 CMDUTILS_COMMON_OPTIONS
3266 { "f", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_format}, "force format", "format" },
3267 { "unit", OPT_TYPE_BOOL, 0, {&show_value_unit}, "show unit of the displayed values" },
3268 { "prefix", OPT_TYPE_BOOL, 0, {&use_value_prefix}, "use SI prefixes for the displayed values" },
3269 { "byte_binary_prefix", OPT_TYPE_BOOL, 0, {&use_byte_value_binary_prefix},
3270 "use binary prefixes for byte units" },
3271 { "sexagesimal", OPT_TYPE_BOOL, 0, {&use_value_sexagesimal_format},
3272 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
3273 { "pretty", OPT_TYPE_FUNC, 0, {.func_arg = opt_pretty},
3274 "prettify the format of displayed values, make it more human readable" },
3275 { "output_format", OPT_TYPE_STRING, 0, { &output_format },
3276 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
3277 { "print_format", OPT_TYPE_STRING, 0, { &output_format }, "alias for -output_format (deprecated)" },
3278 { "of", OPT_TYPE_STRING, 0, { &output_format }, "alias for -output_format", "format" },
3279 { "select_streams", OPT_TYPE_STRING, 0, { &stream_specifier }, "select the specified streams", "stream_specifier" },
3280 { "sections", OPT_TYPE_FUNC, OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
3281 { "data_dump_format", OPT_TYPE_STRING, 0, { &data_dump_format }, "set data dump format (available formats are: xxd, base64)" },
3282 { "show_data", OPT_TYPE_BOOL, 0, { &do_show_data }, "show packets data" },
3283 { "show_data_hash", OPT_TYPE_STRING, 0, { &show_data_hash }, "show packets data hash" },
3284 { "show_error", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_error }, "show probing error" },
3285 { "show_format", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_format }, "show format/container info" },
3286 { "show_frames", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_frames }, "show frames info" },
3287 { "show_entries", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_show_entries},
3288 "show a set of specified entries", "entry_list" },
3289 #if HAVE_THREADS
3290 { "show_log", OPT_TYPE_INT, 0, { &do_show_log }, "show log" },
3291 #endif
3292 { "show_packets", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_packets }, "show packets info" },
3293 { "show_programs", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_programs }, "show programs info" },
3294 { "show_stream_groups", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_stream_groups }, "show stream groups info" },
3295 { "show_streams", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_streams }, "show streams info" },
3296 { "show_chapters", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_chapters }, "show chapters info" },
3297 { "count_frames", OPT_TYPE_BOOL, 0, { &do_count_frames }, "count the number of frames per stream" },
3298 { "count_packets", OPT_TYPE_BOOL, 0, { &do_count_packets }, "count the number of packets per stream" },
3299 { "show_program_version", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_program_version }, "show ffprobe version" },
3300 { "show_library_versions", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_library_versions }, "show library versions" },
3301 { "show_versions", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_versions }, "show program and library versions" },
3302 { "show_pixel_formats", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_pixel_formats }, "show pixel format descriptions" },
3303 { "show_optional_fields", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" },
3304 { "show_private_data", OPT_TYPE_BOOL, 0, { &show_private_data }, "show private data" },
3305 { "private", OPT_TYPE_BOOL, 0, { &show_private_data }, "same as show_private_data" },
3306 { "analyze_frames", OPT_TYPE_BOOL, 0, { &do_analyze_frames }, "analyze frames to provide additional stream-level information" },
3307 { "bitexact", OPT_TYPE_BOOL, 0, {&do_bitexact}, "force bitexact output" },
3308 { "read_intervals", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
3309 { "i", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
3310 { "o", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_output_file_o}, "write to specified output", "output_file"},
3311 { "print_filename", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"},
3312 { "find_stream_info", OPT_TYPE_BOOL, OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3313 "read and decode the streams to fill missing information with heuristics" },
3314 { "c", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_codec}, "force decoder", "decoder_name" },
3315 { "codec", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_codec}, "alias for -c (force decoder)", "decoder_name" },
3316 { NULL, },
3317 };
3318
3319 16865 static inline int check_section_show_entries(int section_id)
3320 {
3321 16865 const EntrySelection *selection = &selected_entries[section_id];
3322
3323
4/4
✓ Branch 0 taken 16424 times.
✓ Branch 1 taken 441 times.
✓ Branch 2 taken 341 times.
✓ Branch 3 taken 16083 times.
16865 if (selection->show_all_entries || selection->entries_to_show)
3324 782 return 1;
3325
3326 16083 const AVTextFormatSection *section = &sections[section_id];
3327
2/2
✓ Branch 0 taken 11303 times.
✓ Branch 1 taken 15359 times.
26662 for (const int *id = section->children_ids; *id != -1; id++)
3328
2/2
✓ Branch 1 taken 724 times.
✓ Branch 2 taken 10579 times.
11303 if (check_section_show_entries(*id))
3329 724 return 1;
3330 15359 return 0;
3331 }
3332
3333 #define SET_DO_SHOW(id, varname) do { \
3334 if (check_section_show_entries(SECTION_ID_##id)) \
3335 do_show_##varname = 1; \
3336 } while (0)
3337
3338 206 int main(int argc, char **argv)
3339 {
3340 const AVTextFormatter *f;
3341 AVTextFormatContext *tctx;
3342 AVTextWriterContext *wctx;
3343 char *buf;
3344 206 char *f_name = NULL, *f_args = NULL;
3345 int ret, input_ret;
3346 206 AVTextFormatDataDump data_dump_format_id = AV_TEXTFORMAT_DATADUMP_XXD;
3347
3348 206 init_dynload();
3349
3350 206 setvbuf(stderr, NULL, _IONBF, 0); /* win32 runtime needs this */
3351
3352 206 av_log_set_flags(AV_LOG_SKIP_REPEATED);
3353
3354 206 options = real_options;
3355 206 parse_loglevel(argc, argv, options);
3356 206 avformat_network_init();
3357 #if CONFIG_AVDEVICE
3358 206 avdevice_register_all();
3359 #endif
3360
3361 206 show_banner(argc, argv, options);
3362 206 ret = parse_options(NULL, argc, argv, options, opt_input_file);
3363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (ret < 0) {
3364 ret = (ret == AVERROR_EXIT) ? 0 : ret;
3365 goto end;
3366 }
3367
3368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (do_show_log)
3369 av_log_set_callback(log_callback);
3370
3371 /* mark things to show, based on -show_entries */
3372
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 201 times.
206 SET_DO_SHOW(CHAPTERS, chapters);
3373
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 SET_DO_SHOW(ERROR, error);
3374
2/2
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 163 times.
206 SET_DO_SHOW(FORMAT, format);
3375
2/2
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 148 times.
206 SET_DO_SHOW(FRAMES, frames);
3376
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
3377
2/2
✓ Branch 1 taken 71 times.
✓ Branch 2 taken 135 times.
206 SET_DO_SHOW(PACKETS, packets);
3378
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 SET_DO_SHOW(PIXEL_FORMATS, pixel_formats);
3379
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
3380
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
3381
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 SET_DO_SHOW(PROGRAM_VERSION, program_version);
3382
2/2
✓ Branch 1 taken 88 times.
✓ Branch 2 taken 118 times.
206 SET_DO_SHOW(PROGRAMS, programs);
3383
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 198 times.
206 SET_DO_SHOW(STREAM_GROUP_DISPOSITION, stream_group_disposition);
3384
2/2
✓ Branch 1 taken 106 times.
✓ Branch 2 taken 100 times.
206 SET_DO_SHOW(STREAM_GROUPS, stream_groups);
3385
2/2
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 185 times.
206 SET_DO_SHOW(STREAM_GROUP_COMPONENTS, stream_group_components);
3386
2/2
✓ Branch 1 taken 124 times.
✓ Branch 2 taken 82 times.
206 SET_DO_SHOW(STREAMS, streams);
3387
2/2
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 161 times.
206 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
3388
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 201 times.
206 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3389
2/2
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 182 times.
206 SET_DO_SHOW(STREAM_GROUP_STREAM_DISPOSITION, stream_disposition);
3390
3391
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 201 times.
206 SET_DO_SHOW(CHAPTER_TAGS, chapter_tags);
3392
2/2
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 171 times.
206 SET_DO_SHOW(FORMAT_TAGS, format_tags);
3393
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 158 times.
206 SET_DO_SHOW(FRAME_TAGS, frame_tags);
3394
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 SET_DO_SHOW(PROGRAM_TAGS, program_tags);
3395
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 198 times.
206 SET_DO_SHOW(STREAM_GROUP_TAGS, stream_group_tags);
3396
2/2
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 165 times.
206 SET_DO_SHOW(STREAM_TAGS, stream_tags);
3397
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 201 times.
206 SET_DO_SHOW(PROGRAM_STREAM_TAGS, stream_tags);
3398
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 201 times.
206 SET_DO_SHOW(STREAM_GROUP_STREAM_TAGS, stream_tags);
3399
2/2
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 169 times.
206 SET_DO_SHOW(PACKET_TAGS, packet_tags);
3400
3401
4/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 189 times.
206 if (do_bitexact && (do_show_program_version || do_show_library_versions)) {
3402 av_log(NULL, AV_LOG_ERROR,
3403 "-bitexact and -show_program_version or -show_library_versions "
3404 "options are incompatible\n");
3405 ret = AVERROR(EINVAL);
3406 goto end;
3407 }
3408
3409
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 68 times.
206 if (!output_format)
3410 138 output_format = av_strdup("default");
3411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (!output_format) {
3412 ret = AVERROR(ENOMEM);
3413 goto end;
3414 }
3415 206 f_name = av_strtok(output_format, "=", &buf);
3416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (!f_name) {
3417 av_log(NULL, AV_LOG_ERROR,
3418 "No name specified for the output format\n");
3419 ret = AVERROR(EINVAL);
3420 goto end;
3421 }
3422 206 f_args = buf;
3423
3424 206 f = avtext_get_formatter_by_name(f_name);
3425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (!f) {
3426 av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", f_name);
3427 ret = AVERROR(EINVAL);
3428 goto end;
3429 }
3430
3431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (data_dump_format) {
3432 if (!strcmp(data_dump_format, "xxd")) {
3433 data_dump_format_id = AV_TEXTFORMAT_DATADUMP_XXD;
3434 } else if (!strcmp(data_dump_format, "base64")) {
3435 data_dump_format_id = AV_TEXTFORMAT_DATADUMP_BASE64;
3436 } else {
3437 av_log(NULL, AV_LOG_ERROR, "Unknown data dump format with name '%s'\n", data_dump_format);
3438 ret = AVERROR(EINVAL);
3439 goto end;
3440 }
3441 }
3442
3443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (output_filename) {
3444 ret = avtextwriter_create_file(&wctx, output_filename);
3445 } else
3446 206 ret = avtextwriter_create_stdout(&wctx);
3447
3448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (ret < 0)
3449 goto end;
3450
3451 206 AVTextFormatOptions tf_options = {
3452 .is_key_selected = is_key_selected_callback,
3453 .show_optional_fields = show_optional_fields,
3454 .show_value_unit = show_value_unit,
3455 .use_value_prefix = use_value_prefix,
3456 .use_byte_value_binary_prefix = use_byte_value_binary_prefix,
3457 .use_value_sexagesimal_format = use_value_sexagesimal_format,
3458 .data_dump_format = data_dump_format_id,
3459 };
3460
3461
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 206 times.
206 if ((ret = avtext_context_open(&tctx, f, wctx, f_args, sections, FF_ARRAY_ELEMS(sections), tf_options, show_data_hash)) >= 0) {
3462
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 204 times.
206 if (f == &avtextformatter_xml)
3463 2 tctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;
3464
3465 206 avtext_print_section_header(tctx, NULL, SECTION_ID_ROOT);
3466
3467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (do_show_program_version)
3468 ffprobe_show_program_version(tctx);
3469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (do_show_library_versions)
3470 ffprobe_show_library_versions(tctx);
3471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (do_show_pixel_formats)
3472 ffprobe_show_pixel_formats(tctx);
3473
3474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (!input_filename &&
3475 ((do_show_format || do_show_programs || do_show_stream_groups || do_show_streams || do_show_chapters || do_show_packets || do_show_error) ||
3476 (!do_show_program_version && !do_show_library_versions && !do_show_pixel_formats))) {
3477 show_usage();
3478 av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
3479 av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
3480 ret = AVERROR(EINVAL);
3481
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 } else if (input_filename) {
3482 206 ret = probe_file(tctx, input_filename, print_input_filename);
3483
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
206 if (ret < 0 && do_show_error)
3484 show_error(tctx, ret);
3485 }
3486
3487 206 input_ret = ret;
3488
3489 206 avtext_print_section_footer(tctx);
3490
3491 206 ret = avtextwriter_context_close(&wctx);
3492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (ret < 0)
3493 av_log(NULL, AV_LOG_ERROR, "Writing output failed (closing writer): %s\n", av_err2str(ret));
3494
3495 206 ret = avtext_context_close(&tctx);
3496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206 times.
206 if (ret < 0)
3497 av_log(NULL, AV_LOG_ERROR, "Writing output failed (closing formatter): %s\n", av_err2str(ret));
3498
3499 206 ret = FFMIN(ret, input_ret);
3500 }
3501
3502 end:
3503 206 av_freep(&output_format);
3504 206 av_freep(&output_filename);
3505 206 av_freep(&input_filename);
3506 206 av_freep(&print_input_filename);
3507 206 av_freep(&read_intervals);
3508
3509 206 uninit_opts();
3510
2/2
✓ Branch 0 taken 14008 times.
✓ Branch 1 taken 206 times.
14214 for (size_t i = 0; i < FF_ARRAY_ELEMS(selected_entries); ++i)
3511 14008 av_dict_free(&selected_entries[i].entries_to_show);
3512
3513 206 avformat_network_deinit();
3514
3515 206 return ret < 0;
3516 }
3517