FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffprobe.c
Date: 2026-08-15 14:54:27
Exec Total Coverage
Lines: 1423 2039 69.8%
Functions: 67 95 70.5%
Branches: 782 1318 59.3%

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