FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffprobe.c
Date: 2026-04-20 20:24:43
Exec Total Coverage
Lines: 1403 2007 69.9%
Functions: 67 94 71.3%
Branches: 762 1298 58.7%

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 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 154109 static int is_key_selected_callback(AVTextFormatContext *tctx, const char *key)
374 {
375 154109 const AVTextFormatSection *section = tctx->section[tctx->level];
376 154109 const EntrySelection *selection = &selected_entries[section - sections];
377
378
4/4
✓ Branch 0 taken 88944 times.
✓ Branch 1 taken 65165 times.
✓ Branch 3 taken 18165 times.
✓ Branch 4 taken 70779 times.
154109 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 (int idx = 0; idx < n; idx++) { \
440 for (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 1408 static inline int show_tags(AVTextFormatContext *tfc, AVDictionary *tags, int section_id)
493 {
494 1408 const AVDictionaryEntry *tag = NULL;
495 1408 int ret = 0;
496
497
2/2
✓ Branch 0 taken 698 times.
✓ Branch 1 taken 710 times.
1408 if (!tags)
498 698 return 0;
499 710 avtext_print_section_header(tfc, NULL, section_id);
500
501
2/2
✓ Branch 1 taken 3320 times.
✓ Branch 2 taken 710 times.
4030 while ((tag = av_dict_iterate(tags, tag))) {
502
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3320 times.
3320 if ((ret = print_str_validate(tag->key, tag->value)) < 0)
503 break;
504 }
505 710 avtext_print_section_footer(tfc);
506
507 710 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 (int 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 485 static void print_private_data(AVTextFormatContext *tfc, void *priv_data)
1177 {
1178 485 const AVOption *opt = NULL;
1179
2/2
✓ Branch 1 taken 3684 times.
✓ Branch 2 taken 485 times.
4169 while (opt = av_opt_next(priv_data, opt)) {
1180 uint8_t *str;
1181
2/2
✓ Branch 0 taken 3482 times.
✓ Branch 1 taken 202 times.
3684 if (!(opt->flags & AV_OPT_FLAG_EXPORT)) continue;
1182
1/2
✓ Branch 1 taken 202 times.
✗ Branch 2 not taken.
202 if (av_opt_get(priv_data, opt->name, 0, &str) >= 0) {
1183 202 print_str(opt->name, str);
1184 202 av_free(str);
1185 }
1186 }
1187 485 }
1188
1189 690 static void print_pixel_format(AVTextFormatContext *tfc, enum AVPixelFormat pix_fmt)
1190 {
1191 690 const char *s = av_get_pix_fmt_name(pix_fmt);
1192 enum AVPixelFormat swapped_pix_fmt;
1193
1194
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 688 times.
690 if (!s) {
1195 2 print_str_opt("pix_fmt", "unknown");
1196
4/4
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 632 times.
✓ Branch 3 taken 24 times.
1344 } else if (!do_bitexact ||
1197 656 (swapped_pix_fmt = av_pix_fmt_swap_endianness(pix_fmt)) == AV_PIX_FMT_NONE) {
1198 664 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 690 }
1213
1214 690 static void print_color_range(AVTextFormatContext *tfc, enum AVColorRange color_range)
1215 {
1216 690 const char *val = av_color_range_name(color_range);
1217
3/4
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 410 times.
✓ Branch 3 taken 280 times.
690 if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
1218 410 print_str_opt("color_range", "unknown");
1219 } else {
1220 280 print_str("color_range", val);
1221 }
1222 690 }
1223
1224 690 static void print_color_space(AVTextFormatContext *tfc, enum AVColorSpace color_space)
1225 {
1226 690 const char *val = av_color_space_name(color_space);
1227
3/4
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 460 times.
✓ Branch 3 taken 230 times.
690 if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
1228 460 print_str_opt("color_space", "unknown");
1229 } else {
1230 230 print_str("color_space", val);
1231 }
1232 690 }
1233
1234 690 static void print_primaries(AVTextFormatContext *tfc, enum AVColorPrimaries color_primaries)
1235 {
1236 690 const char *val = av_color_primaries_name(color_primaries);
1237
3/4
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 484 times.
✓ Branch 3 taken 206 times.
690 if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
1238 484 print_str_opt("color_primaries", "unknown");
1239 } else {
1240 206 print_str("color_primaries", val);
1241 }
1242 690 }
1243
1244 690 static void print_color_trc(AVTextFormatContext *tfc, enum AVColorTransferCharacteristic color_trc)
1245 {
1246 690 const char *val = av_color_transfer_name(color_trc);
1247
3/4
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 483 times.
✓ Branch 3 taken 207 times.
690 if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
1248 483 print_str_opt("color_transfer", "unknown");
1249 } else {
1250 207 print_str("color_transfer", val);
1251 }
1252 690 }
1253
1254 690 static void print_chroma_location(AVTextFormatContext *tfc, enum AVChromaLocation chroma_location)
1255 {
1256 690 const char *val = av_chroma_location_name(chroma_location);
1257
3/4
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 412 times.
✓ Branch 3 taken 278 times.
690 if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
1258 412 print_str_opt("chroma_location", "unspecified");
1259 } else {
1260 278 print_str("chroma_location", val);
1261 }
1262 690 }
1263
1264 584 static void print_alpha_mode(AVTextFormatContext *tfc, enum AVAlphaMode alpha_mode)
1265 {
1266 584 const char *val = av_alpha_mode_name(alpha_mode);
1267
3/4
✓ Branch 0 taken 584 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 583 times.
✓ Branch 3 taken 1 times.
584 if (!val || alpha_mode == AVALPHA_MODE_UNSPECIFIED) {
1268 583 print_str_opt("alpha_mode", "unspecified");
1269 } else {
1270 1 print_str("alpha_mode", val);
1271 }
1272 584 }
1273
1274 6360 static void clear_log(int need_lock)
1275 {
1276 int i;
1277
1278
1/2
✓ Branch 0 taken 6360 times.
✗ Branch 1 not taken.
6360 if (need_lock)
1279 6360 ff_mutex_lock(&log_mutex);
1280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6360 times.
6360 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 6360 log_buffer_size = 0;
1286
1/2
✓ Branch 0 taken 6360 times.
✗ Branch 1 not taken.
6360 if(need_lock)
1287 6360 ff_mutex_unlock(&log_mutex);
1288 6360 }
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 190 static void print_frame_side_data(AVTextFormatContext *tfc,
1406 const AVFrame *frame,
1407 const AVStream *stream)
1408 {
1409 190 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_LIST);
1410
1411
2/2
✓ Branch 0 taken 339 times.
✓ Branch 1 taken 190 times.
529 for (int i = 0; i < frame->nb_side_data; i++) {
1412 339 const AVFrameSideData *sd = frame->side_data[i];
1413 const char *name;
1414
1415 339 avtext_print_section_header(tfc, sd, SECTION_ID_FRAME_SIDE_DATA);
1416 339 name = av_frame_side_data_name(sd->type);
1417
1/2
✓ Branch 0 taken 339 times.
✗ Branch 1 not taken.
339 print_str("side_data_type", name ? name : "unknown");
1418
3/4
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 247 times.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
339 if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1419 92 print_displaymatrix(tfc, (const int32_t*)sd->data);
1420
3/4
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
247 } else if (sd->type == AV_FRAME_DATA_AFD && sd->size > 0) {
1421 67 print_int("active_format", *sd->data);
1422
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 180 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
180 } else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
1423 char tcbuf[AV_TIMECODE_STR_SIZE];
1424 av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
1425 print_str("timecode", tcbuf);
1426
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 159 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
201 } else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
1427 21 uint32_t *tc = (uint32_t*)sd->data;
1428 21 int m = FFMIN(tc[0],3);
1429 21 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST);
1430
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 21 times.
42 for (int j = 1; j <= m ; j++) {
1431 char tcbuf[AV_TIMECODE_STR_SIZE];
1432 21 av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
1433 21 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME_SIDE_DATA_TIMECODE);
1434 21 print_str("value", tcbuf);
1435 21 avtext_print_section_footer(tfc);
1436 }
1437 21 avtext_print_section_footer(tfc);
1438
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 135 times.
159 } else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
1439 24 print_mastering_display_metadata(tfc, (AVMasteringDisplayMetadata *)sd->data);
1440
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 133 times.
135 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
1441 2 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
1442 2 print_dynamic_hdr10_plus(tfc, metadata);
1443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
133 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5) {
1444 AVDynamicHDRSmpte2094App5 *metadata = (AVDynamicHDRSmpte2094App5 *)sd->data;
1445 print_dynamic_hdr_smpte2094_app5(tfc, metadata);
1446
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 109 times.
133 } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
1447 24 print_context_light_level(tfc, (AVContentLightMetadata *)sd->data);
1448
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 106 times.
109 } else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
1449 3 const AVDictionaryEntry *tag = av_dict_get(sd->metadata, "name", NULL, AV_DICT_MATCH_CASE);
1450
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (tag)
1451 2 print_str(tag->key, tag->value);
1452 3 print_int("size", sd->size);
1453
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 104 times.
106 } else if (sd->type == AV_FRAME_DATA_DOVI_METADATA) {
1454 2 print_dovi_metadata(tfc, (const AVDOVIMetadata *)sd->data);
1455
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 103 times.
104 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_VIVID) {
1456 1 AVDynamicHDRVivid *metadata = (AVDynamicHDRVivid *)sd->data;
1457 1 print_dynamic_hdr_vivid(tfc, metadata);
1458
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 101 times.
103 } else if (sd->type == AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
1459 2 print_ambient_viewing_environment(tfc, (const AVAmbientViewingEnvironment *)sd->data);
1460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 101 times.
101 } else if (sd->type == AV_FRAME_DATA_FILM_GRAIN_PARAMS) {
1461 AVFilmGrainParams *fgp = (AVFilmGrainParams *)sd->data;
1462 print_film_grain_params(tfc, fgp);
1463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 101 times.
101 } else if (sd->type == AV_FRAME_DATA_VIEW_ID) {
1464 print_int("view_id", *(int*)sd->data);
1465
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 93 times.
101 } else if (sd->type == AV_FRAME_DATA_EXIF) {
1466 8 print_int("size", sd->size);
1467 }
1468 339 avtext_print_section_footer(tfc);
1469 }
1470 190 avtext_print_section_footer(tfc);
1471 190 }
1472
1473 3159 static void show_frame(AVTextFormatContext *tfc, AVFrame *frame, AVStream *stream,
1474 AVFormatContext *fmt_ctx)
1475 {
1476
1/2
✓ Branch 0 taken 3159 times.
✗ Branch 1 not taken.
3159 FrameData *fd = frame->opaque_ref ? (FrameData*)frame->opaque_ref->data : NULL;
1477 AVBPrint pbuf;
1478 char val_str[128];
1479 const char *s;
1480
1481 3159 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
1482
1483 3159 avtext_print_section_header(tfc, NULL, SECTION_ID_FRAME);
1484
1485 3159 s = av_get_media_type_string(stream->codecpar->codec_type);
1486
1/2
✓ Branch 0 taken 3159 times.
✗ Branch 1 not taken.
3159 if (s) print_str ("media_type", s);
1487 else print_str_opt("media_type", "unknown");
1488 3159 print_int("stream_index", stream->index);
1489 3159 print_int("key_frame", !!(frame->flags & AV_FRAME_FLAG_KEY));
1490 3159 print_ts ("pts", frame->pts);
1491 3159 print_time("pts_time", frame->pts, &stream->time_base);
1492 3159 print_ts ("pkt_dts", frame->pkt_dts);
1493 3159 print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
1494 3159 print_ts ("best_effort_timestamp", frame->best_effort_timestamp);
1495 3159 print_time("best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
1496 3159 print_duration_ts ("duration", frame->duration);
1497 3159 print_duration_time("duration_time", frame->duration, &stream->time_base);
1498
3/4
✓ Branch 0 taken 3159 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2472 times.
✓ Branch 3 taken 687 times.
3159 if (fd && fd->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, fd->pkt_pos);
1499 687 else print_str_opt("pkt_pos", "N/A");
1500
2/4
✓ Branch 0 taken 3159 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3159 times.
✗ Branch 3 not taken.
3159 if (fd && fd->pkt_size != -1) print_val ("pkt_size", fd->pkt_size, unit_byte_str);
1501 else print_str_opt("pkt_size", "N/A");
1502
1503
2/3
✓ Branch 0 taken 584 times.
✓ Branch 1 taken 2575 times.
✗ Branch 2 not taken.
3159 switch (stream->codecpar->codec_type) {
1504 AVRational sar;
1505
1506 584 case AVMEDIA_TYPE_VIDEO:
1507 584 print_int("width", frame->width);
1508 584 print_int("height", frame->height);
1509 584 print_int("crop_top", frame->crop_top);
1510 584 print_int("crop_bottom", frame->crop_bottom);
1511 584 print_int("crop_left", frame->crop_left);
1512 584 print_int("crop_right", frame->crop_right);
1513 584 print_pixel_format(tfc, frame->format);
1514 584 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
1515
2/2
✓ Branch 0 taken 571 times.
✓ Branch 1 taken 13 times.
584 if (sar.num) {
1516 571 print_q("sample_aspect_ratio", sar, ':');
1517 } else {
1518 13 print_str_opt("sample_aspect_ratio", "N/A");
1519 }
1520 584 print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
1521 584 print_int("interlaced_frame", !!(frame->flags & AV_FRAME_FLAG_INTERLACED));
1522 584 print_int("top_field_first", !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST));
1523 584 print_int("lossless", !!(frame->flags & AV_FRAME_FLAG_LOSSLESS));
1524 584 print_int("repeat_pict", frame->repeat_pict);
1525
1526 584 print_color_range(tfc, frame->color_range);
1527 584 print_color_space(tfc, frame->colorspace);
1528 584 print_primaries(tfc, frame->color_primaries);
1529 584 print_color_trc(tfc, frame->color_trc);
1530 584 print_chroma_location(tfc, frame->chroma_location);
1531 584 print_alpha_mode(tfc, frame->alpha_mode);
1532 584 break;
1533
1534 2575 case AVMEDIA_TYPE_AUDIO:
1535 2575 s = av_get_sample_fmt_name(frame->format);
1536
1/2
✓ Branch 0 taken 2575 times.
✗ Branch 1 not taken.
2575 if (s) print_str ("sample_fmt", s);
1537 else print_str_opt("sample_fmt", "unknown");
1538 2575 print_int("nb_samples", frame->nb_samples);
1539 2575 print_int("channels", frame->ch_layout.nb_channels);
1540
2/2
✓ Branch 0 taken 2352 times.
✓ Branch 1 taken 223 times.
2575 if (frame->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
1541 2352 av_channel_layout_describe(&frame->ch_layout, val_str, sizeof(val_str));
1542 2352 print_str ("channel_layout", val_str);
1543 } else
1544 223 print_str_opt("channel_layout", "unknown");
1545 2575 break;
1546 }
1547
2/2
✓ Branch 0 taken 1111 times.
✓ Branch 1 taken 2048 times.
3159 if (do_show_frame_tags)
1548 1111 show_tags(tfc, frame->metadata, SECTION_ID_FRAME_TAGS);
1549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3159 times.
3159 if (do_show_log)
1550 show_log(tfc, SECTION_ID_FRAME_LOGS, SECTION_ID_FRAME_LOG, do_show_log);
1551
2/2
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 2969 times.
3159 if (frame->nb_side_data)
1552 190 print_frame_side_data(tfc, frame, stream);
1553
1554 3159 avtext_print_section_footer(tfc);
1555
1556 3159 av_bprint_finalize(&pbuf, NULL);
1557 3159 fflush(stdout);
1558 3159 }
1559
1560 6360 static av_always_inline int process_frame(AVTextFormatContext *tfc,
1561 InputFile *ifile,
1562 AVFrame *frame, const AVPacket *pkt,
1563 int *packet_new)
1564 {
1565 6360 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
1566 6360 AVCodecContext *dec_ctx = ifile->streams[pkt->stream_index].dec_ctx;
1567 6360 AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar;
1568 AVSubtitle sub;
1569 6360 int ret = 0, got_frame = 0;
1570
1571 6360 clear_log(1);
1572
2/2
✓ Branch 0 taken 6354 times.
✓ Branch 1 taken 6 times.
6360 if (dec_ctx) {
1573
1/3
✓ Branch 0 taken 6354 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
6354 switch (par->codec_type) {
1574 6354 case AVMEDIA_TYPE_VIDEO:
1575 case AVMEDIA_TYPE_AUDIO:
1576
2/2
✓ Branch 0 taken 3216 times.
✓ Branch 1 taken 3138 times.
6354 if (*packet_new) {
1577 3216 ret = avcodec_send_packet(dec_ctx, pkt);
1578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3216 times.
3216 if (ret == AVERROR(EAGAIN)) {
1579 ret = 0;
1580
4/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 3193 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 2 times.
3216 } else if (ret >= 0 || ret == AVERROR_EOF) {
1581 3214 ret = 0;
1582 3214 *packet_new = 0;
1583 }
1584 }
1585
2/2
✓ Branch 0 taken 6352 times.
✓ Branch 1 taken 2 times.
6354 if (ret >= 0) {
1586 6352 ret = avcodec_receive_frame(dec_ctx, frame);
1587
2/2
✓ Branch 0 taken 3159 times.
✓ Branch 1 taken 3193 times.
6352 if (ret >= 0) {
1588 3159 got_frame = 1;
1589
3/4
✓ Branch 0 taken 77 times.
✓ Branch 1 taken 3116 times.
✓ Branch 2 taken 77 times.
✗ Branch 3 not taken.
3193 } else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
1590 3193 ret = 0;
1591 }
1592 }
1593 6354 break;
1594
1595 case AVMEDIA_TYPE_SUBTITLE:
1596 if (*packet_new)
1597 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
1598 *packet_new = 0;
1599 break;
1600 default:
1601 *packet_new = 0;
1602 }
1603 } else {
1604 6 *packet_new = 0;
1605 }
1606
1607
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6358 times.
6360 if (ret < 0)
1608 2 return ret;
1609
2/2
✓ Branch 0 taken 3159 times.
✓ Branch 1 taken 3199 times.
6358 if (got_frame) {
1610 3159 int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
1611 3159 nb_streams_frames[pkt->stream_index]++;
1612
1/2
✓ Branch 0 taken 3159 times.
✗ Branch 1 not taken.
3159 if (do_show_frames)
1613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3159 times.
3159 if (is_sub)
1614 show_subtitle(tfc, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
1615 else
1616 3159 show_frame(tfc, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);
1617
1618
2/4
✓ Branch 0 taken 3159 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3159 times.
3159 if (!is_sub && do_analyze_frames) {
1619 for (int i = 0; i < frame->nb_side_data; i++) {
1620 if (frame->side_data[i]->type == AV_FRAME_DATA_A53_CC)
1621 streams_with_closed_captions[pkt->stream_index] = 1;
1622 else if (frame->side_data[i]->type == AV_FRAME_DATA_FILM_GRAIN_PARAMS)
1623 streams_with_film_grain[pkt->stream_index] = 1;
1624 }
1625 }
1626
1627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3159 times.
3159 if (is_sub)
1628 avsubtitle_free(&sub);
1629 }
1630
3/4
✓ Branch 0 taken 3199 times.
✓ Branch 1 taken 3159 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3199 times.
6358 return got_frame || *packet_new;
1631 }
1632
1633 119 static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
1634 {
1635 119 av_log(log_ctx, log_level, "id:%d", interval->id);
1636
1637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 119 times.
119 if (interval->has_start) {
1638 av_log(log_ctx, log_level, " start:%s%s", interval->start_is_offset ? "+" : "",
1639 av_ts2timestr(interval->start, &AV_TIME_BASE_Q));
1640 } else {
1641 119 av_log(log_ctx, log_level, " start:N/A");
1642 }
1643
1644
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 111 times.
119 if (interval->has_end) {
1645
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 ? "+" : "");
1646
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (interval->duration_frames)
1647 2 av_log(log_ctx, log_level, "#%"PRId64, interval->end);
1648 else
1649 6 av_log(log_ctx, log_level, "%s", av_ts2timestr(interval->end, &AV_TIME_BASE_Q));
1650 } else {
1651 111 av_log(log_ctx, log_level, " end:N/A");
1652 }
1653
1654 119 av_log(log_ctx, log_level, "\n");
1655 119 }
1656
1657 115 static int read_interval_packets(AVTextFormatContext *tfc, InputFile *ifile,
1658 const ReadInterval *interval, int64_t *cur_ts)
1659 {
1660 115 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
1661 115 AVPacket *pkt = NULL;
1662 115 AVFrame *frame = NULL;
1663 115 int ret = 0, i = 0, frame_count = 0;
1664 115 int64_t start = -INT64_MAX, end = interval->end;
1665
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 111 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
115 int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
1666
1667 115 av_log(NULL, AV_LOG_VERBOSE, "Processing read interval ");
1668 115 log_read_interval(interval, NULL, AV_LOG_VERBOSE);
1669
1670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (interval->has_start) {
1671 int64_t target;
1672 if (interval->start_is_offset) {
1673 if (*cur_ts == AV_NOPTS_VALUE) {
1674 av_log(NULL, AV_LOG_ERROR,
1675 "Could not seek to relative position since current "
1676 "timestamp is not defined\n");
1677 ret = AVERROR(EINVAL);
1678 goto end;
1679 }
1680 target = *cur_ts + interval->start;
1681 } else {
1682 target = interval->start;
1683 }
1684
1685 av_log(NULL, AV_LOG_VERBOSE, "Seeking to read interval start point %s\n",
1686 av_ts2timestr(target, &AV_TIME_BASE_Q));
1687 if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
1688 av_log(NULL, AV_LOG_ERROR, "Could not seek to position %"PRId64": %s\n",
1689 interval->start, av_err2str(ret));
1690 goto end;
1691 }
1692 }
1693
1694 115 frame = av_frame_alloc();
1695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (!frame) {
1696 ret = AVERROR(ENOMEM);
1697 goto end;
1698 }
1699 115 pkt = av_packet_alloc();
1700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (!pkt) {
1701 ret = AVERROR(ENOMEM);
1702 goto end;
1703 }
1704
2/2
✓ Branch 1 taken 8807 times.
✓ Branch 2 taken 111 times.
8918 while (!av_read_frame(fmt_ctx, pkt)) {
1705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8807 times.
8807 if (fmt_ctx->nb_streams > nb_streams) {
1706 REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams);
1707 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);
1708 REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams);
1709 REALLOCZ_ARRAY_STREAM(streams_with_closed_captions, nb_streams, fmt_ctx->nb_streams);
1710 REALLOCZ_ARRAY_STREAM(streams_with_film_grain, nb_streams, fmt_ctx->nb_streams);
1711 nb_streams = fmt_ctx->nb_streams;
1712 }
1713
2/2
✓ Branch 0 taken 8721 times.
✓ Branch 1 taken 86 times.
8807 if (selected_streams[pkt->stream_index]) {
1714 8721 AVRational tb = ifile->streams[pkt->stream_index].st->time_base;
1715
2/2
✓ Branch 0 taken 8628 times.
✓ Branch 1 taken 93 times.
8721 int64_t pts = pkt->pts != AV_NOPTS_VALUE ? pkt->pts : pkt->dts;
1716
1717
2/2
✓ Branch 0 taken 8628 times.
✓ Branch 1 taken 93 times.
8721 if (pts != AV_NOPTS_VALUE)
1718 8628 *cur_ts = av_rescale_q(pts, tb, AV_TIME_BASE_Q);
1719
1720
4/4
✓ Branch 0 taken 201 times.
✓ Branch 1 taken 8520 times.
✓ Branch 2 taken 109 times.
✓ Branch 3 taken 92 times.
8721 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
1721 109 start = *cur_ts;
1722 109 has_start = 1;
1723 }
1724
1725
6/6
✓ Branch 0 taken 8629 times.
✓ Branch 1 taken 92 times.
✓ Branch 2 taken 8613 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8612 times.
8721 if (has_start && !has_end && interval->end_is_offset) {
1726 1 end = start + interval->end;
1727 1 has_end = 1;
1728 }
1729
1730
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8718 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
8721 if (interval->end_is_offset && interval->duration_frames) {
1731
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (frame_count >= interval->end)
1732 4 break;
1733
5/6
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 8704 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 11 times.
8718 } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
1734 3 break;
1735 }
1736
1737 8717 frame_count++;
1738
2/2
✓ Branch 0 taken 5866 times.
✓ Branch 1 taken 2851 times.
8717 if (do_read_packets) {
1739
1/2
✓ Branch 0 taken 5866 times.
✗ Branch 1 not taken.
5866 if (do_show_packets)
1740 5866 show_packet(tfc, ifile, pkt, i++);
1741 5866 nb_streams_packets[pkt->stream_index]++;
1742 }
1743
2/2
✓ Branch 0 taken 3118 times.
✓ Branch 1 taken 5599 times.
8717 if (do_read_frames) {
1744 3118 int packet_new = 1;
1745 FrameData *fd;
1746
1747 3118 pkt->opaque_ref = av_buffer_allocz(sizeof(*fd));
1748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3118 times.
3118 if (!pkt->opaque_ref) {
1749 ret = AVERROR(ENOMEM);
1750 goto end;
1751 }
1752 3118 fd = (FrameData*)pkt->opaque_ref->data;
1753 3118 fd->pkt_pos = pkt->pos;
1754 3118 fd->pkt_size = pkt->size;
1755
1756
2/2
✓ Branch 1 taken 3138 times.
✓ Branch 2 taken 3118 times.
6256 while (process_frame(tfc, ifile, frame, pkt, &packet_new) > 0);
1757 }
1758 }
1759 8803 av_packet_unref(pkt);
1760 }
1761 115 av_packet_unref(pkt);
1762 //Flush remaining frames that are cached in the decoder
1763
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 115 times.
275 for (i = 0; i < ifile->nb_streams; i++) {
1764 160 pkt->stream_index = i;
1765
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 77 times.
160 if (do_read_frames) {
1766
2/2
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 83 times.
104 while (process_frame(tfc, ifile, frame, pkt, &(int){1}) > 0);
1767 }
1768 }
1769
1770 115 end:
1771 115 av_frame_free(&frame);
1772 115 av_packet_free(&pkt);
1773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if (ret < 0) {
1774 av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval ");
1775 log_read_interval(interval, NULL, AV_LOG_ERROR);
1776 }
1777 115 return ret;
1778 }
1779
1780 static void flush_buffers(InputFile *ifile)
1781 {
1782 int i;
1783
1784 if (!do_read_frames)
1785 return;
1786 for (i = 0; i < ifile->nb_streams; i++) {
1787 if (ifile->streams[i].dec_ctx)
1788 avcodec_flush_buffers(ifile->streams[i].dec_ctx);
1789 }
1790 }
1791
1792 115 static int read_packets(AVTextFormatContext *tfc, InputFile *ifile)
1793 {
1794 115 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
1795 115 int i, ret = 0;
1796 115 int64_t cur_ts = fmt_ctx->start_time;
1797
1798
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 4 times.
115 if (read_intervals_nb == 0) {
1799 111 ReadInterval interval = (ReadInterval) { .has_start = 0, .has_end = 0 };
1800 111 ret = read_interval_packets(tfc, ifile, &interval, &cur_ts);
1801 } else {
1802
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (i = 0; i < read_intervals_nb; i++) {
1803 /* flushing buffers can reset parts of the private context which may be
1804 * read by show_streams(), so only flush between each read_interval */
1805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (i)
1806 flush_buffers(ifile);
1807 4 ret = read_interval_packets(tfc, ifile, &read_intervals[i], &cur_ts);
1808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0)
1809 break;
1810 }
1811 }
1812
1813 115 return ret;
1814 }
1815
1816 289 static void print_dispositions(AVTextFormatContext *tfc, uint32_t disposition, SectionID section_id)
1817 {
1818 289 avtext_print_section_header(tfc, NULL, section_id);
1819
2/2
✓ Branch 0 taken 9248 times.
✓ Branch 1 taken 289 times.
9537 for (int i = 0; i < sizeof(disposition) * CHAR_BIT; i++) {
1820 9248 const char *disposition_str = av_disposition_to_string(1U << i);
1821
1822
2/2
✓ Branch 0 taken 5491 times.
✓ Branch 1 taken 3757 times.
9248 if (disposition_str)
1823 5491 print_int(disposition_str, !!(disposition & (1U << i)));
1824 }
1825 289 avtext_print_section_footer(tfc);
1826 289 }
1827
1828 #define IN_PROGRAM 1
1829 #define IN_STREAM_GROUP 2
1830
1831 379 static int show_stream(AVTextFormatContext *tfc, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int container)
1832 {
1833 379 AVStream *stream = ist->st;
1834 AVCodecParameters *par;
1835 AVCodecContext *dec_ctx;
1836 char val_str[128];
1837 const char *s;
1838 AVRational sar, dar;
1839 AVBPrint pbuf;
1840 const AVCodecDescriptor *cd;
1841 379 const SectionID section_header[] = {
1842 SECTION_ID_STREAM,
1843 SECTION_ID_PROGRAM_STREAM,
1844 SECTION_ID_STREAM_GROUP_STREAM,
1845 };
1846 379 const SectionID section_disposition[] = {
1847 SECTION_ID_STREAM_DISPOSITION,
1848 SECTION_ID_PROGRAM_STREAM_DISPOSITION,
1849 SECTION_ID_STREAM_GROUP_STREAM_DISPOSITION,
1850 };
1851 379 const SectionID section_tags[] = {
1852 SECTION_ID_STREAM_TAGS,
1853 SECTION_ID_PROGRAM_STREAM_TAGS,
1854 SECTION_ID_STREAM_GROUP_STREAM_TAGS,
1855 };
1856 379 int ret = 0;
1857 379 const char *profile = NULL;
1858
1859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 379 times.
379 av_assert0(container < FF_ARRAY_ELEMS(section_header));
1860
1861 379 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
1862
1863 379 avtext_print_section_header(tfc, NULL, section_header[container]);
1864
1865 379 print_int("index", stream->index);
1866
1867 379 par = stream->codecpar;
1868 379 dec_ctx = ist->dec_ctx;
1869
2/2
✓ Branch 1 taken 376 times.
✓ Branch 2 taken 3 times.
379 if (cd = avcodec_descriptor_get(par->codec_id)) {
1870 376 print_str("codec_name", cd->name);
1871
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 364 times.
376 if (!do_bitexact) {
1872
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 print_str("codec_long_name",
1873 cd->long_name ? cd->long_name : "unknown");
1874 }
1875 } else {
1876 3 print_str_opt("codec_name", "unknown");
1877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!do_bitexact) {
1878 print_str_opt("codec_long_name", "unknown");
1879 }
1880 }
1881
1882
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 367 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 1 times.
379 if (!do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
1883 11 print_str("profile", profile);
1884 else {
1885
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 267 times.
368 if (par->profile != AV_PROFILE_UNKNOWN) {
1886 char profile_num[12];
1887 101 snprintf(profile_num, sizeof(profile_num), "%d", par->profile);
1888 101 print_str("profile", profile_num);
1889 } else
1890 267 print_str_opt("profile", "unknown");
1891 }
1892
1893 379 s = av_get_media_type_string(par->codec_type);
1894
1/2
✓ Branch 0 taken 379 times.
✗ Branch 1 not taken.
379 if (s) print_str ("codec_type", s);
1895 else print_str_opt("codec_type", "unknown");
1896
1897 /* print AVI/FourCC tag */
1898 379 print_str("codec_tag_string", av_fourcc2str(par->codec_tag));
1899 379 print_fmt("codec_tag", "0x%04"PRIx32, par->codec_tag);
1900
1901 379 av_bprint_clear(&pbuf);
1902
2/2
✓ Branch 1 taken 223 times.
✓ Branch 2 taken 156 times.
379 if (!av_mime_codec_str(par, stream->avg_frame_rate, &pbuf))
1903 223 print_str("mime_codec_string", pbuf.str);
1904
1905
4/4
✓ Branch 0 taken 106 times.
✓ Branch 1 taken 259 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 7 times.
379 switch (par->codec_type) {
1906 106 case AVMEDIA_TYPE_VIDEO:
1907 106 print_int("width", par->width);
1908 106 print_int("height", par->height);
1909
1/2
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
106 if (dec_ctx) {
1910 106 print_int("coded_width", dec_ctx->coded_width);
1911 106 print_int("coded_height", dec_ctx->coded_height);
1912
1913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if (do_analyze_frames) {
1914 print_int("closed_captions", streams_with_closed_captions[stream->index]);
1915 print_int("film_grain", streams_with_film_grain[stream->index]);
1916 }
1917 }
1918 106 print_int("has_b_frames", par->video_delay);
1919 106 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
1920
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 33 times.
106 if (sar.num) {
1921 73 print_q("sample_aspect_ratio", sar, ':');
1922 73 av_reduce(&dar.num, &dar.den,
1923 73 (int64_t) par->width * sar.num,
1924 73 (int64_t) par->height * sar.den,
1925 1024*1024);
1926 73 print_q("display_aspect_ratio", dar, ':');
1927 } else {
1928 33 print_str_opt("sample_aspect_ratio", "N/A");
1929 33 print_str_opt("display_aspect_ratio", "N/A");
1930 }
1931 106 print_pixel_format(tfc, par->format);
1932 106 print_int("level", par->level);
1933
1934 106 print_color_range(tfc, par->color_range);
1935 106 print_color_space(tfc, par->color_space);
1936 106 print_color_trc(tfc, par->color_trc);
1937 106 print_primaries(tfc, par->color_primaries);
1938 106 print_chroma_location(tfc, par->chroma_location);
1939
1940
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 77 times.
106 if (par->field_order == AV_FIELD_PROGRESSIVE)
1941 29 print_str("field_order", "progressive");
1942
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 68 times.
77 else if (par->field_order == AV_FIELD_TT)
1943 9 print_str("field_order", "tt");
1944
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 67 times.
68 else if (par->field_order == AV_FIELD_BB)
1945 1 print_str("field_order", "bb");
1946
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 else if (par->field_order == AV_FIELD_TB)
1947 print_str("field_order", "tb");
1948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 else if (par->field_order == AV_FIELD_BT)
1949 print_str("field_order", "bt");
1950 else
1951 67 print_str_opt("field_order", "unknown");
1952
1953
3/4
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 82 times.
106 if (dec_ctx && do_read_frames)
1954 24 print_int("refs", dec_ctx->refs);
1955 106 break;
1956
1957 259 case AVMEDIA_TYPE_AUDIO:
1958 259 s = av_get_sample_fmt_name(par->format);
1959
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 if (s) print_str ("sample_fmt", s);
1960 else print_str_opt("sample_fmt", "unknown");
1961 259 print_val("sample_rate", par->sample_rate, unit_hertz_str);
1962 259 print_int("channels", par->ch_layout.nb_channels);
1963
1964
2/2
✓ Branch 0 taken 233 times.
✓ Branch 1 taken 26 times.
259 if (par->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
1965 233 av_channel_layout_describe(&par->ch_layout, val_str, sizeof(val_str));
1966 233 print_str ("channel_layout", val_str);
1967 } else {
1968 26 print_str_opt("channel_layout", "unknown");
1969 }
1970
1971 259 print_int("bits_per_sample", av_get_bits_per_sample(par->codec_id));
1972
1973 259 print_int("initial_padding", par->initial_padding);
1974 259 break;
1975
1976 7 case AVMEDIA_TYPE_SUBTITLE:
1977
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (par->width)
1978 print_int("width", par->width);
1979 else
1980 7 print_str_opt("width", "N/A");
1981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (par->height)
1982 print_int("height", par->height);
1983 else
1984 7 print_str_opt("height", "N/A");
1985 7 break;
1986 }
1987
1988
2/2
✓ Branch 0 taken 376 times.
✓ Branch 1 taken 3 times.
379 if (show_private_data) {
1989
4/4
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 303 times.
✓ Branch 3 taken 64 times.
376 if (dec_ctx && dec_ctx->codec->priv_class)
1990 303 print_private_data(tfc, dec_ctx->priv_data);
1991
2/2
✓ Branch 0 taken 182 times.
✓ Branch 1 taken 194 times.
376 if (fmt_ctx->iformat->priv_class)
1992 182 print_private_data(tfc, fmt_ctx->priv_data);
1993 }
1994
1995
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 143 times.
379 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
1996 143 else print_str_opt("id", "N/A");
1997 379 print_q("r_frame_rate", stream->r_frame_rate, '/');
1998 379 print_q("avg_frame_rate", stream->avg_frame_rate, '/');
1999 379 print_q("time_base", stream->time_base, '/');
2000 379 print_ts ("start_pts", stream->start_time);
2001 379 print_time("start_time", stream->start_time, &stream->time_base);
2002 379 print_ts ("duration_ts", stream->duration);
2003 379 print_time("duration", stream->duration, &stream->time_base);
2004
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 294 times.
379 if (par->bit_rate > 0) print_val ("bit_rate", par->bit_rate, unit_bit_per_second_str);
2005 294 else print_str_opt("bit_rate", "N/A");
2006
3/4
✓ Branch 0 taken 370 times.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 370 times.
379 if (dec_ctx && dec_ctx->rc_max_rate > 0)
2007 print_val ("max_bit_rate", dec_ctx->rc_max_rate, unit_bit_per_second_str);
2008 else
2009 379 print_str_opt("max_bit_rate", "N/A");
2010
4/4
✓ Branch 0 taken 370 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 200 times.
✓ Branch 3 taken 170 times.
379 if (dec_ctx && dec_ctx->bits_per_raw_sample > 0) print_fmt("bits_per_raw_sample", "%d", dec_ctx->bits_per_raw_sample);
2011 179 else print_str_opt("bits_per_raw_sample", "N/A");
2012
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 327 times.
379 if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
2013 327 else print_str_opt("nb_frames", "N/A");
2014
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 343 times.
379 if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
2015 343 else print_str_opt("nb_read_frames", "N/A");
2016
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 290 times.
379 if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
2017 290 else print_str_opt("nb_read_packets", "N/A");
2018
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 379 times.
379 if (do_show_data)
2019 avtext_print_data(tfc, "extradata", par->extradata,
2020 par->extradata_size);
2021
2022
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 129 times.
379 if (par->extradata_size > 0) {
2023 250 print_int("extradata_size", par->extradata_size);
2024 250 avtext_print_data_hash(tfc, "extradata_hash", par->extradata,
2025 par->extradata_size);
2026 }
2027
2028 /* Print disposition information */
2029
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 103 times.
379 if (do_show_stream_disposition) {
2030
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 276 times.
276 av_assert0(container < FF_ARRAY_ELEMS(section_disposition));
2031 276 print_dispositions(tfc, stream->disposition, section_disposition[container]);
2032 }
2033
2034
2/2
✓ Branch 0 taken 97 times.
✓ Branch 1 taken 282 times.
379 if (do_show_stream_tags) {
2035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 97 times.
97 av_assert0(container < FF_ARRAY_ELEMS(section_tags));
2036 97 ret = show_tags(tfc, stream->metadata, section_tags[container]);
2037 }
2038
2039
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 340 times.
379 if (stream->codecpar->nb_coded_side_data) {
2040 39 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_SIDE_DATA_LIST);
2041
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++) {
2042 54 print_pkt_side_data(tfc, stream->codecpar->width, stream->codecpar->height, &stream->codecpar->coded_side_data[i],
2043 SECTION_ID_STREAM_SIDE_DATA);
2044 54 avtext_print_section_footer(tfc);
2045 }
2046 39 avtext_print_section_footer(tfc);
2047 }
2048
2049 379 avtext_print_section_footer(tfc);
2050 379 av_bprint_finalize(&pbuf, NULL);
2051 379 fflush(stdout);
2052
2053 379 return ret;
2054 }
2055
2056 120 static int show_streams(AVTextFormatContext *tfc, InputFile *ifile)
2057 {
2058 120 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2059 120 int i, ret = 0;
2060
2061 120 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAMS);
2062
2/2
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 120 times.
346 for (i = 0; i < ifile->nb_streams; i++)
2063
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 10 times.
226 if (selected_streams[i]) {
2064 216 ret = show_stream(tfc, fmt_ctx, i, &ifile->streams[i], 0);
2065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if (ret < 0)
2066 break;
2067 }
2068 120 avtext_print_section_footer(tfc);
2069
2070 120 return ret;
2071 }
2072
2073 3 static int show_program(AVTextFormatContext *tfc, InputFile *ifile, AVProgram *program)
2074 {
2075 3 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2076 3 int i, ret = 0;
2077
2078 3 avtext_print_section_header(tfc, NULL, SECTION_ID_PROGRAM);
2079 3 print_int("program_id", program->id);
2080 3 print_int("program_num", program->program_num);
2081 3 print_int("nb_streams", program->nb_stream_indexes);
2082 3 print_int("pmt_pid", program->pmt_pid);
2083 3 print_int("pcr_pid", program->pcr_pid);
2084
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (do_show_program_tags)
2085 ret = show_tags(tfc, program->metadata, SECTION_ID_PROGRAM_TAGS);
2086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
2087 goto end;
2088
2089 3 avtext_print_section_header(tfc, NULL, SECTION_ID_PROGRAM_STREAMS);
2090
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (i = 0; i < program->nb_stream_indexes; i++) {
2091
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (selected_streams[program->stream_index[i]]) {
2092 8 ret = show_stream(tfc, fmt_ctx, program->stream_index[i], &ifile->streams[program->stream_index[i]], IN_PROGRAM);
2093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
2094 break;
2095 }
2096 }
2097 3 avtext_print_section_footer(tfc);
2098
2099 3 end:
2100 3 avtext_print_section_footer(tfc);
2101 3 return ret;
2102 }
2103
2104 84 static int show_programs(AVTextFormatContext *tfc, InputFile *ifile)
2105 {
2106 84 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2107 84 int i, ret = 0;
2108
2109 84 avtext_print_section_header(tfc, NULL, SECTION_ID_PROGRAMS);
2110
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 84 times.
87 for (i = 0; i < fmt_ctx->nb_programs; i++) {
2111 3 AVProgram *program = fmt_ctx->programs[i];
2112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!program)
2113 continue;
2114 3 ret = show_program(tfc, ifile, program);
2115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
2116 break;
2117 }
2118 84 avtext_print_section_footer(tfc);
2119 84 return ret;
2120 }
2121
2122 3 static void print_tile_grid_params(AVTextFormatContext *tfc, const AVStreamGroup *stg,
2123 const AVStreamGroupTileGrid *tile_grid)
2124 {
2125 3 avtext_print_section_header(tfc, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
2126 3 print_int("nb_tiles", tile_grid->nb_tiles);
2127 3 print_int("coded_width", tile_grid->coded_width);
2128 3 print_int("coded_height", tile_grid->coded_height);
2129 3 print_int("horizontal_offset", tile_grid->horizontal_offset);
2130 3 print_int("vertical_offset", tile_grid->vertical_offset);
2131 3 print_int("width", tile_grid->width);
2132 3 print_int("height", tile_grid->height);
2133 3 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
2134
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 for (int i = 0; i < tile_grid->nb_tiles; i++) {
2135 8 avtext_print_section_header(tfc, "tile_offset", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2136 8 print_int("stream_index", tile_grid->offsets[i].idx);
2137 8 print_int("tile_horizontal_offset", tile_grid->offsets[i].horizontal);
2138 8 print_int("tile_vertical_offset", tile_grid->offsets[i].vertical);
2139 8 avtext_print_section_footer(tfc);
2140 }
2141 3 avtext_print_section_footer(tfc);
2142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (tile_grid->nb_coded_side_data) {
2143 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SIDE_DATA_LIST);
2144 for (int i = 0; i < tile_grid->nb_coded_side_data; i++) {
2145 print_pkt_side_data(tfc, tile_grid->width, tile_grid->height, &tile_grid->coded_side_data[i],
2146 SECTION_ID_STREAM_GROUP_SIDE_DATA);
2147 avtext_print_section_footer(tfc);
2148 }
2149 avtext_print_section_footer(tfc);
2150 }
2151 3 avtext_print_section_footer(tfc);
2152 3 }
2153
2154 46 static void print_iamf_param_definition(AVTextFormatContext *tfc, const char *name,
2155 const AVIAMFParamDefinition *param, SectionID section_id)
2156 {
2157 SectionID subsection_id, parameter_section_id;
2158 46 subsection_id = sections[section_id].children_ids[0];
2159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 av_assert0(subsection_id != -1);
2160 46 parameter_section_id = sections[subsection_id].children_ids[0];
2161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 av_assert0(parameter_section_id != -1);
2162 46 avtext_print_section_header(tfc, "IAMF Param Definition", section_id);
2163 46 print_str("name", name);
2164 46 print_int("nb_subblocks", param->nb_subblocks);
2165 46 print_int("type", param->type);
2166 46 print_int("parameter_id", param->parameter_id);
2167 46 print_int("parameter_rate", param->parameter_rate);
2168 46 print_int("duration", param->duration);
2169 46 print_int("constant_subblock_duration", param->constant_subblock_duration);
2170
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 37 times.
46 if (param->nb_subblocks > 0)
2171 9 avtext_print_section_header(tfc, NULL, subsection_id);
2172
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 46 times.
55 for (int i = 0; i < param->nb_subblocks; i++) {
2173 9 const void *subblock = av_iamf_param_definition_get_subblock(param, i);
2174
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
9 switch(param->type) {
2175 case AV_IAMF_PARAMETER_DEFINITION_MIX_GAIN: {
2176 const AVIAMFMixGain *mix = subblock;
2177 avtext_print_section_header(tfc, "IAMF Mix Gain Parameters", parameter_section_id);
2178 print_int("subblock_duration", mix->subblock_duration);
2179 print_int("animation_type", mix->animation_type);
2180 print_q("start_point_value", mix->start_point_value, '/');
2181 print_q("end_point_value", mix->end_point_value, '/');
2182 print_q("control_point_value", mix->control_point_value, '/');
2183 print_q("control_point_relative_time", mix->control_point_relative_time, '/');
2184 avtext_print_section_footer(tfc); // parameter_section_id
2185 break;
2186 }
2187 7 case AV_IAMF_PARAMETER_DEFINITION_DEMIXING: {
2188 7 const AVIAMFDemixingInfo *demix = subblock;
2189 7 avtext_print_section_header(tfc, "IAMF Demixing Info", parameter_section_id);
2190 7 print_int("subblock_duration", demix->subblock_duration);
2191 7 print_int("dmixp_mode", demix->dmixp_mode);
2192 7 avtext_print_section_footer(tfc); // parameter_section_id
2193 7 break;
2194 }
2195 2 case AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN: {
2196 2 const AVIAMFReconGain *recon = subblock;
2197 2 avtext_print_section_header(tfc, "IAMF Recon Gain", parameter_section_id);
2198 2 print_int("subblock_duration", recon->subblock_duration);
2199 2 avtext_print_section_footer(tfc); // parameter_section_id
2200 2 break;
2201 }
2202 }
2203 }
2204
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 37 times.
46 if (param->nb_subblocks > 0)
2205 9 avtext_print_section_footer(tfc); // subsection_id
2206 46 avtext_print_section_footer(tfc); // section_id
2207 46 }
2208
2209 17 static void print_iamf_audio_element_params(AVTextFormatContext *tfc, const AVStreamGroup *stg,
2210 const AVIAMFAudioElement *audio_element)
2211 {
2212 AVBPrint pbuf;
2213
2214 17 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2215
2216 17 avtext_print_section_header(tfc, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
2217 17 print_int("nb_layers", audio_element->nb_layers);
2218 17 print_int("audio_element_type", audio_element->audio_element_type);
2219 17 print_int("default_w", audio_element->default_w);
2220 17 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
2221
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 17 times.
51 for (int i = 0; i < audio_element->nb_layers; i++) {
2222 34 const AVIAMFLayer *layer = audio_element->layers[i];
2223 char val_str[128];
2224 34 avtext_print_section_header(tfc, "IAMF Audio Layer", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2225 34 av_channel_layout_describe(&layer->ch_layout, val_str, sizeof(val_str));
2226 34 print_str("channel_layout", val_str);
2227
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) {
2228 29 print_int("output_gain_flags", layer->output_gain_flags);
2229 29 print_q("output_gain", layer->output_gain, '/');
2230
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) {
2231 5 print_int("ambisonics_mode", layer->ambisonics_mode);
2232
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 if (layer->ambisonics_mode == AV_IAMF_AMBISONICS_MODE_PROJECTION)
2233
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,
2234 layer->demixing_matrix[idx].den);
2235 }
2236 34 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
2237 }
2238
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 10 times.
17 if (audio_element->demixing_info)
2239 7 print_iamf_param_definition(tfc, "demixing_info", audio_element->demixing_info,
2240 SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2241
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 15 times.
17 if (audio_element->recon_gain_info)
2242 2 print_iamf_param_definition(tfc, "recon_gain_info", audio_element->recon_gain_info,
2243 SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2244 17 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENTS
2245 17 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_COMPONENT
2246
2247 17 av_bprint_finalize(&pbuf, NULL);
2248 17 }
2249
2250 18 static void print_iamf_submix_params(AVTextFormatContext *tfc, const AVIAMFSubmix *submix)
2251 {
2252 18 avtext_print_section_header(tfc, "IAMF Submix", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2253 18 print_int("nb_elements", submix->nb_elements);
2254 18 print_int("nb_layouts", submix->nb_layouts);
2255 18 print_q("default_mix_gain", submix->default_mix_gain, '/');
2256 18 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_PIECES);
2257
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 18 times.
37 for (int i = 0; i < submix->nb_elements; i++) {
2258 19 const AVIAMFSubmixElement *element = submix->elements[i];
2259 19 avtext_print_section_header(tfc, "IAMF Submix Element", SECTION_ID_STREAM_GROUP_PIECE);
2260 19 print_int("stream_id", element->audio_element_id);
2261 19 print_q("default_mix_gain", element->default_mix_gain, '/');
2262 19 print_int("headphones_rendering_mode", element->headphones_rendering_mode);
2263 19 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SUBPIECES);
2264
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 if (element->annotations) {
2265 19 const AVDictionaryEntry *annotation = NULL;
2266 19 avtext_print_section_header(tfc, "IAMF Annotations", SECTION_ID_STREAM_GROUP_SUBPIECE);
2267
2/2
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 19 times.
38 while (annotation = av_dict_iterate(element->annotations, annotation))
2268 19 print_str(annotation->key, annotation->value);
2269 19 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBPIECE
2270 }
2271
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 if (element->element_mix_config)
2272 19 print_iamf_param_definition(tfc, "element_mix_config", element->element_mix_config,
2273 SECTION_ID_STREAM_GROUP_SUBPIECE);
2274 19 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBPIECES
2275 19 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_PIECE
2276 }
2277
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (submix->output_mix_config)
2278 18 print_iamf_param_definition(tfc, "output_mix_config", submix->output_mix_config,
2279 SECTION_ID_STREAM_GROUP_PIECE);
2280
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for (int i = 0; i < submix->nb_layouts; i++) {
2281 36 const AVIAMFSubmixLayout *layout = submix->layouts[i];
2282 char val_str[128];
2283 36 avtext_print_section_header(tfc, "IAMF Submix Layout", SECTION_ID_STREAM_GROUP_PIECE);
2284 36 av_channel_layout_describe(&layout->sound_system, val_str, sizeof(val_str));
2285 36 print_str("sound_system", val_str);
2286 36 print_q("integrated_loudness", layout->integrated_loudness, '/');
2287 36 print_q("digital_peak", layout->digital_peak, '/');
2288 36 print_q("true_peak", layout->true_peak, '/');
2289 36 print_q("dialogue_anchored_loudness", layout->dialogue_anchored_loudness, '/');
2290 36 print_q("album_anchored_loudness", layout->album_anchored_loudness, '/');
2291 36 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_PIECE
2292 }
2293 18 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_PIECES
2294 18 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
2295 18 }
2296
2297 16 static void print_iamf_mix_presentation_params(AVTextFormatContext *tfc, const AVStreamGroup *stg,
2298 const AVIAMFMixPresentation *mix_presentation)
2299 {
2300 16 avtext_print_section_header(tfc, stg, SECTION_ID_STREAM_GROUP_COMPONENT);
2301 16 print_int("nb_submixes", mix_presentation->nb_submixes);
2302 16 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_SUBCOMPONENTS);
2303
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (mix_presentation->annotations) {
2304 16 const AVDictionaryEntry *annotation = NULL;
2305 16 avtext_print_section_header(tfc, "IAMF Annotations", SECTION_ID_STREAM_GROUP_SUBCOMPONENT);
2306
2/2
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 16 times.
32 while (annotation = av_dict_iterate(mix_presentation->annotations, annotation))
2307 16 print_str(annotation->key, annotation->value);
2308 16 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENT
2309 }
2310
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 16 times.
34 for (int i = 0; i < mix_presentation->nb_submixes; i++)
2311 18 print_iamf_submix_params(tfc, mix_presentation->submixes[i]);
2312 16 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_SUBCOMPONENTS
2313 16 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_COMPONENT
2314 16 }
2315
2316 36 static void print_stream_group_params(AVTextFormatContext *tfc, AVStreamGroup *stg)
2317 {
2318 36 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_COMPONENTS);
2319
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 33 times.
36 if (stg->type == AV_STREAM_GROUP_PARAMS_TILE_GRID)
2320 3 print_tile_grid_params(tfc, stg, stg->params.tile_grid);
2321
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 16 times.
33 else if (stg->type == AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT)
2322 17 print_iamf_audio_element_params(tfc, stg, stg->params.iamf_audio_element);
2323
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 else if (stg->type == AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION)
2324 16 print_iamf_mix_presentation_params(tfc, stg, stg->params.iamf_mix_presentation);
2325 36 avtext_print_section_footer(tfc); // SECTION_ID_STREAM_GROUP_COMPONENTS
2326 36 }
2327
2328 36 static int show_stream_group(AVTextFormatContext *tfc, InputFile *ifile, AVStreamGroup *stg)
2329 {
2330 36 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2331 AVBPrint pbuf;
2332 36 int i, ret = 0;
2333
2334 36 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2335 36 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP);
2336 36 print_int("index", stg->index);
2337
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%"PRIx64, stg->id);
2338 else print_str_opt("id", "N/A");
2339 36 print_int("nb_streams", stg->nb_streams);
2340
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if (stg->type != AV_STREAM_GROUP_PARAMS_NONE)
2341 36 print_str("type", av_x_if_null(avformat_stream_group_name(stg->type), "unknown"));
2342 else
2343 print_str_opt("type", "unknown");
2344
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if (do_show_stream_group_components)
2345 36 print_stream_group_params(tfc, stg);
2346
2347 /* Print disposition information */
2348
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 23 times.
36 if (do_show_stream_group_disposition)
2349 13 print_dispositions(tfc, stg->disposition, SECTION_ID_STREAM_GROUP_DISPOSITION);
2350
2351
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 23 times.
36 if (do_show_stream_group_tags)
2352 13 ret = show_tags(tfc, stg->metadata, SECTION_ID_STREAM_GROUP_TAGS);
2353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (ret < 0)
2354 goto end;
2355
2356 36 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUP_STREAMS);
2357
2/2
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 36 times.
191 for (i = 0; i < stg->nb_streams; i++) {
2358
1/2
✓ Branch 0 taken 155 times.
✗ Branch 1 not taken.
155 if (selected_streams[stg->streams[i]->index]) {
2359 155 ret = show_stream(tfc, fmt_ctx, stg->streams[i]->index, &ifile->streams[stg->streams[i]->index], IN_STREAM_GROUP);
2360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 155 times.
155 if (ret < 0)
2361 break;
2362 }
2363 }
2364 36 avtext_print_section_footer(tfc);
2365
2366 36 end:
2367 36 av_bprint_finalize(&pbuf, NULL);
2368 36 avtext_print_section_footer(tfc);
2369 36 return ret;
2370 }
2371
2372 102 static int show_stream_groups(AVTextFormatContext *tfc, InputFile *ifile)
2373 {
2374 102 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2375 102 int i, ret = 0;
2376
2377 102 avtext_print_section_header(tfc, NULL, SECTION_ID_STREAM_GROUPS);
2378
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 102 times.
138 for (i = 0; i < fmt_ctx->nb_stream_groups; i++) {
2379 36 AVStreamGroup *stg = fmt_ctx->stream_groups[i];
2380
2381 36 ret = show_stream_group(tfc, ifile, stg);
2382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (ret < 0)
2383 break;
2384 }
2385 102 avtext_print_section_footer(tfc);
2386 102 return ret;
2387 }
2388
2389 5 static int show_chapters(AVTextFormatContext *tfc, InputFile *ifile)
2390 {
2391 5 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2392 5 int i, ret = 0;
2393
2394 5 avtext_print_section_header(tfc, NULL, SECTION_ID_CHAPTERS);
2395
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 5 times.
27 for (i = 0; i < fmt_ctx->nb_chapters; i++) {
2396 22 AVChapter *chapter = fmt_ctx->chapters[i];
2397
2398 22 avtext_print_section_header(tfc, NULL, SECTION_ID_CHAPTER);
2399 22 print_int("id", chapter->id);
2400 22 print_q ("time_base", chapter->time_base, '/');
2401 22 print_int("start", chapter->start);
2402 22 print_time("start_time", chapter->start, &chapter->time_base);
2403 22 print_int("end", chapter->end);
2404 22 print_time("end_time", chapter->end, &chapter->time_base);
2405
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (do_show_chapter_tags)
2406 22 ret = show_tags(tfc, chapter->metadata, SECTION_ID_CHAPTER_TAGS);
2407 22 avtext_print_section_footer(tfc);
2408 }
2409 5 avtext_print_section_footer(tfc);
2410
2411 5 return ret;
2412 }
2413
2414 42 static int show_format(AVTextFormatContext *tfc, InputFile *ifile)
2415 {
2416 42 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2417
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
2418 42 int ret = 0;
2419
2420 42 avtext_print_section_header(tfc, NULL, SECTION_ID_FORMAT);
2421 42 print_str_validate("filename", fmt_ctx->url);
2422 42 print_int("nb_streams", fmt_ctx->nb_streams);
2423 42 print_int("nb_programs", fmt_ctx->nb_programs);
2424 42 print_int("nb_stream_groups", fmt_ctx->nb_stream_groups);
2425 42 print_str("format_name", fmt_ctx->iformat->name);
2426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (!do_bitexact) {
2427 if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
2428 else print_str_opt("format_long_name", "unknown");
2429 }
2430 42 print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
2431 42 print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
2432
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if (size >= 0) print_val ("size", size, unit_byte_str);
2433 else print_str_opt("size", "N/A");
2434
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 1 times.
42 if (fmt_ctx->bit_rate > 0) print_val ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
2435 1 else print_str_opt("bit_rate", "N/A");
2436 42 print_int("probe_score", fmt_ctx->probe_score);
2437
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 8 times.
42 if (do_show_format_tags)
2438 34 ret = show_tags(tfc, fmt_ctx->metadata, SECTION_ID_FORMAT_TAGS);
2439
2440 42 avtext_print_section_footer(tfc);
2441 42 fflush(stdout);
2442 42 return ret;
2443 }
2444
2445 static void show_error(AVTextFormatContext *tfc, int err)
2446 {
2447 avtext_print_section_header(tfc, NULL, SECTION_ID_ERROR);
2448 print_int("code", err);
2449 print_str("string", av_err2str(err));
2450 avtext_print_section_footer(tfc);
2451 }
2452
2453 792 static int get_decoder_by_name(const char *codec_name, const AVCodec **codec)
2454 {
2455
1/2
✓ Branch 0 taken 792 times.
✗ Branch 1 not taken.
792 if (codec_name == NULL)
2456 792 return 0;
2457
2458 *codec = avcodec_find_decoder_by_name(codec_name);
2459 if (*codec == NULL) {
2460 av_log(NULL, AV_LOG_ERROR,
2461 "No codec could be found with name '%s'\n", codec_name);
2462 return AVERROR(EINVAL);
2463 }
2464 return 0;
2465 }
2466
2467 198 static int set_decoders(AVFormatContext *fmt_ctx)
2468 {
2469 int ret;
2470
2471 #define GET_DECODER(type_) \
2472 ret = get_decoder_by_name(type_##_codec_name, &fmt_ctx->type_##_codec); \
2473 if (ret < 0) return ret;
2474
2475
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 GET_DECODER(audio);
2476
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 GET_DECODER(data);
2477
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 GET_DECODER(subtitle);
2478
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 GET_DECODER(video);
2479 198 return 0;
2480 }
2481
2482 378 static const AVCodec *get_decoder_for_stream(AVFormatContext *fmt_ctx, AVStream *stream)
2483 {
2484 378 const AVCodec *codec = NULL;
2485
5/5
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 198 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 2 times.
378 switch (stream->codecpar->codec_type) {
2486 156 case AVMEDIA_TYPE_VIDEO: codec = fmt_ctx->video_codec; break;
2487 198 case AVMEDIA_TYPE_AUDIO: codec = fmt_ctx->audio_codec; break;
2488 9 case AVMEDIA_TYPE_SUBTITLE: codec = fmt_ctx->subtitle_codec; break;
2489 13 case AVMEDIA_TYPE_DATA: codec = fmt_ctx->data_codec; break;
2490 }
2491
2492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 378 times.
378 if (codec != NULL)
2493 return codec;
2494
2495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 378 times.
378 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
2496 av_log(NULL, AV_LOG_WARNING,
2497 "Failed to probe codec for input stream %d\n", stream->index);
2498 return NULL;
2499 }
2500
2501 378 codec = avcodec_find_decoder(stream->codecpar->codec_id);
2502
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 359 times.
378 if (codec == NULL) {
2503 19 av_log(NULL, AV_LOG_WARNING,
2504 "Unsupported codec with id %d for input stream %d\n",
2505 19 stream->codecpar->codec_id, stream->index);
2506 19 return NULL;
2507 }
2508
2509 359 return codec;
2510 }
2511
2512 198 static int open_input_file(InputFile *ifile, const char *filename,
2513 const char *print_filename)
2514 {
2515 int err, i;
2516 198 AVFormatContext *fmt_ctx = NULL;
2517 198 const AVDictionaryEntry *t = NULL;
2518 198 int scan_all_pmts_set = 0;
2519
2520 198 fmt_ctx = avformat_alloc_context();
2521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (!fmt_ctx)
2522 return AVERROR(ENOMEM);
2523
2524 198 err = set_decoders(fmt_ctx);
2525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (err < 0)
2526 return err;
2527
1/2
✓ Branch 1 taken 198 times.
✗ Branch 2 not taken.
198 if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2528 198 av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
2529 198 scan_all_pmts_set = 1;
2530 }
2531
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 if ((err = avformat_open_input(&fmt_ctx, filename,
2532 iformat, &format_opts)) < 0) {
2533 print_error(filename, err);
2534 return err;
2535 }
2536
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 182 times.
198 if (print_filename) {
2537 16 av_freep(&fmt_ctx->url);
2538 16 fmt_ctx->url = av_strdup(print_filename);
2539 }
2540 198 ifile->fmt_ctx = fmt_ctx;
2541
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
198 if (scan_all_pmts_set)
2542 198 av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2543
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 while ((t = av_dict_iterate(format_opts, t)))
2544 av_log(NULL, AV_LOG_WARNING, "Option %s skipped - not known to demuxer.\n", t->key);
2545
2546
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
198 if (find_stream_info) {
2547 AVDictionary **opts;
2548 198 int orig_nb_streams = fmt_ctx->nb_streams;
2549
2550 198 err = setup_find_stream_info_opts(fmt_ctx, codec_opts, &opts);
2551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (err < 0)
2552 return err;
2553
2554 198 err = avformat_find_stream_info(fmt_ctx, opts);
2555
2556
2/2
✓ Branch 0 taken 356 times.
✓ Branch 1 taken 198 times.
554 for (i = 0; i < orig_nb_streams; i++)
2557 356 av_dict_free(&opts[i]);
2558 198 av_freep(&opts);
2559
2560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (err < 0) {
2561 print_error(filename, err);
2562 return err;
2563 }
2564 }
2565
2566 198 av_dump_format(fmt_ctx, 0, filename, 0);
2567
2568 198 ifile->streams = av_calloc(fmt_ctx->nb_streams, sizeof(*ifile->streams));
2569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (!ifile->streams)
2570 exit(1);
2571 198 ifile->nb_streams = fmt_ctx->nb_streams;
2572
2573 /* bind a decoder to each input stream */
2574
2/2
✓ Branch 0 taken 378 times.
✓ Branch 1 taken 198 times.
576 for (i = 0; i < fmt_ctx->nb_streams; i++) {
2575 378 InputStream *ist = &ifile->streams[i];
2576 378 AVStream *stream = fmt_ctx->streams[i];
2577 const AVCodec *codec;
2578
2579 378 ist->st = stream;
2580
2581 378 codec = get_decoder_for_stream(fmt_ctx, stream);
2582
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 359 times.
378 if (!codec)
2583 19 continue;
2584
2585 {
2586 AVDictionary *opts;
2587
2588 359 err = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
2589 fmt_ctx, stream, codec, &opts, NULL);
2590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
359 if (err < 0)
2591 exit(1);
2592
2593 359 ist->dec_ctx = avcodec_alloc_context3(codec);
2594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
359 if (!ist->dec_ctx)
2595 exit(1);
2596
2597 359 err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
2598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
359 if (err < 0)
2599 exit(1);
2600
2601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
359 if (do_show_log) {
2602 // For logging it is needed to disable at least frame threads as otherwise
2603 // the log information would need to be reordered and matches up to contexts and frames
2604 // That is in fact possible but not trivial
2605 av_dict_set(&codec_opts, "threads", "1", 0);
2606 }
2607
2608 359 av_dict_set(&opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
2609
2610 359 ist->dec_ctx->pkt_timebase = stream->time_base;
2611
2612
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 359 times.
359 if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) {
2613 av_log(NULL, AV_LOG_WARNING, "Could not open codec for input stream %d\n",
2614 stream->index);
2615 exit(1);
2616 }
2617
2618
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 359 times.
359 if ((t = av_dict_iterate(opts, NULL))) {
2619 av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
2620 t->key, stream->index);
2621 return AVERROR_OPTION_NOT_FOUND;
2622 }
2623 }
2624 }
2625
2626 198 ifile->fmt_ctx = fmt_ctx;
2627 198 return 0;
2628 }
2629
2630 198 static void close_input_file(InputFile *ifile)
2631 {
2632 int i;
2633
2634 /* close decoder for each stream */
2635
2/2
✓ Branch 0 taken 378 times.
✓ Branch 1 taken 198 times.
576 for (i = 0; i < ifile->nb_streams; i++)
2636 378 avcodec_free_context(&ifile->streams[i].dec_ctx);
2637
2638 198 av_freep(&ifile->streams);
2639 198 ifile->nb_streams = 0;
2640
2641 198 avformat_close_input(&ifile->fmt_ctx);
2642 198 }
2643
2644 198 static int probe_file(AVTextFormatContext *tfc, const char *filename,
2645 const char *print_filename)
2646 {
2647 198 InputFile ifile = { 0 };
2648 int ret, i;
2649 int section_id;
2650
2651
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
198 do_analyze_frames = do_analyze_frames && do_show_streams;
2652
4/6
✓ Branch 0 taken 143 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 143 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 143 times.
198 do_read_frames = do_show_frames || do_count_frames || do_analyze_frames;
2653
3/4
✓ Branch 0 taken 127 times.
✓ Branch 1 taken 71 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 127 times.
198 do_read_packets = do_show_packets || do_count_packets;
2654
2655 198 ret = open_input_file(&ifile, filename, print_filename);
2656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (ret < 0)
2657 goto end;
2658
2659 #define CHECK_END if (ret < 0) goto end
2660
2661 198 nb_streams = ifile.fmt_ctx->nb_streams;
2662
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);
2663
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);
2664
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams);
2665
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 REALLOCZ_ARRAY_STREAM(streams_with_closed_captions,0,ifile.fmt_ctx->nb_streams);
2666
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 REALLOCZ_ARRAY_STREAM(streams_with_film_grain,0,ifile.fmt_ctx->nb_streams);
2667
2668
2/2
✓ Branch 0 taken 378 times.
✓ Branch 1 taken 198 times.
576 for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
2669
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 327 times.
378 if (stream_specifier) {
2670 51 ret = avformat_match_stream_specifier(ifile.fmt_ctx,
2671 51 ifile.fmt_ctx->streams[i],
2672 stream_specifier);
2673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 CHECK_END;
2674 else
2675 51 selected_streams[i] = ret;
2676 51 ret = 0;
2677 } else {
2678 327 selected_streams[i] = 1;
2679 }
2680
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 359 times.
378 if (!selected_streams[i])
2681 19 ifile.fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
2682 }
2683
2684
4/4
✓ Branch 0 taken 143 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 83 times.
198 if (do_read_frames || do_read_packets) {
2685
4/4
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 44 times.
115 if (do_show_frames && do_show_packets &&
2686
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
11 tfc->formatter->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT)
2687 5 section_id = SECTION_ID_PACKETS_AND_FRAMES;
2688
4/4
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 6 times.
110 else if (do_show_packets && !do_show_frames)
2689 60 section_id = SECTION_ID_PACKETS;
2690 else // (!do_show_packets && do_show_frames)
2691 50 section_id = SECTION_ID_FRAMES;
2692
3/4
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
115 if (do_show_frames || do_show_packets)
2693 115 avtext_print_section_header(tfc, NULL, section_id);
2694 115 ret = read_packets(tfc, &ifile);
2695
3/4
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
115 if (do_show_frames || do_show_packets)
2696 115 avtext_print_section_footer(tfc);
2697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 CHECK_END;
2698 }
2699
2700
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 114 times.
198 if (do_show_programs) {
2701 84 ret = show_programs(tfc, &ifile);
2702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 CHECK_END;
2703 }
2704
2705
2/2
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 96 times.
198 if (do_show_stream_groups) {
2706 102 ret = show_stream_groups(tfc, &ifile);
2707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 102 times.
102 CHECK_END;
2708 }
2709
2710
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 78 times.
198 if (do_show_streams) {
2711 120 ret = show_streams(tfc, &ifile);
2712
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
120 CHECK_END;
2713 }
2714
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 193 times.
198 if (do_show_chapters) {
2715 5 ret = show_chapters(tfc, &ifile);
2716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 CHECK_END;
2717 }
2718
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 42 times.
198 if (do_show_format) {
2719 42 ret = show_format(tfc, &ifile);
2720
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 CHECK_END;
2721 }
2722
2723 198 end:
2724
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
198 if (ifile.fmt_ctx)
2725 198 close_input_file(&ifile);
2726 198 av_freep(&nb_streams_frames);
2727 198 av_freep(&nb_streams_packets);
2728 198 av_freep(&selected_streams);
2729 198 av_freep(&streams_with_closed_captions);
2730 198 av_freep(&streams_with_film_grain);
2731 198 av_freep(&audio_codec_name);
2732 198 av_freep(&data_codec_name);
2733 198 av_freep(&subtitle_codec_name);
2734 198 av_freep(&video_codec_name);
2735
2736 198 return ret;
2737 }
2738
2739 static void show_usage(void)
2740 {
2741 av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
2742 av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] INPUT_FILE\n", program_name);
2743 av_log(NULL, AV_LOG_INFO, "\n");
2744 }
2745
2746 static void ffprobe_show_program_version(AVTextFormatContext *tfc)
2747 {
2748 AVBPrint pbuf;
2749 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2750
2751 avtext_print_section_header(tfc, NULL, SECTION_ID_PROGRAM_VERSION);
2752 print_str("version", FFMPEG_VERSION);
2753 print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
2754 program_birth_year, CONFIG_THIS_YEAR);
2755 print_str("compiler_ident", CC_IDENT);
2756 print_str("configuration", FFMPEG_CONFIGURATION);
2757 avtext_print_section_footer(tfc);
2758
2759 av_bprint_finalize(&pbuf, NULL);
2760 }
2761
2762 #define SHOW_LIB_VERSION(libname, LIBNAME) \
2763 do { \
2764 if (CONFIG_##LIBNAME) { \
2765 unsigned int version = libname##_version(); \
2766 avtext_print_section_header(tfc, NULL, SECTION_ID_LIBRARY_VERSION); \
2767 print_str("name", "lib" #libname); \
2768 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
2769 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
2770 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
2771 print_int("version", version); \
2772 print_str("ident", LIB##LIBNAME##_IDENT); \
2773 avtext_print_section_footer(tfc); \
2774 } \
2775 } while (0)
2776
2777 static void ffprobe_show_library_versions(AVTextFormatContext *tfc)
2778 {
2779 avtext_print_section_header(tfc, NULL, SECTION_ID_LIBRARY_VERSIONS);
2780 SHOW_LIB_VERSION(avutil, AVUTIL);
2781 SHOW_LIB_VERSION(avcodec, AVCODEC);
2782 SHOW_LIB_VERSION(avformat, AVFORMAT);
2783 SHOW_LIB_VERSION(avdevice, AVDEVICE);
2784 SHOW_LIB_VERSION(avfilter, AVFILTER);
2785 SHOW_LIB_VERSION(swscale, SWSCALE);
2786 SHOW_LIB_VERSION(swresample, SWRESAMPLE);
2787 avtext_print_section_footer(tfc);
2788 }
2789
2790 #define PRINT_PIX_FMT_FLAG(flagname, name) \
2791 do { \
2792 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
2793 } while (0)
2794
2795 static void ffprobe_show_pixel_formats(AVTextFormatContext *tfc)
2796 {
2797 const AVPixFmtDescriptor *pixdesc = NULL;
2798 int i, n;
2799
2800 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMATS);
2801 while (pixdesc = av_pix_fmt_desc_next(pixdesc)) {
2802 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMAT);
2803 print_str("name", pixdesc->name);
2804 print_int("nb_components", pixdesc->nb_components);
2805 if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
2806 print_int ("log2_chroma_w", pixdesc->log2_chroma_w);
2807 print_int ("log2_chroma_h", pixdesc->log2_chroma_h);
2808 } else {
2809 print_str_opt("log2_chroma_w", "N/A");
2810 print_str_opt("log2_chroma_h", "N/A");
2811 }
2812 n = av_get_bits_per_pixel(pixdesc);
2813 if (n) print_int ("bits_per_pixel", n);
2814 else print_str_opt("bits_per_pixel", "N/A");
2815 if (do_show_pixel_format_flags) {
2816 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMAT_FLAGS);
2817 PRINT_PIX_FMT_FLAG(BE, "big_endian");
2818 PRINT_PIX_FMT_FLAG(PAL, "palette");
2819 PRINT_PIX_FMT_FLAG(BITSTREAM, "bitstream");
2820 PRINT_PIX_FMT_FLAG(HWACCEL, "hwaccel");
2821 PRINT_PIX_FMT_FLAG(PLANAR, "planar");
2822 PRINT_PIX_FMT_FLAG(RGB, "rgb");
2823 PRINT_PIX_FMT_FLAG(ALPHA, "alpha");
2824 avtext_print_section_footer(tfc);
2825 }
2826 if (do_show_pixel_format_components && (pixdesc->nb_components > 0)) {
2827 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMAT_COMPONENTS);
2828 for (i = 0; i < pixdesc->nb_components; i++) {
2829 avtext_print_section_header(tfc, NULL, SECTION_ID_PIXEL_FORMAT_COMPONENT);
2830 print_int("index", i + 1);
2831 print_int("bit_depth", pixdesc->comp[i].depth);
2832 avtext_print_section_footer(tfc);
2833 }
2834 avtext_print_section_footer(tfc);
2835 }
2836 avtext_print_section_footer(tfc);
2837 }
2838 avtext_print_section_footer(tfc);
2839 }
2840
2841 static int opt_show_optional_fields(void *optctx, const char *opt, const char *arg)
2842 {
2843 if (!av_strcasecmp(arg, "always")) show_optional_fields = SHOW_OPTIONAL_FIELDS_ALWAYS;
2844 else if (!av_strcasecmp(arg, "never")) show_optional_fields = SHOW_OPTIONAL_FIELDS_NEVER;
2845 else if (!av_strcasecmp(arg, "auto")) show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO;
2846
2847 if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto")) {
2848 double num;
2849 int ret = parse_number("show_optional_fields", arg, OPT_TYPE_INT,
2850 SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS, &num);
2851 if (ret < 0)
2852 return ret;
2853 show_optional_fields = num;
2854 }
2855 return 0;
2856 }
2857
2858 15 static int opt_format(void *optctx, const char *opt, const char *arg)
2859 {
2860 15 iformat = av_find_input_format(arg);
2861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (!iformat) {
2862 av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
2863 return AVERROR(EINVAL);
2864 }
2865 15 return 0;
2866 }
2867
2868 1690 static inline void mark_section_show_entries(SectionID section_id,
2869 int show_all_entries, AVDictionary *entries)
2870 {
2871 1690 EntrySelection *selection = &selected_entries[section_id];
2872
2873 1690 selection->show_all_entries = show_all_entries;
2874
2/2
✓ Branch 0 taken 1330 times.
✓ Branch 1 taken 360 times.
1690 if (show_all_entries) {
2875 1330 const AVTextFormatSection *section = &sections[section_id];
2876
2/2
✓ Branch 0 taken 1038 times.
✓ Branch 1 taken 1330 times.
2368 for (const int *id = section->children_ids; *id != -1; id++)
2877 1038 mark_section_show_entries(*id, show_all_entries, entries);
2878 } else {
2879 360 av_dict_copy(&selection->entries_to_show, entries, 0);
2880 }
2881 1690 }
2882
2883 368 static int match_section(const char *section_name,
2884 int show_all_entries, AVDictionary *entries)
2885 {
2886 368 int i, ret = 0;
2887
2888
2/2
✓ Branch 0 taken 25024 times.
✓ Branch 1 taken 368 times.
25392 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
2889 25024 const struct AVTextFormatSection *section = &sections[i];
2890
2/2
✓ Branch 0 taken 24670 times.
✓ Branch 1 taken 354 times.
25024 if (!strcmp(section_name, section->name) ||
2891
4/4
✓ Branch 0 taken 12708 times.
✓ Branch 1 taken 11962 times.
✓ Branch 2 taken 185 times.
✓ Branch 3 taken 12523 times.
24670 (section->unique_name && !strcmp(section_name, section->unique_name))) {
2892 539 av_log(NULL, AV_LOG_DEBUG,
2893 "'%s' matches section with unique name '%s'\n", section_name,
2894 539 (char *)av_x_if_null(section->unique_name, section->name));
2895 539 ret++;
2896 539 mark_section_show_entries(section->id, show_all_entries, entries);
2897 }
2898 }
2899 368 return ret;
2900 }
2901
2902 149 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
2903 {
2904 149 const char *p = arg;
2905 149 int ret = 0;
2906
2907
2/2
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 149 times.
517 while (*p) {
2908 368 AVDictionary *entries = NULL;
2909 368 char *section_name = av_get_token(&p, "=:");
2910 368 int show_all_entries = 0;
2911
2912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 368 times.
368 if (!section_name) {
2913 av_log(NULL, AV_LOG_ERROR,
2914 "Missing section name for option '%s'\n", opt);
2915 return AVERROR(EINVAL);
2916 }
2917
2918
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 166 times.
368 if (*p == '=') {
2919 202 p++;
2920
4/4
✓ Branch 0 taken 601 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 454 times.
✓ Branch 3 taken 147 times.
858 while (*p && *p != ':') {
2921 454 char *entry = av_get_token(&p, ",:");
2922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 454 times.
454 if (!entry)
2923 break;
2924 454 av_log(NULL, AV_LOG_VERBOSE,
2925 "Adding '%s' to the entries to show in section '%s'\n",
2926 entry, section_name);
2927 454 av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
2928
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 252 times.
454 if (*p == ',')
2929 252 p++;
2930 }
2931 } else {
2932 166 show_all_entries = 1;
2933 }
2934
2935 368 ret = match_section(section_name, show_all_entries, entries);
2936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 368 times.
368 if (ret == 0) {
2937 av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
2938 ret = AVERROR(EINVAL);
2939 }
2940 368 av_dict_free(&entries);
2941 368 av_free(section_name);
2942
2943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 368 times.
368 if (ret <= 0)
2944 break;
2945
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 149 times.
368 if (*p)
2946 219 p++;
2947 }
2948
2949 149 return ret;
2950 }
2951
2952 198 static int opt_input_file(void *optctx, const char *arg)
2953 {
2954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (input_filename) {
2955 av_log(NULL, AV_LOG_ERROR,
2956 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
2957 arg, input_filename);
2958 return AVERROR(EINVAL);
2959 }
2960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (!strcmp(arg, "-"))
2961 arg = "fd:";
2962 198 input_filename = av_strdup(arg);
2963
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (!input_filename)
2964 return AVERROR(ENOMEM);
2965
2966 198 return 0;
2967 }
2968
2969 10 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
2970 {
2971 10 opt_input_file(optctx, arg);
2972 10 return 0;
2973 }
2974
2975 static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
2976 {
2977 if (output_filename) {
2978 av_log(NULL, AV_LOG_ERROR,
2979 "Argument '%s' provided as output filename, but '%s' was already specified.\n",
2980 arg, output_filename);
2981 return AVERROR(EINVAL);
2982 }
2983 if (!strcmp(arg, "-"))
2984 arg = "fd:";
2985 output_filename = av_strdup(arg);
2986 if (!output_filename)
2987 return AVERROR(ENOMEM);
2988
2989 return 0;
2990 }
2991
2992 16 static int opt_print_filename(void *optctx, const char *opt, const char *arg)
2993 {
2994 16 av_freep(&print_input_filename);
2995 16 print_input_filename = av_strdup(arg);
2996
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 return print_input_filename ? 0 : AVERROR(ENOMEM);
2997 }
2998
2999 void show_help_default(const char *opt, const char *arg)
3000 {
3001 av_log_set_callback(log_callback_help);
3002 show_usage();
3003 show_help_options(options, "Main options:", 0, 0);
3004 printf("\n");
3005
3006 show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
3007 show_help_children(avcodec_get_class(), AV_OPT_FLAG_DECODING_PARAM);
3008 }
3009
3010 /**
3011 * Parse interval specification, according to the format:
3012 * INTERVAL ::= [START|+START_OFFSET][%[END|+END_OFFSET]]
3013 * INTERVALS ::= INTERVAL[,INTERVALS]
3014 */
3015 4 static int parse_read_interval(const char *interval_spec,
3016 ReadInterval *interval)
3017 {
3018 4 int ret = 0;
3019 4 char *next, *p, *spec = av_strdup(interval_spec);
3020
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!spec)
3021 return AVERROR(ENOMEM);
3022
3023
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!*spec) {
3024 av_log(NULL, AV_LOG_ERROR, "Invalid empty interval specification\n");
3025 ret = AVERROR(EINVAL);
3026 goto end;
3027 }
3028
3029 4 p = spec;
3030 4 next = strchr(spec, '%');
3031
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (next)
3032 4 *next++ = 0;
3033
3034 /* parse first part */
3035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (*p) {
3036 interval->has_start = 1;
3037
3038 if (*p == '+') {
3039 interval->start_is_offset = 1;
3040 p++;
3041 } else {
3042 interval->start_is_offset = 0;
3043 }
3044
3045 ret = av_parse_time(&interval->start, p, 1);
3046 if (ret < 0) {
3047 av_log(NULL, AV_LOG_ERROR, "Invalid interval start specification '%s'\n", p);
3048 goto end;
3049 }
3050 } else {
3051 4 interval->has_start = 0;
3052 }
3053
3054 /* parse second part */
3055 4 p = next;
3056
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 if (p && *p) {
3057 int64_t us;
3058 4 interval->has_end = 1;
3059
3060
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (*p == '+') {
3061 1 interval->end_is_offset = 1;
3062 1 p++;
3063 } else {
3064 3 interval->end_is_offset = 0;
3065 }
3066
3067
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 == '#') {
3068 long long int lli;
3069 char *tail;
3070 1 interval->duration_frames = 1;
3071 1 p++;
3072 1 lli = strtoll(p, &tail, 10);
3073
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) {
3074 av_log(NULL, AV_LOG_ERROR,
3075 "Invalid or negative value '%s' for duration number of frames\n", p);
3076 goto end;
3077 }
3078 1 interval->end = lli;
3079 } else {
3080 3 interval->duration_frames = 0;
3081 3 ret = av_parse_time(&us, p, 1);
3082
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0) {
3083 av_log(NULL, AV_LOG_ERROR, "Invalid interval end/duration specification '%s'\n", p);
3084 goto end;
3085 }
3086 3 interval->end = us;
3087 }
3088 } else {
3089 interval->has_end = 0;
3090 }
3091
3092 4 end:
3093 4 av_free(spec);
3094 4 return ret;
3095 }
3096
3097 4 static int parse_read_intervals(const char *intervals_spec)
3098 {
3099 int ret, n, i;
3100 4 char *p, *spec = av_strdup(intervals_spec);
3101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!spec)
3102 return AVERROR(ENOMEM);
3103
3104 /* preparse specification, get number of intervals */
3105
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 4 times.
23 for (n = 0, p = spec; *p; p++)
3106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
19 if (*p == ',')
3107 n++;
3108 4 n++;
3109
3110 4 read_intervals = av_malloc_array(n, sizeof(*read_intervals));
3111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!read_intervals) {
3112 ret = AVERROR(ENOMEM);
3113 goto end;
3114 }
3115 4 read_intervals_nb = n;
3116
3117 /* parse intervals */
3118 4 p = spec;
3119
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 for (i = 0; p; i++) {
3120 char *next;
3121
3122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 av_assert0(i < read_intervals_nb);
3123 4 next = strchr(p, ',');
3124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (next)
3125 *next++ = 0;
3126
3127 4 read_intervals[i].id = i;
3128 4 ret = parse_read_interval(p, &read_intervals[i]);
3129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0) {
3130 av_log(NULL, AV_LOG_ERROR, "Error parsing read interval #%d '%s'\n",
3131 i, p);
3132 goto end;
3133 }
3134 4 av_log(NULL, AV_LOG_VERBOSE, "Parsed log interval ");
3135 4 log_read_interval(&read_intervals[i], NULL, AV_LOG_VERBOSE);
3136 4 p = next;
3137 }
3138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 av_assert0(i == read_intervals_nb);
3139
3140 4 end:
3141 4 av_free(spec);
3142 4 return ret;
3143 }
3144
3145 4 static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
3146 {
3147 4 return parse_read_intervals(arg);
3148 }
3149
3150 static int opt_pretty(void *optctx, const char *opt, const char *arg)
3151 {
3152 show_value_unit = 1;
3153 use_value_prefix = 1;
3154 use_byte_value_binary_prefix = 1;
3155 use_value_sexagesimal_format = 1;
3156 return 0;
3157 }
3158
3159 static void print_section(SectionID id, int level)
3160 {
3161 const int *pid;
3162 const struct AVTextFormatSection *section = &sections[id];
3163 printf("%c%c%c%c",
3164 section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
3165 section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY ? 'A' : '.',
3166 section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS ? 'V' : '.',
3167 section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE ? 'T' : '.');
3168 printf("%*c %s", level * 4, ' ', section->name);
3169 if (section->unique_name)
3170 printf("/%s", section->unique_name);
3171 printf("\n");
3172
3173 for (pid = section->children_ids; *pid != -1; pid++)
3174 print_section(*pid, level+1);
3175 }
3176
3177 static int opt_sections(void *optctx, const char *opt, const char *arg)
3178 {
3179 printf("Sections:\n"
3180 "W... = Section is a wrapper (contains other sections, no local entries)\n"
3181 ".A.. = Section contains an array of elements of the same type\n"
3182 "..V. = Section may contain a variable number of fields with variable keys\n"
3183 "...T = Section contain a unique type\n"
3184 "FLAGS NAME/UNIQUE_NAME\n"
3185 "----\n");
3186 print_section(SECTION_ID_ROOT, 0);
3187 return 0;
3188 }
3189
3190 static int opt_codec(void *optctx, const char *opt, const char *arg)
3191 {
3192 const char *spec = strchr(opt, ':');
3193 const char **name;
3194 if (!spec) {
3195 av_log(NULL, AV_LOG_ERROR,
3196 "No media specifier was specified for '%s' in option '%s'. Use -%s:<media_spec> "
3197 "where <media_spec> can be one of: 'a' (audio), 'v' (video), 's' (subtitle), 'd' (data)\n",
3198 arg, opt, opt);
3199 return AVERROR(EINVAL);
3200 }
3201 spec++;
3202
3203 switch (spec[0]) {
3204 case 'a' : name = &audio_codec_name; break;
3205 case 'd' : name = &data_codec_name; break;
3206 case 's' : name = &subtitle_codec_name; break;
3207 case 'v' : name = &video_codec_name; break;
3208 default:
3209 av_log(NULL, AV_LOG_ERROR,
3210 "Invalid media specifier '%s' in option '%s'. "
3211 "Must be one of: 'a' (audio), 'v' (video), 's' (subtitle), 'd' (data)\n", spec, opt);
3212 return AVERROR(EINVAL);
3213 }
3214
3215 av_freep(name);
3216 *name = av_strdup(arg);
3217 return *name ? 0 : AVERROR(ENOMEM);
3218 }
3219
3220 static int opt_show_versions(void *optctx, const char *opt, const char *arg)
3221 {
3222 mark_section_show_entries(SECTION_ID_PROGRAM_VERSION, 1, NULL);
3223 mark_section_show_entries(SECTION_ID_LIBRARY_VERSION, 1, NULL);
3224 return 0;
3225 }
3226
3227 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3228 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3229 { \
3230 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3231 return 0; \
3232 }
3233
3234 4 DEFINE_OPT_SHOW_SECTION(chapters, CHAPTERS)
3235 DEFINE_OPT_SHOW_SECTION(error, ERROR)
3236 16 DEFINE_OPT_SHOW_SECTION(format, FORMAT)
3237 32 DEFINE_OPT_SHOW_SECTION(frames, FRAMES)
3238 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS)
3239 35 DEFINE_OPT_SHOW_SECTION(packets, PACKETS)
3240 DEFINE_OPT_SHOW_SECTION(pixel_formats, PIXEL_FORMATS)
3241 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION)
3242 26 DEFINE_OPT_SHOW_SECTION(streams, STREAMS)
3243 DEFINE_OPT_SHOW_SECTION(programs, PROGRAMS)
3244 DEFINE_OPT_SHOW_SECTION(stream_groups, STREAM_GROUPS)
3245
3246 static const OptionDef real_options[] = {
3247 CMDUTILS_COMMON_OPTIONS
3248 { "f", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_format}, "force format", "format" },
3249 { "unit", OPT_TYPE_BOOL, 0, {&show_value_unit}, "show unit of the displayed values" },
3250 { "prefix", OPT_TYPE_BOOL, 0, {&use_value_prefix}, "use SI prefixes for the displayed values" },
3251 { "byte_binary_prefix", OPT_TYPE_BOOL, 0, {&use_byte_value_binary_prefix},
3252 "use binary prefixes for byte units" },
3253 { "sexagesimal", OPT_TYPE_BOOL, 0, {&use_value_sexagesimal_format},
3254 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
3255 { "pretty", OPT_TYPE_FUNC, 0, {.func_arg = opt_pretty},
3256 "prettify the format of displayed values, make it more human readable" },
3257 { "output_format", OPT_TYPE_STRING, 0, { &output_format },
3258 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
3259 { "print_format", OPT_TYPE_STRING, 0, { &output_format }, "alias for -output_format (deprecated)" },
3260 { "of", OPT_TYPE_STRING, 0, { &output_format }, "alias for -output_format", "format" },
3261 { "select_streams", OPT_TYPE_STRING, 0, { &stream_specifier }, "select the specified streams", "stream_specifier" },
3262 { "sections", OPT_TYPE_FUNC, OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
3263 { "data_dump_format", OPT_TYPE_STRING, 0, { &data_dump_format }, "set data dump format (available formats are: xxd, base64)" },
3264 { "show_data", OPT_TYPE_BOOL, 0, { &do_show_data }, "show packets data" },
3265 { "show_data_hash", OPT_TYPE_STRING, 0, { &show_data_hash }, "show packets data hash" },
3266 { "show_error", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_error }, "show probing error" },
3267 { "show_format", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_format }, "show format/container info" },
3268 { "show_frames", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_frames }, "show frames info" },
3269 { "show_entries", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_show_entries},
3270 "show a set of specified entries", "entry_list" },
3271 #if HAVE_THREADS
3272 { "show_log", OPT_TYPE_INT, 0, { &do_show_log }, "show log" },
3273 #endif
3274 { "show_packets", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_packets }, "show packets info" },
3275 { "show_programs", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_programs }, "show programs info" },
3276 { "show_stream_groups", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_stream_groups }, "show stream groups info" },
3277 { "show_streams", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_streams }, "show streams info" },
3278 { "show_chapters", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_chapters }, "show chapters info" },
3279 { "count_frames", OPT_TYPE_BOOL, 0, { &do_count_frames }, "count the number of frames per stream" },
3280 { "count_packets", OPT_TYPE_BOOL, 0, { &do_count_packets }, "count the number of packets per stream" },
3281 { "show_program_version", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_program_version }, "show ffprobe version" },
3282 { "show_library_versions", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_library_versions }, "show library versions" },
3283 { "show_versions", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_versions }, "show program and library versions" },
3284 { "show_pixel_formats", OPT_TYPE_FUNC, 0, { .func_arg = &opt_show_pixel_formats }, "show pixel format descriptions" },
3285 { "show_optional_fields", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" },
3286 { "show_private_data", OPT_TYPE_BOOL, 0, { &show_private_data }, "show private data" },
3287 { "private", OPT_TYPE_BOOL, 0, { &show_private_data }, "same as show_private_data" },
3288 { "analyze_frames", OPT_TYPE_BOOL, 0, { &do_analyze_frames }, "analyze frames to provide additional stream-level information" },
3289 { "bitexact", OPT_TYPE_BOOL, 0, {&do_bitexact}, "force bitexact output" },
3290 { "read_intervals", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
3291 { "i", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
3292 { "o", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_output_file_o}, "write to specified output", "output_file"},
3293 { "print_filename", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"},
3294 { "find_stream_info", OPT_TYPE_BOOL, OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3295 "read and decode the streams to fill missing information with heuristics" },
3296 { "c", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_codec}, "force decoder", "decoder_name" },
3297 { "codec", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_codec}, "alias for -c (force decoder)", "decoder_name" },
3298 { NULL, },
3299 };
3300
3301 16220 static inline int check_section_show_entries(int section_id)
3302 {
3303 16220 const EntrySelection *selection = &selected_entries[section_id];
3304
3305
4/4
✓ Branch 0 taken 15784 times.
✓ Branch 1 taken 436 times.
✓ Branch 2 taken 328 times.
✓ Branch 3 taken 15456 times.
16220 if (selection->show_all_entries || selection->entries_to_show)
3306 764 return 1;
3307
3308 15456 const AVTextFormatSection *section = &sections[section_id];
3309
2/2
✓ Branch 0 taken 10874 times.
✓ Branch 1 taken 14764 times.
25638 for (const int *id = section->children_ids; *id != -1; id++)
3310
2/2
✓ Branch 1 taken 692 times.
✓ Branch 2 taken 10182 times.
10874 if (check_section_show_entries(*id))
3311 692 return 1;
3312 14764 return 0;
3313 }
3314
3315 #define SET_DO_SHOW(id, varname) do { \
3316 if (check_section_show_entries(SECTION_ID_##id)) \
3317 do_show_##varname = 1; \
3318 } while (0)
3319
3320 198 int main(int argc, char **argv)
3321 {
3322 const AVTextFormatter *f;
3323 AVTextFormatContext *tctx;
3324 AVTextWriterContext *wctx;
3325 char *buf;
3326 198 char *f_name = NULL, *f_args = NULL;
3327 int ret, input_ret;
3328 198 AVTextFormatDataDump data_dump_format_id = AV_TEXTFORMAT_DATADUMP_XXD;
3329
3330 198 init_dynload();
3331
3332 198 setvbuf(stderr, NULL, _IONBF, 0); /* win32 runtime needs this */
3333
3334 198 av_log_set_flags(AV_LOG_SKIP_REPEATED);
3335
3336 198 options = real_options;
3337 198 parse_loglevel(argc, argv, options);
3338 198 avformat_network_init();
3339 #if CONFIG_AVDEVICE
3340 198 avdevice_register_all();
3341 #endif
3342
3343 198 show_banner(argc, argv, options);
3344 198 ret = parse_options(NULL, argc, argv, options, opt_input_file);
3345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (ret < 0) {
3346 ret = (ret == AVERROR_EXIT) ? 0 : ret;
3347 goto end;
3348 }
3349
3350
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (do_show_log)
3351 av_log_set_callback(log_callback);
3352
3353 /* mark things to show, based on -show_entries */
3354
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 193 times.
198 SET_DO_SHOW(CHAPTERS, chapters);
3355
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 SET_DO_SHOW(ERROR, error);
3356
2/2
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 156 times.
198 SET_DO_SHOW(FORMAT, format);
3357
2/2
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 143 times.
198 SET_DO_SHOW(FRAMES, frames);
3358
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
3359
2/2
✓ Branch 1 taken 71 times.
✓ Branch 2 taken 127 times.
198 SET_DO_SHOW(PACKETS, packets);
3360
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 SET_DO_SHOW(PIXEL_FORMATS, pixel_formats);
3361
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
3362
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
3363
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 SET_DO_SHOW(PROGRAM_VERSION, program_version);
3364
2/2
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 114 times.
198 SET_DO_SHOW(PROGRAMS, programs);
3365
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 190 times.
198 SET_DO_SHOW(STREAM_GROUP_DISPOSITION, stream_group_disposition);
3366
2/2
✓ Branch 1 taken 102 times.
✓ Branch 2 taken 96 times.
198 SET_DO_SHOW(STREAM_GROUPS, stream_groups);
3367
2/2
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 177 times.
198 SET_DO_SHOW(STREAM_GROUP_COMPONENTS, stream_group_components);
3368
2/2
✓ Branch 1 taken 120 times.
✓ Branch 2 taken 78 times.
198 SET_DO_SHOW(STREAMS, streams);
3369
2/2
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 154 times.
198 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
3370
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 193 times.
198 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3371
2/2
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 174 times.
198 SET_DO_SHOW(STREAM_GROUP_STREAM_DISPOSITION, stream_disposition);
3372
3373
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 193 times.
198 SET_DO_SHOW(CHAPTER_TAGS, chapter_tags);
3374
2/2
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 164 times.
198 SET_DO_SHOW(FORMAT_TAGS, format_tags);
3375
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 150 times.
198 SET_DO_SHOW(FRAME_TAGS, frame_tags);
3376
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 SET_DO_SHOW(PROGRAM_TAGS, program_tags);
3377
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 190 times.
198 SET_DO_SHOW(STREAM_GROUP_TAGS, stream_group_tags);
3378
2/2
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 157 times.
198 SET_DO_SHOW(STREAM_TAGS, stream_tags);
3379
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 193 times.
198 SET_DO_SHOW(PROGRAM_STREAM_TAGS, stream_tags);
3380
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 193 times.
198 SET_DO_SHOW(STREAM_GROUP_STREAM_TAGS, stream_tags);
3381
2/2
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 161 times.
198 SET_DO_SHOW(PACKET_TAGS, packet_tags);
3382
3383
4/6
✓ Branch 0 taken 181 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 181 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 181 times.
198 if (do_bitexact && (do_show_program_version || do_show_library_versions)) {
3384 av_log(NULL, AV_LOG_ERROR,
3385 "-bitexact and -show_program_version or -show_library_versions "
3386 "options are incompatible\n");
3387 ret = AVERROR(EINVAL);
3388 goto end;
3389 }
3390
3391
2/2
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 67 times.
198 if (!output_format)
3392 131 output_format = av_strdup("default");
3393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (!output_format) {
3394 ret = AVERROR(ENOMEM);
3395 goto end;
3396 }
3397 198 f_name = av_strtok(output_format, "=", &buf);
3398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (!f_name) {
3399 av_log(NULL, AV_LOG_ERROR,
3400 "No name specified for the output format\n");
3401 ret = AVERROR(EINVAL);
3402 goto end;
3403 }
3404 198 f_args = buf;
3405
3406 198 f = avtext_get_formatter_by_name(f_name);
3407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (!f) {
3408 av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", f_name);
3409 ret = AVERROR(EINVAL);
3410 goto end;
3411 }
3412
3413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (data_dump_format) {
3414 if (!strcmp(data_dump_format, "xxd")) {
3415 data_dump_format_id = AV_TEXTFORMAT_DATADUMP_XXD;
3416 } else if (!strcmp(data_dump_format, "base64")) {
3417 data_dump_format_id = AV_TEXTFORMAT_DATADUMP_BASE64;
3418 } else {
3419 av_log(NULL, AV_LOG_ERROR, "Unknown data dump format with name '%s'\n", data_dump_format);
3420 ret = AVERROR(EINVAL);
3421 goto end;
3422 }
3423 }
3424
3425
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (output_filename) {
3426 ret = avtextwriter_create_file(&wctx, output_filename);
3427 } else
3428 198 ret = avtextwriter_create_stdout(&wctx);
3429
3430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (ret < 0)
3431 goto end;
3432
3433 198 AVTextFormatOptions tf_options = {
3434 .is_key_selected = is_key_selected_callback,
3435 .show_optional_fields = show_optional_fields,
3436 .show_value_unit = show_value_unit,
3437 .use_value_prefix = use_value_prefix,
3438 .use_byte_value_binary_prefix = use_byte_value_binary_prefix,
3439 .use_value_sexagesimal_format = use_value_sexagesimal_format,
3440 .data_dump_format = data_dump_format_id,
3441 };
3442
3443
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 198 times.
198 if ((ret = avtext_context_open(&tctx, f, wctx, f_args, sections, FF_ARRAY_ELEMS(sections), tf_options, show_data_hash)) >= 0) {
3444
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 196 times.
198 if (f == &avtextformatter_xml)
3445 2 tctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;
3446
3447 198 avtext_print_section_header(tctx, NULL, SECTION_ID_ROOT);
3448
3449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (do_show_program_version)
3450 ffprobe_show_program_version(tctx);
3451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (do_show_library_versions)
3452 ffprobe_show_library_versions(tctx);
3453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (do_show_pixel_formats)
3454 ffprobe_show_pixel_formats(tctx);
3455
3456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (!input_filename &&
3457 ((do_show_format || do_show_programs || do_show_stream_groups || do_show_streams || do_show_chapters || do_show_packets || do_show_error) ||
3458 (!do_show_program_version && !do_show_library_versions && !do_show_pixel_formats))) {
3459 show_usage();
3460 av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
3461 av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
3462 ret = AVERROR(EINVAL);
3463
1/2
✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
198 } else if (input_filename) {
3464 198 ret = probe_file(tctx, input_filename, print_input_filename);
3465
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
198 if (ret < 0 && do_show_error)
3466 show_error(tctx, ret);
3467 }
3468
3469 198 input_ret = ret;
3470
3471 198 avtext_print_section_footer(tctx);
3472
3473 198 ret = avtextwriter_context_close(&wctx);
3474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (ret < 0)
3475 av_log(NULL, AV_LOG_ERROR, "Writing output failed (closing writer): %s\n", av_err2str(ret));
3476
3477 198 ret = avtext_context_close(&tctx);
3478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
198 if (ret < 0)
3479 av_log(NULL, AV_LOG_ERROR, "Writing output failed (closing formatter): %s\n", av_err2str(ret));
3480
3481 198 ret = FFMIN(ret, input_ret);
3482 }
3483
3484 end:
3485 198 av_freep(&output_format);
3486 198 av_freep(&output_filename);
3487 198 av_freep(&input_filename);
3488 198 av_freep(&print_input_filename);
3489 198 av_freep(&read_intervals);
3490
3491 198 uninit_opts();
3492
2/2
✓ Branch 0 taken 13464 times.
✓ Branch 1 taken 198 times.
13662 for (size_t i = 0; i < FF_ARRAY_ELEMS(selected_entries); ++i)
3493 13464 av_dict_free(&selected_entries[i].entries_to_show);
3494
3495 198 avformat_network_deinit();
3496
3497 198 return ret < 0;
3498 }
3499