| FFmpegKit iOS / macOS / tvOS API 6.0

Loading...
Searching...
No Matches
fftools_ffprobe.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2010 Stefano Sabatini
3 * Copyright (c) 2020-2022 Taner Sener
4 * Copyright (c) 2023 ARTHENICA LTD
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
28/*
29 * This file is the modified version of ffprobe.c file living in ffmpeg source code under the fftools folder. We
30 * manually update it each time we depend on a new ffmpeg version. Below you can see the list of changes applied
31 * by us to develop mobile-ffmpeg and later ffmpeg-kit libraries.
32 *
33 * ffmpeg-kit changes by ARTHENICA LTD
34 *
35 * 07.2023
36 * --------------------------------------------------------
37 * - FFmpeg 6.0 changes migrated
38 * - fftools header names updated
39 *
40 * mobile-ffmpeg / ffmpeg-kit changes by Taner Sener
41 *
42 * 09.2022
43 * --------------------------------------------------------
44 * - implemented writer_printf_printf using av_vlog
45 * - printf statements replaced with av_log
46 * - volatile dropped from thread local variables
47 * - sections cleaned before starting a new execution
48 *
49 * 01.2020
50 * --------------------------------------------------------
51 * - ffprobe support (volatile added to critical variables, options updated as ffprobe_options, printf
52 * statements replaced with av_log, dropped static variables in methods, show_help_default renamed as
53 * show_help_default_ffprobe, implemented exit_program with longjmp, OptionDef defines combined)
54 * - concurrent execution support ("__thread" specifier added to variables used by multiple threads,
55 * static keyword removed from methods called by both ffmpeg and ffprobe)
56 * - main() function renamed as ffprobe_execute()
57 */
58
59#include "config.h"
60#include "libavutil/ffversion.h"
61
62#include <string.h>
63#include <math.h>
64
65#include "libavformat/avformat.h"
66#include "libavcodec/avcodec.h"
67#include "libavutil/ambient_viewing_environment.h"
68#include "libavutil/avassert.h"
69#include "libavutil/avstring.h"
70#include "libavutil/bprint.h"
71#include "libavutil/channel_layout.h"
72#include "libavutil/display.h"
73#include "libavutil/hash.h"
74#include "libavutil/hdr_dynamic_metadata.h"
75#include "libavutil/mastering_display_metadata.h"
76#include "libavutil/hdr_dynamic_vivid_metadata.h"
77#include "libavutil/dovi_meta.h"
78#include "libavutil/opt.h"
79#include "libavutil/pixdesc.h"
80#include "libavutil/spherical.h"
81#include "libavutil/stereo3d.h"
82#include "libavutil/dict.h"
83#include "libavutil/intreadwrite.h"
84#include "libavutil/libm.h"
85#include "libavutil/parseutils.h"
86#include "libavutil/timecode.h"
87#include "libavutil/timestamp.h"
88#include "libavdevice/avdevice.h"
89#include "libswscale/swscale.h"
90#include "libswresample/swresample.h"
91#include "fftools_cmdutils.h"
92#include "fftools_opt_common.h"
93
94#include "libavutil/thread.h"
95
96#include "ffmpegkit_exception.h"
97
98#if !HAVE_THREADS
99# ifdef pthread_mutex_lock
100# undef pthread_mutex_lock
101# endif
102# define pthread_mutex_lock(a) do{}while(0)
103# ifdef pthread_mutex_unlock
104# undef pthread_mutex_unlock
105# endif
106# define pthread_mutex_unlock(a) do{}while(0)
107#endif
108
109 typedef struct InputStream {
110 AVStream *st;
111
112 AVCodecContext *dec_ctx;
113} InputStream;
114
115 typedef struct InputFile {
116 AVFormatContext *fmt_ctx;
117
118 InputStream *streams;
119 int nb_streams;
120} InputFile;
121
122__thread int do_bitexact = 0;
123__thread int do_count_frames = 0;
124__thread int do_count_packets = 0;
125__thread int do_read_frames = 0;
126__thread int do_read_packets = 0;
127__thread int do_show_chapters = 0;
128__thread int do_show_error = 0;
129__thread int do_show_format = 0;
130__thread int do_show_frames = 0;
131__thread int do_show_packets = 0;
132__thread int do_show_programs = 0;
133__thread int do_show_streams = 0;
134__thread int do_show_stream_disposition = 0;
135__thread int do_show_data = 0;
136__thread int do_show_program_version = 0;
137__thread int do_show_library_versions = 0;
138__thread int do_show_pixel_formats = 0;
139__thread int do_show_pixel_format_flags = 0;
140__thread int do_show_pixel_format_components = 0;
141__thread int do_show_log = 0;
142
143__thread int do_show_chapter_tags = 0;
144__thread int do_show_format_tags = 0;
145__thread int do_show_frame_tags = 0;
146__thread int do_show_program_tags = 0;
147__thread int do_show_stream_tags = 0;
148__thread int do_show_packet_tags = 0;
149
150__thread int show_value_unit = 0;
151__thread int use_value_prefix = 0;
152__thread int use_byte_value_binary_prefix = 0;
153__thread int use_value_sexagesimal_format = 0;
154__thread int show_private_data = 1;
155
156#define SHOW_OPTIONAL_FIELDS_AUTO -1
157#define SHOW_OPTIONAL_FIELDS_NEVER 0
158#define SHOW_OPTIONAL_FIELDS_ALWAYS 1
159__thread int show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO;
160
161__thread char *print_format;
162__thread char *stream_specifier;
163__thread char *show_data_hash;
164
165 typedef struct ReadInterval {
166 int id;
167 int64_t start, end;
168 int has_start, has_end;
169 int start_is_offset, end_is_offset;
170 int duration_frames;
171} ReadInterval;
172
173__thread ReadInterval *read_intervals;
174__thread int read_intervals_nb = 0;
175
176__thread int find_stream_info = 1;
177
178/* section structure definition */
179
180#define SECTION_MAX_NB_CHILDREN 10
181
182 struct section {
183 int id;
184 const char *name;
185
186#define SECTION_FLAG_IS_WRAPPER 1
187#define SECTION_FLAG_IS_ARRAY 2
188#define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
190 int flags;
191 int children_ids[SECTION_MAX_NB_CHILDREN+1];
192 const char *element_name;
193 const char *unique_name;
194 AVDictionary *entries_to_show;
195 int show_all_entries;
196};
197
198 typedef enum {
199 SECTION_ID_NONE = -1,
200 SECTION_ID_CHAPTER,
201 SECTION_ID_CHAPTER_TAGS,
202 SECTION_ID_CHAPTERS,
203 SECTION_ID_ERROR,
204 SECTION_ID_FORMAT,
205 SECTION_ID_FORMAT_TAGS,
206 SECTION_ID_FRAME,
207 SECTION_ID_FRAMES,
208 SECTION_ID_FRAME_TAGS,
209 SECTION_ID_FRAME_SIDE_DATA_LIST,
210 SECTION_ID_FRAME_SIDE_DATA,
211 SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST,
212 SECTION_ID_FRAME_SIDE_DATA_TIMECODE,
213 SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST,
214 SECTION_ID_FRAME_SIDE_DATA_COMPONENT,
215 SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST,
216 SECTION_ID_FRAME_SIDE_DATA_PIECE,
217 SECTION_ID_FRAME_LOG,
218 SECTION_ID_FRAME_LOGS,
219 SECTION_ID_LIBRARY_VERSION,
220 SECTION_ID_LIBRARY_VERSIONS,
221 SECTION_ID_PACKET,
222 SECTION_ID_PACKET_TAGS,
223 SECTION_ID_PACKETS,
224 SECTION_ID_PACKETS_AND_FRAMES,
225 SECTION_ID_PACKET_SIDE_DATA_LIST,
226 SECTION_ID_PACKET_SIDE_DATA,
227 SECTION_ID_PIXEL_FORMAT,
228 SECTION_ID_PIXEL_FORMAT_FLAGS,
229 SECTION_ID_PIXEL_FORMAT_COMPONENT,
230 SECTION_ID_PIXEL_FORMAT_COMPONENTS,
231 SECTION_ID_PIXEL_FORMATS,
232 SECTION_ID_PROGRAM_STREAM_DISPOSITION,
233 SECTION_ID_PROGRAM_STREAM_TAGS,
234 SECTION_ID_PROGRAM,
235 SECTION_ID_PROGRAM_STREAMS,
236 SECTION_ID_PROGRAM_STREAM,
237 SECTION_ID_PROGRAM_TAGS,
238 SECTION_ID_PROGRAM_VERSION,
239 SECTION_ID_PROGRAMS,
240 SECTION_ID_ROOT,
241 SECTION_ID_STREAM,
242 SECTION_ID_STREAM_DISPOSITION,
243 SECTION_ID_STREAMS,
244 SECTION_ID_STREAM_TAGS,
245 SECTION_ID_STREAM_SIDE_DATA_LIST,
246 SECTION_ID_STREAM_SIDE_DATA,
247 SECTION_ID_SUBTITLE,
248} SectionID;
249
250__thread static struct section sections[] = {
251 [SECTION_ID_CHAPTERS] = { SECTION_ID_CHAPTERS, "chapters", SECTION_FLAG_IS_ARRAY, { SECTION_ID_CHAPTER, -1 } },
252 [SECTION_ID_CHAPTER] = { SECTION_ID_CHAPTER, "chapter", 0, { SECTION_ID_CHAPTER_TAGS, -1 } },
253 [SECTION_ID_CHAPTER_TAGS] = { SECTION_ID_CHAPTER_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "chapter_tags" },
254 [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "error", 0, { -1 } },
255 [SECTION_ID_FORMAT] = { SECTION_ID_FORMAT, "format", 0, { SECTION_ID_FORMAT_TAGS, -1 } },
256 [SECTION_ID_FORMAT_TAGS] = { SECTION_ID_FORMAT_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "format_tags" },
257 [SECTION_ID_FRAMES] = { SECTION_ID_FRAMES, "frames", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME, SECTION_ID_SUBTITLE, -1 } },
258 [SECTION_ID_FRAME] = { SECTION_ID_FRAME, "frame", 0, { SECTION_ID_FRAME_TAGS, SECTION_ID_FRAME_SIDE_DATA_LIST, SECTION_ID_FRAME_LOGS, -1 } },
259 [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" },
260 [SECTION_ID_FRAME_SIDE_DATA_LIST] ={ SECTION_ID_FRAME_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "frame_side_data_list" },
261 [SECTION_ID_FRAME_SIDE_DATA] = { SECTION_ID_FRAME_SIDE_DATA, "side_data", 0, { SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST, -1 }, .unique_name = "frame_side_data" },
262 [SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST] = { SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, "timecodes", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_TIMECODE, -1 } },
263 [SECTION_ID_FRAME_SIDE_DATA_TIMECODE] = { SECTION_ID_FRAME_SIDE_DATA_TIMECODE, "timecode", 0, { -1 } },
264 [SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST] = { SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST, "components", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_COMPONENT, -1 } },
265 [SECTION_ID_FRAME_SIDE_DATA_COMPONENT] = { SECTION_ID_FRAME_SIDE_DATA_COMPONENT, "component", 0, { SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST, -1 } },
266 [SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST] = { SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST, "pieces", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA_PIECE, -1 } },
267 [SECTION_ID_FRAME_SIDE_DATA_PIECE] = { SECTION_ID_FRAME_SIDE_DATA_PIECE, "section", 0, { -1 } },
268 [SECTION_ID_FRAME_LOGS] = { SECTION_ID_FRAME_LOGS, "logs", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_LOG, -1 } },
269 [SECTION_ID_FRAME_LOG] = { SECTION_ID_FRAME_LOG, "log", 0, { -1 }, },
270 [SECTION_ID_LIBRARY_VERSIONS] = { SECTION_ID_LIBRARY_VERSIONS, "library_versions", SECTION_FLAG_IS_ARRAY, { SECTION_ID_LIBRARY_VERSION, -1 } },
271 [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } },
272 [SECTION_ID_PACKETS] = { SECTION_ID_PACKETS, "packets", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} },
273 [SECTION_ID_PACKETS_AND_FRAMES] = { SECTION_ID_PACKETS_AND_FRAMES, "packets_and_frames", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} },
274 [SECTION_ID_PACKET] = { SECTION_ID_PACKET, "packet", 0, { SECTION_ID_PACKET_TAGS, SECTION_ID_PACKET_SIDE_DATA_LIST, -1 } },
275 [SECTION_ID_PACKET_TAGS] = { SECTION_ID_PACKET_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "packet_tags" },
276 [SECTION_ID_PACKET_SIDE_DATA_LIST] ={ SECTION_ID_PACKET_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "packet_side_data_list" },
277 [SECTION_ID_PACKET_SIDE_DATA] = { SECTION_ID_PACKET_SIDE_DATA, "side_data", 0, { -1 }, .unique_name = "packet_side_data" },
278 [SECTION_ID_PIXEL_FORMATS] = { SECTION_ID_PIXEL_FORMATS, "pixel_formats", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PIXEL_FORMAT, -1 } },
279 [SECTION_ID_PIXEL_FORMAT] = { SECTION_ID_PIXEL_FORMAT, "pixel_format", 0, { SECTION_ID_PIXEL_FORMAT_FLAGS, SECTION_ID_PIXEL_FORMAT_COMPONENTS, -1 } },
280 [SECTION_ID_PIXEL_FORMAT_FLAGS] = { SECTION_ID_PIXEL_FORMAT_FLAGS, "flags", 0, { -1 }, .unique_name = "pixel_format_flags" },
281 [SECTION_ID_PIXEL_FORMAT_COMPONENTS] = { SECTION_ID_PIXEL_FORMAT_COMPONENTS, "components", SECTION_FLAG_IS_ARRAY, {SECTION_ID_PIXEL_FORMAT_COMPONENT, -1 }, .unique_name = "pixel_format_components" },
282 [SECTION_ID_PIXEL_FORMAT_COMPONENT] = { SECTION_ID_PIXEL_FORMAT_COMPONENT, "component", 0, { -1 } },
283 [SECTION_ID_PROGRAM_STREAM_DISPOSITION] = { SECTION_ID_PROGRAM_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "program_stream_disposition" },
284 [SECTION_ID_PROGRAM_STREAM_TAGS] = { SECTION_ID_PROGRAM_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_stream_tags" },
285 [SECTION_ID_PROGRAM] = { SECTION_ID_PROGRAM, "program", 0, { SECTION_ID_PROGRAM_TAGS, SECTION_ID_PROGRAM_STREAMS, -1 } },
286 [SECTION_ID_PROGRAM_STREAMS] = { SECTION_ID_PROGRAM_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM_STREAM, -1 }, .unique_name = "program_streams" },
287 [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" },
288 [SECTION_ID_PROGRAM_TAGS] = { SECTION_ID_PROGRAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_tags" },
289 [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
290 [SECTION_ID_PROGRAMS] = { SECTION_ID_PROGRAMS, "programs", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM, -1 } },
291 [SECTION_ID_ROOT] = { SECTION_ID_ROOT, "root", SECTION_FLAG_IS_WRAPPER,
292 { SECTION_ID_CHAPTERS, SECTION_ID_FORMAT, SECTION_ID_FRAMES, SECTION_ID_PROGRAMS, SECTION_ID_STREAMS,
293 SECTION_ID_PACKETS, SECTION_ID_ERROR, SECTION_ID_PROGRAM_VERSION, SECTION_ID_LIBRARY_VERSIONS,
294 SECTION_ID_PIXEL_FORMATS, -1} },
295 [SECTION_ID_STREAMS] = { SECTION_ID_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM, -1 } },
296 [SECTION_ID_STREAM] = { SECTION_ID_STREAM, "stream", 0, { SECTION_ID_STREAM_DISPOSITION, SECTION_ID_STREAM_TAGS, SECTION_ID_STREAM_SIDE_DATA_LIST, -1 } },
297 [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" },
298 [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" },
299 [SECTION_ID_STREAM_SIDE_DATA_LIST] ={ SECTION_ID_STREAM_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "stream_side_data_list" },
300 [SECTION_ID_STREAM_SIDE_DATA] = { SECTION_ID_STREAM_SIDE_DATA, "side_data", 0, { -1 }, .unique_name = "stream_side_data" },
301 [SECTION_ID_SUBTITLE] = { SECTION_ID_SUBTITLE, "subtitle", 0, { -1 } },
302};
303
304__thread OptionDef *ffprobe_options = NULL;
305
306/* FFprobe context */
307__thread const char *input_filename;
308__thread const char *print_input_filename;
309__thread const AVInputFormat *iformat = NULL;
310__thread const char *output_filename = NULL;
311
312__thread struct AVHashContext *hash;
313
314__thread int main_ffprobe_return_code = 0;
315 extern __thread int longjmp_value;
316
317 static const struct {
318 double bin_val;
319 double dec_val;
320 const char *bin_str;
321 const char *dec_str;
322} si_prefixes[] = {
323 { 1.0, 1.0, "", "" },
324 { 1.024e3, 1e3, "Ki", "K" },
325 { 1.048576e6, 1e6, "Mi", "M" },
326 { 1.073741824e9, 1e9, "Gi", "G" },
327 { 1.099511627776e12, 1e12, "Ti", "T" },
328 { 1.125899906842624e15, 1e15, "Pi", "P" },
329};
330
331 static const char unit_second_str[] = "s" ;
332 static const char unit_hertz_str[] = "Hz" ;
333 static const char unit_byte_str[] = "byte" ;
334 static const char unit_bit_per_second_str[] = "bit/s";
335
336__thread int nb_streams;
337__thread uint64_t *nb_streams_packets;
338__thread uint64_t *nb_streams_frames;
339__thread int *selected_streams;
340
341#if HAVE_THREADS
342__thread pthread_mutex_t log_mutex;
343#endif
344 typedef struct LogBuffer {
345 char *context_name;
346 int log_level;
347 char *log_message;
348 AVClassCategory category;
349 char *parent_name;
350 AVClassCategory parent_category;
351}LogBuffer;
352
353__thread LogBuffer *log_buffer;
354__thread int log_buffer_size;
355
356 static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
357{
358 AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
359 va_list vl2;
360 char line[1024];
361 static int print_prefix = 1;
362 void *new_log_buffer;
363
364 va_copy(vl2, vl);
365 av_log_default_callback(ptr, level, fmt, vl);
366 av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
367 va_end(vl2);
368
369#if HAVE_THREADS
370 pthread_mutex_lock(&log_mutex);
371
372 new_log_buffer = av_realloc_array(log_buffer, log_buffer_size + 1, sizeof(*log_buffer));
373 if (new_log_buffer) {
374 char *msg;
375 int i;
376
377 log_buffer = new_log_buffer;
378 memset(&log_buffer[log_buffer_size], 0, sizeof(log_buffer[log_buffer_size]));
379 log_buffer[log_buffer_size].context_name= avc ? av_strdup(avc->item_name(ptr)) : NULL;
380 if (avc) {
381 if (avc->get_category) log_buffer[log_buffer_size].category = avc->get_category(ptr);
382 else log_buffer[log_buffer_size].category = avc->category;
383 }
384 log_buffer[log_buffer_size].log_level = level;
385 msg = log_buffer[log_buffer_size].log_message = av_strdup(line);
386 for (i=strlen(msg) - 1; i>=0 && msg[i] == '\n'; i--) {
387 msg[i] = 0;
388 }
389 if (avc && avc->parent_log_context_offset) {
390 AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
391 avc->parent_log_context_offset);
392 if (parent && *parent) {
393 log_buffer[log_buffer_size].parent_name = av_strdup((*parent)->item_name(parent));
394 log_buffer[log_buffer_size].parent_category =
395 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
396 }
397 }
398 log_buffer_size ++;
399 }
400
401 pthread_mutex_unlock(&log_mutex);
402#endif
403}
404
405 static void ffprobe_cleanup(int ret)
406{
407 int i;
408 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
409 av_dict_free(&(sections[i].entries_to_show));
410
411#if HAVE_THREADS
412 pthread_mutex_destroy(&log_mutex);
413#endif
414}
415
416 struct unit_value {
417 union { double d; long long int i; } val;
418 const char *unit;
419};
420
421 static char *value_string(char *buf, int buf_size, struct unit_value uv)
422{
423 double vald;
424 long long int vali;
425 int show_float = 0;
426
427 if (uv.unit == unit_second_str) {
428 vald = uv.val.d;
429 show_float = 1;
430 } else {
431 vald = vali = uv.val.i;
432 }
433
434 if (uv.unit == unit_second_str && use_value_sexagesimal_format) {
435 double secs;
436 int hours, mins;
437 secs = vald;
438 mins = (int)secs / 60;
439 secs = secs - mins * 60;
440 hours = mins / 60;
441 mins %= 60;
442 snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
443 } else {
444 const char *prefix_string = "";
445
446 if (use_value_prefix && vald > 1) {
447 long long int index;
448
449 if (uv.unit == unit_byte_str && use_byte_value_binary_prefix) {
450 index = (long long int) (log2(vald)) / 10;
451 index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
452 vald /= si_prefixes[index].bin_val;
453 prefix_string = si_prefixes[index].bin_str;
454 } else {
455 index = (long long int) (log10(vald)) / 3;
456 index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
457 vald /= si_prefixes[index].dec_val;
458 prefix_string = si_prefixes[index].dec_str;
459 }
460 vali = vald;
461 }
462
463 if (show_float || (use_value_prefix && vald != (long long int)vald))
464 snprintf(buf, buf_size, "%f", vald);
465 else
466 snprintf(buf, buf_size, "%lld", vali);
467 av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || show_value_unit ? " " : "",
468 prefix_string, show_value_unit ? uv.unit : "");
469 }
470
471 return buf;
472}
473
474/* WRITERS API */
475
476 typedef struct WriterContext WriterContext;
477
478#define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
479#define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
480
481 typedef enum {
482 WRITER_STRING_VALIDATION_FAIL,
483 WRITER_STRING_VALIDATION_REPLACE,
484 WRITER_STRING_VALIDATION_IGNORE,
485 WRITER_STRING_VALIDATION_NB
486} StringValidation;
487
488 typedef struct Writer {
489 const AVClass *priv_class;
490 int priv_size;
491 const char *name;
492
493 int (*init) (WriterContext *wctx);
494 void (*uninit)(WriterContext *wctx);
495
496 void (*print_section_header)(WriterContext *wctx);
497 void (*print_section_footer)(WriterContext *wctx);
498 void (*print_integer) (WriterContext *wctx, const char *, long long int);
499 void (*print_rational) (WriterContext *wctx, AVRational *q, char *sep);
500 void (*print_string) (WriterContext *wctx, const char *, const char *);
501 int flags;
502} Writer;
503
504#define SECTION_MAX_NB_LEVELS 10
505
506 struct WriterContext {
507 const AVClass *class;
508 const Writer *writer;
509 AVIOContext *avio;
510
511 void (* writer_w8)(WriterContext *wctx, int b);
512 void (* writer_put_str)(WriterContext *wctx, const char *str);
513 void (* writer_printf)(WriterContext *wctx, const char *fmt, ...);
514
515 char *name;
516 void *priv;
517
518 const struct section *sections;
519 int nb_sections;
520
521 int level;
522
524 unsigned int nb_item[SECTION_MAX_NB_LEVELS];
525
527 const struct section *section[SECTION_MAX_NB_LEVELS];
528 AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS];
530
531 unsigned int nb_section_packet;
532 unsigned int nb_section_frame;
533 unsigned int nb_section_packet_frame;
534
535 int string_validation;
536 char *string_validation_replacement;
537 unsigned int string_validation_utf8_flags;
538};
539
540 static const char *writer_get_name(void *p)
541{
542 WriterContext *wctx = p;
543 return wctx->writer->name;
544}
545
546#define OFFSET(x) offsetof(WriterContext, x)
547
548 static const AVOption writer_options[] = {
549 { "string_validation", "set string validation mode",
550 OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
551 { "sv", "set string validation mode",
552 OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
553 { "ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_IGNORE}, .unit = "sv" },
554 { "replace", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_REPLACE}, .unit = "sv" },
555 { "fail", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_FAIL}, .unit = "sv" },
556 { "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=""}},
557 { "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str="\xEF\xBF\xBD"}},
558 { NULL }
559};
560
561 static void *writer_child_next(void *obj, void *prev)
562{
563 WriterContext *ctx = obj;
564 if (!prev && ctx->writer && ctx->writer->priv_class && ctx->priv)
565 return ctx->priv;
566 return NULL;
567}
568
569 static const AVClass writer_class = {
570 .class_name = "Writer",
571 .item_name = writer_get_name,
572 .option = writer_options,
573 .version = LIBAVUTIL_VERSION_INT,
574 .child_next = writer_child_next,
575};
576
577 static int writer_close(WriterContext **wctx)
578{
579 int i;
580 int ret = 0;
581
582 if (!*wctx)
583 return -1;
584
585 if ((*wctx)->writer->uninit)
586 (*wctx)->writer->uninit(*wctx);
587 for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
588 av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
589 if ((*wctx)->writer->priv_class)
590 av_opt_free((*wctx)->priv);
591 av_freep(&((*wctx)->priv));
592 av_opt_free(*wctx);
593 if ((*wctx)->avio) {
594 avio_flush((*wctx)->avio);
595 ret = avio_close((*wctx)->avio);
596 }
597 av_freep(wctx);
598 return ret;
599}
600
601 static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
602{
603 int i;
604 av_bprintf(bp, "0X");
605 for (i = 0; i < ubuf_size; i++)
606 av_bprintf(bp, "%02X", ubuf[i]);
607}
608
609 static inline void writer_w8_avio(WriterContext *wctx, int b)
610{
611 avio_w8(wctx->avio, b);
612}
613
614 static inline void writer_put_str_avio(WriterContext *wctx, const char *str)
615{
616 avio_write(wctx->avio, str, strlen(str));
617}
618
619 static inline void writer_printf_avio(WriterContext *wctx, const char *fmt, ...)
620{
621 va_list ap;
622
623 va_start(ap, fmt);
624 avio_vprintf(wctx->avio, fmt, ap);
625 va_end(ap);
626}
627
628 static inline void writer_w8_printf(WriterContext *wctx, int b)
629{
630 av_log(NULL, AV_LOG_STDERR, "%c", b);
631}
632
633 static inline void writer_put_str_printf(WriterContext *wctx, const char *str)
634{
635 av_log(NULL, AV_LOG_STDERR, "%s", str);
636}
637
638 static inline void writer_printf_printf(WriterContext *wctx, const char *fmt, ...)
639{
640 va_list ap;
641
642 va_start(ap, fmt);
643 av_vlog(NULL, AV_LOG_STDERR, fmt, ap);
644 va_end(ap);
645}
646
647 static int writer_open(WriterContext **wctx, const Writer *writer, const char *args,
648 const struct section *sections, int nb_sections, const char *output)
649{
650 int i, ret = 0;
651
652 if (!(*wctx = av_mallocz(sizeof(WriterContext)))) {
653 ret = AVERROR(ENOMEM);
654 goto fail;
655 }
656
657 if (!((*wctx)->priv = av_mallocz(writer->priv_size))) {
658 ret = AVERROR(ENOMEM);
659 goto fail;
660 }
661
662 (*wctx)->class = &writer_class;
663 (*wctx)->writer = writer;
664 (*wctx)->level = -1;
665 (*wctx)->sections = sections;
666 (*wctx)->nb_sections = nb_sections;
667
668 av_opt_set_defaults(*wctx);
669
670 if (writer->priv_class) {
671 void *priv_ctx = (*wctx)->priv;
672 *((const AVClass **)priv_ctx) = writer->priv_class;
673 av_opt_set_defaults(priv_ctx);
674 }
675
676 /* convert options to dictionary */
677 if (args) {
678 AVDictionary *opts = NULL;
679 const AVDictionaryEntry *opt = NULL;
680
681 if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
682 av_log(*wctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to writer context\n", args);
683 av_dict_free(&opts);
684 goto fail;
685 }
686
687 while ((opt = av_dict_iterate(opts, opt))) {
688 if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
689 av_log(*wctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to writer context\n",
690 opt->key, opt->value);
691 av_dict_free(&opts);
692 goto fail;
693 }
694 }
695
696 av_dict_free(&opts);
697 }
698
699 /* validate replace string */
700 {
701 const uint8_t *p = (*wctx)->string_validation_replacement;
702 const uint8_t *endp = p + strlen(p);
703 while (*p) {
704 const uint8_t *p0 = p;
705 int32_t code;
706 ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
707 if (ret < 0) {
708 AVBPrint bp;
709 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
710 bprint_bytes(&bp, p0, p-p0),
711 av_log(wctx, AV_LOG_ERROR,
712 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
713 bp.str, (*wctx)->string_validation_replacement);
714 return ret;
715 }
716 }
717 }
718
719 if (!output_filename) {
720 (*wctx)->writer_w8 = writer_w8_printf;
721 (*wctx)->writer_put_str = writer_put_str_printf;
722 (*wctx)->writer_printf = writer_printf_printf;
723 } else {
724 if ((ret = avio_open(&(*wctx)->avio, output, AVIO_FLAG_WRITE)) < 0) {
725 av_log(*wctx, AV_LOG_ERROR,
726 "Failed to open output '%s' with error: %s\n", output, av_err2str(ret));
727 goto fail;
728 }
729 (*wctx)->writer_w8 = writer_w8_avio;
730 (*wctx)->writer_put_str = writer_put_str_avio;
731 (*wctx)->writer_printf = writer_printf_avio;
732 }
733
734 for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
735 av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
736
737 if ((*wctx)->writer->init)
738 ret = (*wctx)->writer->init(*wctx);
739 if (ret < 0)
740 goto fail;
741
742 return 0;
743
744fail:
745 writer_close(wctx);
746 return ret;
747}
748
749 static inline void writer_print_section_header(WriterContext *wctx,
750 int section_id)
751{
752 int parent_section_id;
753 wctx->level++;
754 av_assert0(wctx->level < SECTION_MAX_NB_LEVELS);
755 parent_section_id = wctx->level ?
756 (wctx->section[wctx->level-1])->id : SECTION_ID_NONE;
757
758 wctx->nb_item[wctx->level] = 0;
759 wctx->section[wctx->level] = &wctx->sections[section_id];
760
761 if (section_id == SECTION_ID_PACKETS_AND_FRAMES) {
762 wctx->nb_section_packet = wctx->nb_section_frame =
763 wctx->nb_section_packet_frame = 0;
764 } else if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
765 wctx->nb_section_packet_frame = section_id == SECTION_ID_PACKET ?
766 wctx->nb_section_packet : wctx->nb_section_frame;
767 }
768
769 if (wctx->writer->print_section_header)
770 wctx->writer->print_section_header(wctx);
771}
772
773 static inline void writer_print_section_footer(WriterContext *wctx)
774{
775 int section_id = wctx->section[wctx->level]->id;
776 int parent_section_id = wctx->level ?
777 wctx->section[wctx->level-1]->id : SECTION_ID_NONE;
778
779 if (parent_section_id != SECTION_ID_NONE)
780 wctx->nb_item[wctx->level-1]++;
781 if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
782 if (section_id == SECTION_ID_PACKET) wctx->nb_section_packet++;
783 else wctx->nb_section_frame++;
784 }
785 if (wctx->writer->print_section_footer)
786 wctx->writer->print_section_footer(wctx);
787 wctx->level--;
788}
789
790 static inline void writer_print_integer(WriterContext *wctx,
791 const char *key, long long int val)
792{
793 const struct section *section = wctx->section[wctx->level];
794
795 if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
796 wctx->writer->print_integer(wctx, key, val);
797 wctx->nb_item[wctx->level]++;
798 }
799}
800
801 static inline int validate_string(WriterContext *wctx, char **dstp, const char *src)
802{
803 const uint8_t *p, *endp;
804 AVBPrint dstbuf;
805 int invalid_chars_nb = 0, ret = 0;
806
807 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
808
809 endp = src + strlen(src);
810 for (p = (uint8_t *)src; *p;) {
811 uint32_t code;
812 int invalid = 0;
813 const uint8_t *p0 = p;
814
815 if (av_utf8_decode(&code, &p, endp, wctx->string_validation_utf8_flags) < 0) {
816 AVBPrint bp;
817 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
818 bprint_bytes(&bp, p0, p-p0);
819 av_log(wctx, AV_LOG_DEBUG,
820 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
821 invalid = 1;
822 }
823
824 if (invalid) {
825 invalid_chars_nb++;
826
827 switch (wctx->string_validation) {
828 case WRITER_STRING_VALIDATION_FAIL:
829 av_log(wctx, AV_LOG_ERROR,
830 "Invalid UTF-8 sequence found in string '%s'\n", src);
831 ret = AVERROR_INVALIDDATA;
832 goto end;
833 break;
834
835 case WRITER_STRING_VALIDATION_REPLACE:
836 av_bprintf(&dstbuf, "%s", wctx->string_validation_replacement);
837 break;
838 }
839 }
840
841 if (!invalid || wctx->string_validation == WRITER_STRING_VALIDATION_IGNORE)
842 av_bprint_append_data(&dstbuf, p0, p-p0);
843 }
844
845 if (invalid_chars_nb && wctx->string_validation == WRITER_STRING_VALIDATION_REPLACE) {
846 av_log(wctx, AV_LOG_WARNING,
847 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
848 invalid_chars_nb, src, wctx->string_validation_replacement);
849 }
850
851end:
852 av_bprint_finalize(&dstbuf, dstp);
853 return ret;
854}
855
856#define PRINT_STRING_OPT 1
857#define PRINT_STRING_VALIDATE 2
858
859 static inline int writer_print_string(WriterContext *wctx,
860 const char *key, const char *val, int flags)
861{
862 const struct section *section = wctx->section[wctx->level];
863 int ret = 0;
864
865 if (show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER ||
866 (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO
867 && (flags & PRINT_STRING_OPT)
868 && !(wctx->writer->flags & WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS)))
869 return 0;
870
871 if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
872 if (flags & PRINT_STRING_VALIDATE) {
873 char *key1 = NULL, *val1 = NULL;
874 ret = validate_string(wctx, &key1, key);
875 if (ret < 0) goto end;
876 ret = validate_string(wctx, &val1, val);
877 if (ret < 0) goto end;
878 wctx->writer->print_string(wctx, key1, val1);
879 end:
880 if (ret < 0) {
881 av_log(wctx, AV_LOG_ERROR,
882 "Invalid key=value string combination %s=%s in section %s\n",
883 key, val, section->unique_name);
884 }
885 av_free(key1);
886 av_free(val1);
887 } else {
888 wctx->writer->print_string(wctx, key, val);
889 }
890
891 wctx->nb_item[wctx->level]++;
892 }
893
894 return ret;
895}
896
897 static inline void writer_print_rational(WriterContext *wctx,
898 const char *key, AVRational q, char sep)
899{
900 AVBPrint buf;
901 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
902 av_bprintf(&buf, "%d%c%d", q.num, sep, q.den);
903 writer_print_string(wctx, key, buf.str, 0);
904}
905
906 static void writer_print_time(WriterContext *wctx, const char *key,
907 int64_t ts, const AVRational *time_base, int is_duration)
908{
909 char buf[128];
910
911 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
912 writer_print_string(wctx, key, "N/A", PRINT_STRING_OPT);
913 } else {
914 double d = ts * av_q2d(*time_base);
915 struct unit_value uv;
916 uv.val.d = d;
917 uv.unit = unit_second_str;
918 value_string(buf, sizeof(buf), uv);
919 writer_print_string(wctx, key, buf, 0);
920 }
921}
922
923 static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
924{
925 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
926 writer_print_string(wctx, key, "N/A", PRINT_STRING_OPT);
927 } else {
928 writer_print_integer(wctx, key, ts);
929 }
930}
931
932 static void writer_print_data(WriterContext *wctx, const char *name,
933 const uint8_t *data, int size)
934{
935 AVBPrint bp;
936 int offset = 0, l, i;
937
938 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
939 av_bprintf(&bp, "\n");
940 while (size) {
941 av_bprintf(&bp, "%08x: ", offset);
942 l = FFMIN(size, 16);
943 for (i = 0; i < l; i++) {
944 av_bprintf(&bp, "%02x", data[i]);
945 if (i & 1)
946 av_bprintf(&bp, " ");
947 }
948 av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
949 for (i = 0; i < l; i++)
950 av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
951 av_bprintf(&bp, "\n");
952 offset += l;
953 data += l;
954 size -= l;
955 }
956 writer_print_string(wctx, name, bp.str, 0);
957 av_bprint_finalize(&bp, NULL);
958}
959
960 static void writer_print_data_hash(WriterContext *wctx, const char *name,
961 const uint8_t *data, int size)
962{
963 char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
964
965 if (!hash)
966 return;
967 av_hash_init(hash);
968 av_hash_update(hash, data, size);
969 snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(hash));
970 p = buf + strlen(buf);
971 av_hash_final_hex(hash, p, buf + sizeof(buf) - p);
972 writer_print_string(wctx, name, buf, 0);
973}
974
975 static void writer_print_integers(WriterContext *wctx, const char *name,
976 uint8_t *data, int size, const char *format,
977 int columns, int bytes, int offset_add)
978{
979 AVBPrint bp;
980 int offset = 0, l, i;
981
982 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
983 av_bprintf(&bp, "\n");
984 while (size) {
985 av_bprintf(&bp, "%08x: ", offset);
986 l = FFMIN(size, columns);
987 for (i = 0; i < l; i++) {
988 if (bytes == 1) av_bprintf(&bp, format, *data);
989 else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
990 else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
991 data += bytes;
992 size --;
993 }
994 av_bprintf(&bp, "\n");
995 offset += offset_add;
996 }
997 writer_print_string(wctx, name, bp.str, 0);
998 av_bprint_finalize(&bp, NULL);
999}
1000
1001#define writer_w8(wctx_, b_) (wctx_)->writer_w8(wctx_, b_)
1002#define writer_put_str(wctx_, str_) (wctx_)->writer_put_str(wctx_, str_)
1003#define writer_printf(wctx_, fmt_, ...) (wctx_)->writer_printf(wctx_, fmt_, __VA_ARGS__)
1004
1005#define MAX_REGISTERED_WRITERS_NB 64
1006
1007__thread const Writer *registered_writers[MAX_REGISTERED_WRITERS_NB + 1];
1008
1009__thread int next_registered_writer_idx = 0;
1010
1011 static int writer_register(const Writer *writer)
1012{
1013 if (next_registered_writer_idx == MAX_REGISTERED_WRITERS_NB)
1014 return AVERROR(ENOMEM);
1015
1016 registered_writers[next_registered_writer_idx++] = writer;
1017 return 0;
1018}
1019
1020 static const Writer *writer_get_by_name(const char *name)
1021{
1022 int i;
1023
1024 for (i = 0; registered_writers[i]; i++)
1025 if (!strcmp(registered_writers[i]->name, name))
1026 return registered_writers[i];
1027
1028 return NULL;
1029}
1030
1031
1032/* WRITERS */
1033
1034#define DEFINE_WRITER_CLASS(name) \
1035 static const char *name##_get_name(void *ctx) \
1036{ \
1037 return #name ; \
1038} \
1039 static const AVClass name##_class = { \
1040 .class_name = #name, \
1041 .item_name = name##_get_name, \
1042 .option = name##_options \
1043}
1044
1045/* Default output */
1046
1047 typedef struct DefaultContext {
1048 const AVClass *class;
1049 int nokey;
1050 int noprint_wrappers;
1051 int nested_section[SECTION_MAX_NB_LEVELS];
1052} DefaultContext;
1053
1054#undef OFFSET
1055#define OFFSET(x) offsetof(DefaultContext, x)
1056
1057 static const AVOption default_options[] = {
1058 { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1059 { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1060 { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1061 { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1062 {NULL},
1063};
1064
1065 DEFINE_WRITER_CLASS(default);
1066
1067/* lame uppercasing routine, assumes the string is lower case ASCII */
1068 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
1069{
1070 int i;
1071 for (i = 0; src[i] && i < dst_size-1; i++)
1072 dst[i] = av_toupper(src[i]);
1073 dst[i] = 0;
1074 return dst;
1075}
1076
1077 static void default_print_section_header(WriterContext *wctx)
1078{
1079 DefaultContext *def = wctx->priv;
1080 char buf[32];
1081 const struct section *section = wctx->section[wctx->level];
1082 const struct section *parent_section = wctx->level ?
1083 wctx->section[wctx->level-1] : NULL;
1084
1085 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
1086 if (parent_section &&
1087 !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
1088 def->nested_section[wctx->level] = 1;
1089 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
1090 wctx->section_pbuf[wctx->level-1].str,
1091 upcase_string(buf, sizeof(buf),
1092 av_x_if_null(section->element_name, section->name)));
1093 }
1094
1095 if (def->noprint_wrappers || def->nested_section[wctx->level])
1096 return;
1097
1098 if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
1099 writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
1100}
1101
1102 static void default_print_section_footer(WriterContext *wctx)
1103{
1104 DefaultContext *def = wctx->priv;
1105 const struct section *section = wctx->section[wctx->level];
1106 char buf[32];
1107
1108 if (def->noprint_wrappers || def->nested_section[wctx->level])
1109 return;
1110
1111 if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
1112 writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
1113}
1114
1115 static void default_print_str(WriterContext *wctx, const char *key, const char *value)
1116{
1117 DefaultContext *def = wctx->priv;
1118
1119 if (!def->nokey)
1120 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1121 writer_printf(wctx, "%s\n", value);
1122}
1123
1124 static void default_print_int(WriterContext *wctx, const char *key, long long int value)
1125{
1126 DefaultContext *def = wctx->priv;
1127
1128 if (!def->nokey)
1129 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1130 writer_printf(wctx, "%lld\n", value);
1131}
1132
1133 static const Writer default_writer = {
1134 .name = "default",
1135 .priv_size = sizeof(DefaultContext),
1136 .print_section_header = default_print_section_header,
1137 .print_section_footer = default_print_section_footer,
1138 .print_integer = default_print_int,
1139 .print_string = default_print_str,
1140 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
1141 .priv_class = &default_class,
1142};
1143
1144/* Compact output */
1145
1149 static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1150{
1151 const char *p;
1152
1153 for (p = src; *p; p++) {
1154 switch (*p) {
1155 case '\b': av_bprintf(dst, "%s", "\\b"); break;
1156 case '\f': av_bprintf(dst, "%s", "\\f"); break;
1157 case '\n': av_bprintf(dst, "%s", "\\n"); break;
1158 case '\r': av_bprintf(dst, "%s", "\\r"); break;
1159 case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1160 default:
1161 if (*p == sep)
1162 av_bprint_chars(dst, '\\', 1);
1163 av_bprint_chars(dst, *p, 1);
1164 }
1165 }
1166 return dst->str;
1167}
1168
1172 static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1173{
1174 char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
1175 int needs_quoting = !!src[strcspn(src, meta_chars)];
1176
1177 if (needs_quoting)
1178 av_bprint_chars(dst, '"', 1);
1179
1180 for (; *src; src++) {
1181 if (*src == '"')
1182 av_bprint_chars(dst, '"', 1);
1183 av_bprint_chars(dst, *src, 1);
1184 }
1185 if (needs_quoting)
1186 av_bprint_chars(dst, '"', 1);
1187 return dst->str;
1188}
1189
1190 static const char *none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1191{
1192 return src;
1193}
1194
1195 typedef struct CompactContext {
1196 const AVClass *class;
1197 char *item_sep_str;
1198 char item_sep;
1199 int nokey;
1200 int print_section;
1201 char *escape_mode_str;
1202 const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
1203 int nested_section[SECTION_MAX_NB_LEVELS];
1204 int has_nested_elems[SECTION_MAX_NB_LEVELS];
1205 int terminate_line[SECTION_MAX_NB_LEVELS];
1206} CompactContext;
1207
1208#undef OFFSET
1209#define OFFSET(x) offsetof(CompactContext, x)
1210
1211 static const AVOption compact_options[]= {
1212 {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 },
1213 {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 },
1214 {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1215 {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1216 {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 },
1217 {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 },
1218 {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1219 {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1220 {NULL},
1221};
1222
1223 DEFINE_WRITER_CLASS(compact);
1224
1225 static av_cold int compact_init(WriterContext *wctx)
1226{
1227 CompactContext *compact = wctx->priv;
1228
1229 if (strlen(compact->item_sep_str) != 1) {
1230 av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1231 compact->item_sep_str);
1232 return AVERROR(EINVAL);
1233 }
1234 compact->item_sep = compact->item_sep_str[0];
1235
1236 if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str;
1237 else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str;
1238 else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str;
1239 else {
1240 av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str);
1241 return AVERROR(EINVAL);
1242 }
1243
1244 return 0;
1245}
1246
1247 static void compact_print_section_header(WriterContext *wctx)
1248{
1249 CompactContext *compact = wctx->priv;
1250 const struct section *section = wctx->section[wctx->level];
1251 const struct section *parent_section = wctx->level ?
1252 wctx->section[wctx->level-1] : NULL;
1253 compact->terminate_line[wctx->level] = 1;
1254 compact->has_nested_elems[wctx->level] = 0;
1255
1256 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
1257 if (!(section->flags & SECTION_FLAG_IS_ARRAY) && parent_section &&
1258 !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
1259 compact->nested_section[wctx->level] = 1;
1260 compact->has_nested_elems[wctx->level-1] = 1;
1261 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
1262 wctx->section_pbuf[wctx->level-1].str,
1263 (char *)av_x_if_null(section->element_name, section->name));
1264 wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
1265 } else {
1266 if (parent_section && compact->has_nested_elems[wctx->level-1] &&
1267 (section->flags & SECTION_FLAG_IS_ARRAY)) {
1268 compact->terminate_line[wctx->level-1] = 0;
1269 }
1270 if (parent_section && !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)) &&
1271 wctx->level && wctx->nb_item[wctx->level-1])
1272 writer_w8(wctx, compact->item_sep);
1273 if (compact->print_section &&
1274 !(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
1275 writer_printf(wctx, "%s%c", section->name, compact->item_sep);
1276 }
1277}
1278
1279 static void compact_print_section_footer(WriterContext *wctx)
1280{
1281 CompactContext *compact = wctx->priv;
1282
1283 if (!compact->nested_section[wctx->level] &&
1284 compact->terminate_line[wctx->level] &&
1285 !(wctx->section[wctx->level]->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
1286 writer_w8(wctx, '\n');
1287}
1288
1289 static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
1290{
1291 CompactContext *compact = wctx->priv;
1292 AVBPrint buf;
1293
1294 if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep);
1295 if (!compact->nokey)
1296 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1297 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1298 writer_put_str(wctx, compact->escape_str(&buf, value, compact->item_sep, wctx));
1299 av_bprint_finalize(&buf, NULL);
1300}
1301
1302 static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
1303{
1304 CompactContext *compact = wctx->priv;
1305
1306 if (wctx->nb_item[wctx->level]) writer_w8(wctx, compact->item_sep);
1307 if (!compact->nokey)
1308 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1309 writer_printf(wctx, "%lld", value);
1310}
1311
1312 static const Writer compact_writer = {
1313 .name = "compact",
1314 .priv_size = sizeof(CompactContext),
1315 .init = compact_init,
1316 .print_section_header = compact_print_section_header,
1317 .print_section_footer = compact_print_section_footer,
1318 .print_integer = compact_print_int,
1319 .print_string = compact_print_str,
1320 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
1321 .priv_class = &compact_class,
1322};
1323
1324/* CSV output */
1325
1326#undef OFFSET
1327#define OFFSET(x) offsetof(CompactContext, x)
1328
1329 static const AVOption csv_options[] = {
1330 {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 },
1331 {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 },
1332 {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1333 {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1334 {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 },
1335 {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 },
1336 {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1337 {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1338 {NULL},
1339};
1340
1341 DEFINE_WRITER_CLASS(csv);
1342
1343 static const Writer csv_writer = {
1344 .name = "csv",
1345 .priv_size = sizeof(CompactContext),
1346 .init = compact_init,
1347 .print_section_header = compact_print_section_header,
1348 .print_section_footer = compact_print_section_footer,
1349 .print_integer = compact_print_int,
1350 .print_string = compact_print_str,
1351 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
1352 .priv_class = &csv_class,
1353};
1354
1355/* Flat output */
1356
1357 typedef struct FlatContext {
1358 const AVClass *class;
1359 const char *sep_str;
1360 char sep;
1361 int hierarchical;
1362} FlatContext;
1363
1364#undef OFFSET
1365#define OFFSET(x) offsetof(FlatContext, x)
1366
1367 static const AVOption flat_options[]= {
1368 {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 },
1369 {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 },
1370 {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1371 {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1372 {NULL},
1373};
1374
1375 DEFINE_WRITER_CLASS(flat);
1376
1377 static av_cold int flat_init(WriterContext *wctx)
1378{
1379 FlatContext *flat = wctx->priv;
1380
1381 if (strlen(flat->sep_str) != 1) {
1382 av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1383 flat->sep_str);
1384 return AVERROR(EINVAL);
1385 }
1386 flat->sep = flat->sep_str[0];
1387
1388 return 0;
1389}
1390
1391 static const char *flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
1392{
1393 const char *p;
1394
1395 for (p = src; *p; p++) {
1396 if (!((*p >= '0' && *p <= '9') ||
1397 (*p >= 'a' && *p <= 'z') ||
1398 (*p >= 'A' && *p <= 'Z')))
1399 av_bprint_chars(dst, '_', 1);
1400 else
1401 av_bprint_chars(dst, *p, 1);
1402 }
1403 return dst->str;
1404}
1405
1406 static const char *flat_escape_value_str(AVBPrint *dst, const char *src)
1407{
1408 const char *p;
1409
1410 for (p = src; *p; p++) {
1411 switch (*p) {
1412 case '\n': av_bprintf(dst, "%s", "\\n"); break;
1413 case '\r': av_bprintf(dst, "%s", "\\r"); break;
1414 case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1415 case '"': av_bprintf(dst, "%s", "\\\""); break;
1416 case '`': av_bprintf(dst, "%s", "\\`"); break;
1417 case '$': av_bprintf(dst, "%s", "\\$"); break;
1418 default: av_bprint_chars(dst, *p, 1); break;
1419 }
1420 }
1421 return dst->str;
1422}
1423
1424 static void flat_print_section_header(WriterContext *wctx)
1425{
1426 FlatContext *flat = wctx->priv;
1427 AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1428 const struct section *section = wctx->section[wctx->level];
1429 const struct section *parent_section = wctx->level ?
1430 wctx->section[wctx->level-1] : NULL;
1431
1432 /* build section header */
1433 av_bprint_clear(buf);
1434 if (!parent_section)
1435 return;
1436 av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1437
1438 if (flat->hierarchical ||
1439 !(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER))) {
1440 av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
1441
1442 if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1443 int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1444 wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1445 av_bprintf(buf, "%d%s", n, flat->sep_str);
1446 }
1447 }
1448}
1449
1450 static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
1451{
1452 writer_printf(wctx, "%s%s=%lld\n", wctx->section_pbuf[wctx->level].str, key, value);
1453}
1454
1455 static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
1456{
1457 FlatContext *flat = wctx->priv;
1458 AVBPrint buf;
1459
1460 writer_put_str(wctx, wctx->section_pbuf[wctx->level].str);
1461 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1462 writer_printf(wctx, "%s=", flat_escape_key_str(&buf, key, flat->sep));
1463 av_bprint_clear(&buf);
1464 writer_printf(wctx, "\"%s\"\n", flat_escape_value_str(&buf, value));
1465 av_bprint_finalize(&buf, NULL);
1466}
1467
1468 static const Writer flat_writer = {
1469 .name = "flat",
1470 .priv_size = sizeof(FlatContext),
1471 .init = flat_init,
1472 .print_section_header = flat_print_section_header,
1473 .print_integer = flat_print_int,
1474 .print_string = flat_print_str,
1475 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS|WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
1476 .priv_class = &flat_class,
1477};
1478
1479/* INI format output */
1480
1481 typedef struct INIContext {
1482 const AVClass *class;
1483 int hierarchical;
1484} INIContext;
1485
1486#undef OFFSET
1487#define OFFSET(x) offsetof(INIContext, x)
1488
1489 static const AVOption ini_options[] = {
1490 {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1491 {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1492 {NULL},
1493};
1494
1495 DEFINE_WRITER_CLASS(ini);
1496
1497 static char *ini_escape_str(AVBPrint *dst, const char *src)
1498{
1499 int i = 0;
1500 char c = 0;
1501
1502 while ((c = src[i++])) {
1503 switch (c) {
1504 case '\b': av_bprintf(dst, "%s", "\\b"); break;
1505 case '\f': av_bprintf(dst, "%s", "\\f"); break;
1506 case '\n': av_bprintf(dst, "%s", "\\n"); break;
1507 case '\r': av_bprintf(dst, "%s", "\\r"); break;
1508 case '\t': av_bprintf(dst, "%s", "\\t"); break;
1509 case '\\':
1510 case '#' :
1511 case '=' :
1512 case ':' : av_bprint_chars(dst, '\\', 1);
1513 default:
1514 if ((unsigned char)c < 32)
1515 av_bprintf(dst, "\\x00%02x", c & 0xff);
1516 else
1517 av_bprint_chars(dst, c, 1);
1518 break;
1519 }
1520 }
1521 return dst->str;
1522}
1523
1524 static void ini_print_section_header(WriterContext *wctx)
1525{
1526 INIContext *ini = wctx->priv;
1527 AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1528 const struct section *section = wctx->section[wctx->level];
1529 const struct section *parent_section = wctx->level ?
1530 wctx->section[wctx->level-1] : NULL;
1531
1532 av_bprint_clear(buf);
1533 if (!parent_section) {
1534 writer_put_str(wctx, "# ffprobe output\n\n");
1535 return;
1536 }
1537
1538 if (wctx->nb_item[wctx->level-1])
1539 writer_w8(wctx, '\n');
1540
1541 av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1542 if (ini->hierarchical ||
1543 !(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER))) {
1544 av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name);
1545
1546 if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1547 int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1548 wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1549 av_bprintf(buf, ".%d", n);
1550 }
1551 }
1552
1553 if (!(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER)))
1554 writer_printf(wctx, "[%s]\n", buf->str);
1555}
1556
1557 static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
1558{
1559 AVBPrint buf;
1560
1561 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1562 writer_printf(wctx, "%s=", ini_escape_str(&buf, key));
1563 av_bprint_clear(&buf);
1564 writer_printf(wctx, "%s\n", ini_escape_str(&buf, value));
1565 av_bprint_finalize(&buf, NULL);
1566}
1567
1568 static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
1569{
1570 writer_printf(wctx, "%s=%lld\n", key, value);
1571}
1572
1573 static const Writer ini_writer = {
1574 .name = "ini",
1575 .priv_size = sizeof(INIContext),
1576 .print_section_header = ini_print_section_header,
1577 .print_integer = ini_print_int,
1578 .print_string = ini_print_str,
1579 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS|WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
1580 .priv_class = &ini_class,
1581};
1582
1583/* JSON output */
1584
1585 typedef struct JSONContext {
1586 const AVClass *class;
1587 int indent_level;
1588 int compact;
1589 const char *item_sep, *item_start_end;
1590} JSONContext;
1591
1592#undef OFFSET
1593#define OFFSET(x) offsetof(JSONContext, x)
1594
1595 static const AVOption json_options[]= {
1596 { "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1597 { "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1598 { NULL }
1599};
1600
1601 DEFINE_WRITER_CLASS(json);
1602
1603 static av_cold int json_init(WriterContext *wctx)
1604{
1605 JSONContext *json = wctx->priv;
1606
1607 json->item_sep = json->compact ? ", " : ",\n";
1608 json->item_start_end = json->compact ? " " : "\n";
1609
1610 return 0;
1611}
1612
1613 static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1614{
1615 static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
1616 static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
1617 const char *p;
1618
1619 for (p = src; *p; p++) {
1620 char *s = strchr(json_escape, *p);
1621 if (s) {
1622 av_bprint_chars(dst, '\\', 1);
1623 av_bprint_chars(dst, json_subst[s - json_escape], 1);
1624 } else if ((unsigned char)*p < 32) {
1625 av_bprintf(dst, "\\u00%02x", *p & 0xff);
1626 } else {
1627 av_bprint_chars(dst, *p, 1);
1628 }
1629 }
1630 return dst->str;
1631}
1632
1633#define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ')
1634
1635 static void json_print_section_header(WriterContext *wctx)
1636{
1637 JSONContext *json = wctx->priv;
1638 AVBPrint buf;
1639 const struct section *section = wctx->section[wctx->level];
1640 const struct section *parent_section = wctx->level ?
1641 wctx->section[wctx->level-1] : NULL;
1642
1643 if (wctx->level && wctx->nb_item[wctx->level-1])
1644 writer_put_str(wctx, ",\n");
1645
1646 if (section->flags & SECTION_FLAG_IS_WRAPPER) {
1647 writer_put_str(wctx, "{\n");
1648 json->indent_level++;
1649 } else {
1650 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1651 json_escape_str(&buf, section->name, wctx);
1652 JSON_INDENT();
1653
1654 json->indent_level++;
1655 if (section->flags & SECTION_FLAG_IS_ARRAY) {
1656 writer_printf(wctx, "\"%s\": [\n", buf.str);
1657 } else if (parent_section && !(parent_section->flags & SECTION_FLAG_IS_ARRAY)) {
1658 writer_printf(wctx, "\"%s\": {%s", buf.str, json->item_start_end);
1659 } else {
1660 writer_printf(wctx, "{%s", json->item_start_end);
1661
1662 /* this is required so the parser can distinguish between packets and frames */
1663 if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) {
1664 if (!json->compact)
1665 JSON_INDENT();
1666 writer_printf(wctx, "\"type\": \"%s\"", section->name);
1667 wctx->nb_item[wctx->level]++;
1668 }
1669 }
1670 av_bprint_finalize(&buf, NULL);
1671 }
1672}
1673
1674 static void json_print_section_footer(WriterContext *wctx)
1675{
1676 JSONContext *json = wctx->priv;
1677 const struct section *section = wctx->section[wctx->level];
1678
1679 if (wctx->level == 0) {
1680 json->indent_level--;
1681 writer_put_str(wctx, "\n}\n");
1682 } else if (section->flags & SECTION_FLAG_IS_ARRAY) {
1683 writer_w8(wctx, '\n');
1684 json->indent_level--;
1685 JSON_INDENT();
1686 writer_w8(wctx, ']');
1687 } else {
1688 writer_put_str(wctx, json->item_start_end);
1689 json->indent_level--;
1690 if (!json->compact)
1691 JSON_INDENT();
1692 writer_w8(wctx, '}');
1693 }
1694}
1695
1696 static inline void json_print_item_str(WriterContext *wctx,
1697 const char *key, const char *value)
1698{
1699 AVBPrint buf;
1700
1701 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1702 writer_printf(wctx, "\"%s\":", json_escape_str(&buf, key, wctx));
1703 av_bprint_clear(&buf);
1704 writer_printf(wctx, " \"%s\"", json_escape_str(&buf, value, wctx));
1705 av_bprint_finalize(&buf, NULL);
1706}
1707
1708 static void json_print_str(WriterContext *wctx, const char *key, const char *value)
1709{
1710 JSONContext *json = wctx->priv;
1711 const struct section *parent_section = wctx->level ?
1712 wctx->section[wctx->level-1] : NULL;
1713
1714 if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES))
1715 writer_put_str(wctx, json->item_sep);
1716 if (!json->compact)
1717 JSON_INDENT();
1718 json_print_item_str(wctx, key, value);
1719}
1720
1721 static void json_print_int(WriterContext *wctx, const char *key, long long int value)
1722{
1723 JSONContext *json = wctx->priv;
1724 const struct section *parent_section = wctx->level ?
1725 wctx->section[wctx->level-1] : NULL;
1726 AVBPrint buf;
1727
1728 if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES))
1729 writer_put_str(wctx, json->item_sep);
1730 if (!json->compact)
1731 JSON_INDENT();
1732
1733 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1734 writer_printf(wctx, "\"%s\": %lld", json_escape_str(&buf, key, wctx), value);
1735 av_bprint_finalize(&buf, NULL);
1736}
1737
1738 static const Writer json_writer = {
1739 .name = "json",
1740 .priv_size = sizeof(JSONContext),
1741 .init = json_init,
1742 .print_section_header = json_print_section_header,
1743 .print_section_footer = json_print_section_footer,
1744 .print_integer = json_print_int,
1745 .print_string = json_print_str,
1746 .flags = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
1747 .priv_class = &json_class,
1748};
1749
1750/* XML output */
1751
1752 typedef struct XMLContext {
1753 const AVClass *class;
1754 int within_tag;
1755 int indent_level;
1756 int fully_qualified;
1757 int xsd_strict;
1758} XMLContext;
1759
1760#undef OFFSET
1761#define OFFSET(x) offsetof(XMLContext, x)
1762
1763 static const AVOption xml_options[] = {
1764 {"fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1765 {"q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1766 {"xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1767 {"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1768 {NULL},
1769};
1770
1771 DEFINE_WRITER_CLASS(xml);
1772
1773 static av_cold int xml_init(WriterContext *wctx)
1774{
1775 XMLContext *xml = wctx->priv;
1776
1777 if (xml->xsd_strict) {
1778 xml->fully_qualified = 1;
1779#define CHECK_COMPLIANCE(opt, opt_name) \
1780 if (opt) { \
1781 av_log(wctx, AV_LOG_ERROR, \
1782 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1783 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1784 return AVERROR(EINVAL); \
1785 }
1786 CHECK_COMPLIANCE(show_private_data, "private");
1787 CHECK_COMPLIANCE(show_value_unit, "unit");
1788 CHECK_COMPLIANCE(use_value_prefix, "prefix");
1789 }
1790
1791 return 0;
1792}
1793
1794#define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ')
1795
1796 static void xml_print_section_header(WriterContext *wctx)
1797{
1798 XMLContext *xml = wctx->priv;
1799 const struct section *section = wctx->section[wctx->level];
1800 const struct section *parent_section = wctx->level ?
1801 wctx->section[wctx->level-1] : NULL;
1802
1803 if (wctx->level == 0) {
1804 const char *qual = " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1805 "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1806 "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1807
1808 writer_put_str(wctx, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1809 writer_printf(wctx, "<%sffprobe%s>\n",
1810 xml->fully_qualified ? "ffprobe:" : "",
1811 xml->fully_qualified ? qual : "");
1812 return;
1813 }
1814
1815 if (xml->within_tag) {
1816 xml->within_tag = 0;
1817 writer_put_str(wctx, ">\n");
1818 }
1819 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1820 xml->indent_level++;
1821 } else {
1822 if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) &&
1823 wctx->level && wctx->nb_item[wctx->level-1])
1824 writer_w8(wctx, '\n');
1825 xml->indent_level++;
1826
1827 if (section->flags & SECTION_FLAG_IS_ARRAY) {
1828 XML_INDENT(); writer_printf(wctx, "<%s>\n", section->name);
1829 } else {
1830 XML_INDENT(); writer_printf(wctx, "<%s ", section->name);
1831 xml->within_tag = 1;
1832 }
1833 }
1834}
1835
1836 static void xml_print_section_footer(WriterContext *wctx)
1837{
1838 XMLContext *xml = wctx->priv;
1839 const struct section *section = wctx->section[wctx->level];
1840
1841 if (wctx->level == 0) {
1842 writer_printf(wctx, "</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : "");
1843 } else if (xml->within_tag) {
1844 xml->within_tag = 0;
1845 writer_put_str(wctx, "/>\n");
1846 xml->indent_level--;
1847 } else if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1848 xml->indent_level--;
1849 } else {
1850 XML_INDENT(); writer_printf(wctx, "</%s>\n", section->name);
1851 xml->indent_level--;
1852 }
1853}
1854
1855 static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
1856{
1857 AVBPrint buf;
1858 XMLContext *xml = wctx->priv;
1859 const struct section *section = wctx->section[wctx->level];
1860
1861 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1862
1863 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1864 XML_INDENT();
1865 av_bprint_escape(&buf, key, NULL,
1866 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1867 writer_printf(wctx, "<%s key=\"%s\"",
1868 section->element_name, buf.str);
1869 av_bprint_clear(&buf);
1870
1871 av_bprint_escape(&buf, value, NULL,
1872 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1873 writer_printf(wctx, " value=\"%s\"/>\n", buf.str);
1874 } else {
1875 if (wctx->nb_item[wctx->level])
1876 writer_w8(wctx, ' ');
1877
1878 av_bprint_escape(&buf, value, NULL,
1879 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1880 writer_printf(wctx, "%s=\"%s\"", key, buf.str);
1881 }
1882
1883 av_bprint_finalize(&buf, NULL);
1884}
1885
1886 static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
1887{
1888 if (wctx->nb_item[wctx->level])
1889 writer_w8(wctx, ' ');
1890 writer_printf(wctx, "%s=\"%lld\"", key, value);
1891}
1892
1893 static Writer xml_writer = {
1894 .name = "xml",
1895 .priv_size = sizeof(XMLContext),
1896 .init = xml_init,
1897 .print_section_header = xml_print_section_header,
1898 .print_section_footer = xml_print_section_footer,
1899 .print_integer = xml_print_int,
1900 .print_string = xml_print_str,
1901 .flags = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
1902 .priv_class = &xml_class,
1903};
1904
1905 static void writer_register_all(void)
1906{
1907
1908 writer_register(&default_writer);
1909 writer_register(&compact_writer);
1910 writer_register(&csv_writer);
1911 writer_register(&flat_writer);
1912 writer_register(&ini_writer);
1913 writer_register(&json_writer);
1914 writer_register(&xml_writer);
1915}
1916
1917#define print_fmt(k, f, ...) do { \
1918 av_bprint_clear(&pbuf); \
1919 av_bprintf(&pbuf, f, __VA_ARGS__); \
1920 writer_print_string(w, k, pbuf.str, 0); \
1921} while (0)
1922
1923#define print_list_fmt(k, f, n, m, ...) do { \
1924 av_bprint_clear(&pbuf); \
1925 for (int idx = 0; idx < n; idx++) { \
1926 for (int idx2 = 0; idx2 < m; idx2++) { \
1927 if (idx > 0 || idx2 > 0) \
1928 av_bprint_chars(&pbuf, ' ', 1); \
1929 av_bprintf(&pbuf, f, __VA_ARGS__); \
1930 } \
1931 } \
1932 writer_print_string(w, k, pbuf.str, 0); \
1933} while (0)
1934
1935#define print_int(k, v) writer_print_integer(w, k, v)
1936#define print_q(k, v, s) writer_print_rational(w, k, v, s)
1937#define print_str(k, v) writer_print_string(w, k, v, 0)
1938#define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1939#define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1940#define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1941#define print_ts(k, v) writer_print_ts(w, k, v, 0)
1942#define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1943#define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1944#define print_val(k, v, u) do { \
1945 struct unit_value uv; \
1946 uv.val.i = v; \
1947 uv.unit = u; \
1948 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1949} while (0)
1950
1951#define print_section_header(s) writer_print_section_header(w, s)
1952#define print_section_footer(s) writer_print_section_footer(w, s)
1953
1954#define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1955{ \
1956 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1957 if (ret < 0) \
1958 goto end; \
1959 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1960}
1961
1962 static inline int show_tags(WriterContext *w, AVDictionary *tags, int section_id)
1963{
1964 const AVDictionaryEntry *tag = NULL;
1965 int ret = 0;
1966
1967 if (!tags)
1968 return 0;
1969 writer_print_section_header(w, section_id);
1970
1971 while ((tag = av_dict_iterate(tags, tag))) {
1972 if ((ret = print_str_validate(tag->key, tag->value)) < 0)
1973 break;
1974 }
1975 writer_print_section_footer(w);
1976
1977 return ret;
1978}
1979
1980 static void print_dovi_metadata(WriterContext *w, const AVDOVIMetadata *dovi)
1981{
1982 if (!dovi)
1983 return;
1984
1985 {
1986 const AVDOVIRpuDataHeader *hdr = av_dovi_get_header(dovi);
1987 const AVDOVIDataMapping *mapping = av_dovi_get_mapping(dovi);
1988 const AVDOVIColorMetadata *color = av_dovi_get_color(dovi);
1989 AVBPrint pbuf;
1990
1991 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
1992
1993 // header
1994 print_int("rpu_type", hdr->rpu_type);
1995 print_int("rpu_format", hdr->rpu_format);
1996 print_int("vdr_rpu_profile", hdr->vdr_rpu_profile);
1997 print_int("vdr_rpu_level", hdr->vdr_rpu_level);
1998 print_int("chroma_resampling_explicit_filter_flag",
1999 hdr->chroma_resampling_explicit_filter_flag);
2000 print_int("coef_data_type", hdr->coef_data_type);
2001 print_int("coef_log2_denom", hdr->coef_log2_denom);
2002 print_int("vdr_rpu_normalized_idc", hdr->vdr_rpu_normalized_idc);
2003 print_int("bl_video_full_range_flag", hdr->bl_video_full_range_flag);
2004 print_int("bl_bit_depth", hdr->bl_bit_depth);
2005 print_int("el_bit_depth", hdr->el_bit_depth);
2006 print_int("vdr_bit_depth", hdr->vdr_bit_depth);
2007 print_int("spatial_resampling_filter_flag",
2008 hdr->spatial_resampling_filter_flag);
2009 print_int("el_spatial_resampling_filter_flag",
2010 hdr->el_spatial_resampling_filter_flag);
2011 print_int("disable_residual_flag", hdr->disable_residual_flag);
2012
2013 // data mapping values
2014 print_int("vdr_rpu_id", mapping->vdr_rpu_id);
2015 print_int("mapping_color_space", mapping->mapping_color_space);
2016 print_int("mapping_chroma_format_idc",
2017 mapping->mapping_chroma_format_idc);
2018
2019 print_int("nlq_method_idc", mapping->nlq_method_idc);
2020 switch (mapping->nlq_method_idc) {
2021 case AV_DOVI_NLQ_NONE:
2022 print_str("nlq_method_idc_name", "none");
2023 break;
2024 case AV_DOVI_NLQ_LINEAR_DZ:
2025 print_str("nlq_method_idc_name", "linear_dz");
2026 break;
2027 default:
2028 print_str("nlq_method_idc_name", "unknown");
2029 break;
2030 }
2031
2032 print_int("num_x_partitions", mapping->num_x_partitions);
2033 print_int("num_y_partitions", mapping->num_y_partitions);
2034
2035 writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST);
2036
2037 for (int c = 0; c < 3; c++) {
2038 const AVDOVIReshapingCurve *curve = &mapping->curves[c];
2039 writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_COMPONENT);
2040
2041 print_list_fmt("pivots", "%"PRIu16, curve->num_pivots, 1, curve->pivots[idx]);
2042
2043 writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST);
2044 for (int i = 0; i < curve->num_pivots - 1; i++) {
2045
2046 writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_PIECE);
2047 print_int("mapping_idc", curve->mapping_idc[i]);
2048 switch (curve->mapping_idc[i]) {
2049 case AV_DOVI_MAPPING_POLYNOMIAL:
2050 print_str("mapping_idc_name", "polynomial");
2051 print_int("poly_order", curve->poly_order[i]);
2052 print_list_fmt("poly_coef", "%"PRIi64,
2053 curve->poly_order[i] + 1, 1,
2054 curve->poly_coef[i][idx]);
2055 break;
2056 case AV_DOVI_MAPPING_MMR:
2057 print_str("mapping_idc_name", "mmr");
2058 print_int("mmr_order", curve->mmr_order[i]);
2059 print_int("mmr_constant", curve->mmr_constant[i]);
2060 print_list_fmt("mmr_coef", "%"PRIi64,
2061 curve->mmr_order[i], 7,
2062 curve->mmr_coef[i][idx][idx2]);
2063 break;
2064 default:
2065 print_str("mapping_idc_name", "unknown");
2066 break;
2067 }
2068
2069 // SECTION_ID_FRAME_SIDE_DATA_PIECE
2070 writer_print_section_footer(w);
2071 }
2072
2073 // SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST
2074 writer_print_section_footer(w);
2075
2076 if (mapping->nlq_method_idc != AV_DOVI_NLQ_NONE) {
2077 const AVDOVINLQParams *nlq = &mapping->nlq[c];
2078 print_int("nlq_offset", nlq->nlq_offset);
2079 print_int("vdr_in_max", nlq->vdr_in_max);
2080
2081 switch (mapping->nlq_method_idc) {
2082 case AV_DOVI_NLQ_LINEAR_DZ:
2083 print_int("linear_deadzone_slope", nlq->linear_deadzone_slope);
2084 print_int("linear_deadzone_threshold", nlq->linear_deadzone_threshold);
2085 break;
2086 }
2087 }
2088
2089 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
2090 writer_print_section_footer(w);
2091 }
2092
2093 // SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
2094 writer_print_section_footer(w);
2095
2096 // color metadata
2097 print_int("dm_metadata_id", color->dm_metadata_id);
2098 print_int("scene_refresh_flag", color->scene_refresh_flag);
2099 print_list_fmt("ycc_to_rgb_matrix", "%d/%d",
2100 FF_ARRAY_ELEMS(color->ycc_to_rgb_matrix), 1,
2101 color->ycc_to_rgb_matrix[idx].num,
2102 color->ycc_to_rgb_matrix[idx].den);
2103 print_list_fmt("ycc_to_rgb_offset", "%d/%d",
2104 FF_ARRAY_ELEMS(color->ycc_to_rgb_offset), 1,
2105 color->ycc_to_rgb_offset[idx].num,
2106 color->ycc_to_rgb_offset[idx].den);
2107 print_list_fmt("rgb_to_lms_matrix", "%d/%d",
2108 FF_ARRAY_ELEMS(color->rgb_to_lms_matrix), 1,
2109 color->rgb_to_lms_matrix[idx].num,
2110 color->rgb_to_lms_matrix[idx].den);
2111 print_int("signal_eotf", color->signal_eotf);
2112 print_int("signal_eotf_param0", color->signal_eotf_param0);
2113 print_int("signal_eotf_param1", color->signal_eotf_param1);
2114 print_int("signal_eotf_param2", color->signal_eotf_param2);
2115 print_int("signal_bit_depth", color->signal_bit_depth);
2116 print_int("signal_color_space", color->signal_color_space);
2117 print_int("signal_chroma_format", color->signal_chroma_format);
2118 print_int("signal_full_range_flag", color->signal_full_range_flag);
2119 print_int("source_min_pq", color->source_min_pq);
2120 print_int("source_max_pq", color->source_max_pq);
2121 print_int("source_diagonal", color->source_diagonal);
2122
2123 av_bprint_finalize(&pbuf, NULL);
2124 }
2125}
2126
2127 static void print_dynamic_hdr10_plus(WriterContext *w, const AVDynamicHDRPlus *metadata)
2128{
2129 if (!metadata)
2130 return;
2131 print_int("application version", metadata->application_version);
2132 print_int("num_windows", metadata->num_windows);
2133 for (int n = 1; n < metadata->num_windows; n++) {
2134 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2135 print_q("window_upper_left_corner_x",
2136 params->window_upper_left_corner_x,'/');
2137 print_q("window_upper_left_corner_y",
2138 params->window_upper_left_corner_y,'/');
2139 print_q("window_lower_right_corner_x",
2140 params->window_lower_right_corner_x,'/');
2141 print_q("window_lower_right_corner_y",
2142 params->window_lower_right_corner_y,'/');
2143 print_q("window_upper_left_corner_x",
2144 params->window_upper_left_corner_x,'/');
2145 print_q("window_upper_left_corner_y",
2146 params->window_upper_left_corner_y,'/');
2147 print_int("center_of_ellipse_x",
2148 params->center_of_ellipse_x ) ;
2149 print_int("center_of_ellipse_y",
2150 params->center_of_ellipse_y );
2151 print_int("rotation_angle",
2152 params->rotation_angle);
2153 print_int("semimajor_axis_internal_ellipse",
2154 params->semimajor_axis_internal_ellipse);
2155 print_int("semimajor_axis_external_ellipse",
2156 params->semimajor_axis_external_ellipse);
2157 print_int("semiminor_axis_external_ellipse",
2158 params->semiminor_axis_external_ellipse);
2159 print_int("overlap_process_option",
2160 params->overlap_process_option);
2161 }
2162 print_q("targeted_system_display_maximum_luminance",
2163 metadata->targeted_system_display_maximum_luminance,'/');
2164 if (metadata->targeted_system_display_actual_peak_luminance_flag) {
2165 print_int("num_rows_targeted_system_display_actual_peak_luminance",
2166 metadata->num_rows_targeted_system_display_actual_peak_luminance);
2167 print_int("num_cols_targeted_system_display_actual_peak_luminance",
2168 metadata->num_cols_targeted_system_display_actual_peak_luminance);
2169 for (int i = 0; i < metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
2170 for (int j = 0; j < metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
2171 print_q("targeted_system_display_actual_peak_luminance",
2172 metadata->targeted_system_display_actual_peak_luminance[i][j],'/');
2173 }
2174 }
2175 }
2176 for (int n = 0; n < metadata->num_windows; n++) {
2177 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2178 for (int i = 0; i < 3; i++) {
2179 print_q("maxscl",params->maxscl[i],'/');
2180 }
2181 print_q("average_maxrgb",
2182 params->average_maxrgb,'/');
2183 print_int("num_distribution_maxrgb_percentiles",
2184 params->num_distribution_maxrgb_percentiles);
2185 for (int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
2186 print_int("distribution_maxrgb_percentage",
2187 params->distribution_maxrgb[i].percentage);
2188 print_q("distribution_maxrgb_percentile",
2189 params->distribution_maxrgb[i].percentile,'/');
2190 }
2191 print_q("fraction_bright_pixels",
2192 params->fraction_bright_pixels,'/');
2193 }
2194 if (metadata->mastering_display_actual_peak_luminance_flag) {
2195 print_int("num_rows_mastering_display_actual_peak_luminance",
2196 metadata->num_rows_mastering_display_actual_peak_luminance);
2197 print_int("num_cols_mastering_display_actual_peak_luminance",
2198 metadata->num_cols_mastering_display_actual_peak_luminance);
2199 for (int i = 0; i < metadata->num_rows_mastering_display_actual_peak_luminance; i++) {
2200 for (int j = 0; j < metadata->num_cols_mastering_display_actual_peak_luminance; j++) {
2201 print_q("mastering_display_actual_peak_luminance",
2202 metadata->mastering_display_actual_peak_luminance[i][j],'/');
2203 }
2204 }
2205 }
2206
2207 for (int n = 0; n < metadata->num_windows; n++) {
2208 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2209 if (params->tone_mapping_flag) {
2210 print_q("knee_point_x", params->knee_point_x,'/');
2211 print_q("knee_point_y", params->knee_point_y,'/');
2212 print_int("num_bezier_curve_anchors",
2213 params->num_bezier_curve_anchors );
2214 for (int i = 0; i < params->num_bezier_curve_anchors; i++) {
2215 print_q("bezier_curve_anchors",
2216 params->bezier_curve_anchors[i],'/');
2217 }
2218 }
2219 if (params->color_saturation_mapping_flag) {
2220 print_q("color_saturation_weight",
2221 params->color_saturation_weight,'/');
2222 }
2223 }
2224}
2225
2226 static void print_dynamic_hdr_vivid(WriterContext *w, const AVDynamicHDRVivid *metadata)
2227{
2228 if (!metadata)
2229 return;
2230 print_int("system_start_code", metadata->system_start_code);
2231 print_int("num_windows", metadata->num_windows);
2232
2233 for (int n = 0; n < metadata->num_windows; n++) {
2234 const AVHDRVividColorTransformParams *params = &metadata->params[n];
2235
2236 print_q("minimum_maxrgb", params->minimum_maxrgb, '/');
2237 print_q("average_maxrgb", params->average_maxrgb, '/');
2238 print_q("variance_maxrgb", params->variance_maxrgb, '/');
2239 print_q("maximum_maxrgb", params->maximum_maxrgb, '/');
2240 }
2241
2242 for (int n = 0; n < metadata->num_windows; n++) {
2243 const AVHDRVividColorTransformParams *params = &metadata->params[n];
2244
2245 print_int("tone_mapping_mode_flag", params->tone_mapping_mode_flag);
2246 print_int("tone_mapping_param_num", params->tone_mapping_param_num);
2247 if (params->tone_mapping_mode_flag) {
2248 for (int i = 0; i < params->tone_mapping_param_num; i++) {
2249 const AVHDRVividColorToneMappingParams *tm_params = &params->tm_params[i];
2250
2251 print_q("targeted_system_display_maximum_luminance",
2252 tm_params->targeted_system_display_maximum_luminance, '/');
2253 print_int("base_enable_flag", tm_params->base_enable_flag);
2254 if (tm_params->base_enable_flag) {
2255 print_q("base_param_m_p", tm_params->base_param_m_p, '/');
2256 print_q("base_param_m_m", tm_params->base_param_m_m, '/');
2257 print_q("base_param_m_a", tm_params->base_param_m_a, '/');
2258 print_q("base_param_m_b", tm_params->base_param_m_b, '/');
2259 print_q("base_param_m_n", tm_params->base_param_m_n, '/');
2260
2261 print_int("base_param_k1", tm_params->base_param_k1);
2262 print_int("base_param_k2", tm_params->base_param_k2);
2263 print_int("base_param_k3", tm_params->base_param_k3);
2264 print_int("base_param_Delta_enable_mode",
2265 tm_params->base_param_Delta_enable_mode);
2266 print_q("base_param_Delta", tm_params->base_param_Delta, '/');
2267 }
2268 print_int("3Spline_enable_flag", tm_params->three_Spline_enable_flag);
2269 if (tm_params->three_Spline_enable_flag) {
2270 print_int("3Spline_num", tm_params->three_Spline_num);
2271 print_int("3Spline_TH_mode", tm_params->three_Spline_TH_mode);
2272
2273 for (int j = 0; j < tm_params->three_Spline_num; j++) {
2274 print_q("3Spline_TH_enable_MB", tm_params->three_Spline_TH_enable_MB, '/');
2275 print_q("3Spline_TH_enable", tm_params->three_Spline_TH_enable, '/');
2276 print_q("3Spline_TH_Delta1", tm_params->three_Spline_TH_Delta1, '/');
2277 print_q("3Spline_TH_Delta2", tm_params->three_Spline_TH_Delta2, '/');
2278 print_q("3Spline_enable_Strength", tm_params->three_Spline_enable_Strength, '/');
2279 }
2280 }
2281 }
2282 }
2283
2284 print_int("color_saturation_mapping_flag", params->color_saturation_mapping_flag);
2285 if (params->color_saturation_mapping_flag) {
2286 print_int("color_saturation_num", params->color_saturation_num);
2287 for (int i = 0; i < params->color_saturation_num; i++) {
2288 print_q("color_saturation_gain", params->color_saturation_gain[i], '/');
2289 }
2290 }
2291 }
2292}
2293
2294 static void print_ambient_viewing_environment(WriterContext *w,
2295 const AVAmbientViewingEnvironment *env)
2296{
2297 if (!env)
2298 return;
2299
2300 print_q("ambient_illuminance", env->ambient_illuminance, '/');
2301 print_q("ambient_light_x", env->ambient_light_x, '/');
2302 print_q("ambient_light_y", env->ambient_light_y, '/');
2303}
2304
2305 static void print_pkt_side_data(WriterContext *w,
2306 AVCodecParameters *par,
2307 const AVPacketSideData *side_data,
2308 int nb_side_data,
2309 SectionID id_data_list,
2310 SectionID id_data)
2311{
2312 int i;
2313
2314 writer_print_section_header(w, id_data_list);
2315 for (i = 0; i < nb_side_data; i++) {
2316 const AVPacketSideData *sd = &side_data[i];
2317 const char *name = av_packet_side_data_name(sd->type);
2318
2319 writer_print_section_header(w, id_data);
2320 print_str("side_data_type", name ? name : "unknown");
2321 if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2322 double rotation = av_display_rotation_get((int32_t *)sd->data);
2323 if (isnan(rotation))
2324 rotation = 0;
2325 writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
2326 print_int("rotation", rotation);
2327 } else if (sd->type == AV_PKT_DATA_STEREO3D) {
2328 const AVStereo3D *stereo = (AVStereo3D *)sd->data;
2329 print_str("type", av_stereo3d_type_name(stereo->type));
2330 print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
2331 } else if (sd->type == AV_PKT_DATA_SPHERICAL) {
2332 const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
2333 print_str("projection", av_spherical_projection_name(spherical->projection));
2334 if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
2335 print_int("padding", spherical->padding);
2336 } else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
2337 size_t l, t, r, b;
2338 av_spherical_tile_bounds(spherical, par->width, par->height,
2339 &l, &t, &r, &b);
2340 print_int("bound_left", l);
2341 print_int("bound_top", t);
2342 print_int("bound_right", r);
2343 print_int("bound_bottom", b);
2344 }
2345
2346 print_int("yaw", (double) spherical->yaw / (1 << 16));
2347 print_int("pitch", (double) spherical->pitch / (1 << 16));
2348 print_int("roll", (double) spherical->roll / (1 << 16));
2349 } else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
2350 print_int("skip_samples", AV_RL32(sd->data));
2351 print_int("discard_padding", AV_RL32(sd->data + 4));
2352 print_int("skip_reason", AV_RL8(sd->data + 8));
2353 print_int("discard_reason", AV_RL8(sd->data + 9));
2354 } else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
2355 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2356
2357 if (metadata->has_primaries) {
2358 print_q("red_x", metadata->display_primaries[0][0], '/');
2359 print_q("red_y", metadata->display_primaries[0][1], '/');
2360 print_q("green_x", metadata->display_primaries[1][0], '/');
2361 print_q("green_y", metadata->display_primaries[1][1], '/');
2362 print_q("blue_x", metadata->display_primaries[2][0], '/');
2363 print_q("blue_y", metadata->display_primaries[2][1], '/');
2364
2365 print_q("white_point_x", metadata->white_point[0], '/');
2366 print_q("white_point_y", metadata->white_point[1], '/');
2367 }
2368
2369 if (metadata->has_luminance) {
2370 print_q("min_luminance", metadata->min_luminance, '/');
2371 print_q("max_luminance", metadata->max_luminance, '/');
2372 }
2373 } else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
2374 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2375 print_int("max_content", metadata->MaxCLL);
2376 print_int("max_average", metadata->MaxFALL);
2377 } else if (sd->type == AV_PKT_DATA_DOVI_CONF) {
2378 AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord *)sd->data;
2379 print_int("dv_version_major", dovi->dv_version_major);
2380 print_int("dv_version_minor", dovi->dv_version_minor);
2381 print_int("dv_profile", dovi->dv_profile);
2382 print_int("dv_level", dovi->dv_level);
2383 print_int("rpu_present_flag", dovi->rpu_present_flag);
2384 print_int("el_present_flag", dovi->el_present_flag);
2385 print_int("bl_present_flag", dovi->bl_present_flag);
2386 print_int("dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id);
2387 } else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
2388 enum AVAudioServiceType *t = (enum AVAudioServiceType *)sd->data;
2389 print_int("service_type", *t);
2390 } else if (sd->type == AV_PKT_DATA_MPEGTS_STREAM_ID) {
2391 print_int("id", *sd->data);
2392 } else if (sd->type == AV_PKT_DATA_CPB_PROPERTIES) {
2393 const AVCPBProperties *prop = (AVCPBProperties *)sd->data;
2394 print_int("max_bitrate", prop->max_bitrate);
2395 print_int("min_bitrate", prop->min_bitrate);
2396 print_int("avg_bitrate", prop->avg_bitrate);
2397 print_int("buffer_size", prop->buffer_size);
2398 print_int("vbv_delay", prop->vbv_delay);
2399 } else if (sd->type == AV_PKT_DATA_WEBVTT_IDENTIFIER ||
2400 sd->type == AV_PKT_DATA_WEBVTT_SETTINGS) {
2401 if (do_show_data)
2402 writer_print_data(w, "data", sd->data, sd->size);
2403 writer_print_data_hash(w, "data_hash", sd->data, sd->size);
2404 } else if (sd->type == AV_PKT_DATA_AFD && sd->size > 0) {
2405 print_int("active_format", *sd->data);
2406 }
2407 writer_print_section_footer(w);
2408 }
2409 writer_print_section_footer(w);
2410}
2411
2412 static void print_color_range(WriterContext *w, enum AVColorRange color_range)
2413{
2414 const char *val = av_color_range_name(color_range);
2415 if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
2416 print_str_opt("color_range", "unknown");
2417 } else {
2418 print_str("color_range", val);
2419 }
2420}
2421
2422 static void print_color_space(WriterContext *w, enum AVColorSpace color_space)
2423{
2424 const char *val = av_color_space_name(color_space);
2425 if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
2426 print_str_opt("color_space", "unknown");
2427 } else {
2428 print_str("color_space", val);
2429 }
2430}
2431
2432 static void print_primaries(WriterContext *w, enum AVColorPrimaries color_primaries)
2433{
2434 const char *val = av_color_primaries_name(color_primaries);
2435 if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
2436 print_str_opt("color_primaries", "unknown");
2437 } else {
2438 print_str("color_primaries", val);
2439 }
2440}
2441
2442 static void print_color_trc(WriterContext *w, enum AVColorTransferCharacteristic color_trc)
2443{
2444 const char *val = av_color_transfer_name(color_trc);
2445 if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
2446 print_str_opt("color_transfer", "unknown");
2447 } else {
2448 print_str("color_transfer", val);
2449 }
2450}
2451
2452 static void print_chroma_location(WriterContext *w, enum AVChromaLocation chroma_location)
2453{
2454 const char *val = av_chroma_location_name(chroma_location);
2455 if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
2456 print_str_opt("chroma_location", "unspecified");
2457 } else {
2458 print_str("chroma_location", val);
2459 }
2460}
2461
2462
2463 static void clear_log(int need_lock)
2464{
2465 int i;
2466
2467 if (need_lock)
2468 pthread_mutex_lock(&log_mutex);
2469 for (i=0; i<log_buffer_size; i++) {
2470 av_freep(&log_buffer[i].context_name);
2471 av_freep(&log_buffer[i].parent_name);
2472 av_freep(&log_buffer[i].log_message);
2473 }
2474 log_buffer_size = 0;
2475 if(need_lock)
2476 pthread_mutex_unlock(&log_mutex);
2477}
2478
2479 static int show_log(WriterContext *w, int section_ids, int section_id, int log_level)
2480{
2481 int i;
2482 pthread_mutex_lock(&log_mutex);
2483 if (!log_buffer_size) {
2484 pthread_mutex_unlock(&log_mutex);
2485 return 0;
2486 }
2487 writer_print_section_header(w, section_ids);
2488
2489 for (i=0; i<log_buffer_size; i++) {
2490 if (log_buffer[i].log_level <= log_level) {
2491 writer_print_section_header(w, section_id);
2492 print_str("context", log_buffer[i].context_name);
2493 print_int("level", log_buffer[i].log_level);
2494 print_int("category", log_buffer[i].category);
2495 if (log_buffer[i].parent_name) {
2496 print_str("parent_context", log_buffer[i].parent_name);
2497 print_int("parent_category", log_buffer[i].parent_category);
2498 } else {
2499 print_str_opt("parent_context", "N/A");
2500 print_str_opt("parent_category", "N/A");
2501 }
2502 print_str("message", log_buffer[i].log_message);
2503 writer_print_section_footer(w);
2504 }
2505 }
2506 clear_log(0);
2507 pthread_mutex_unlock(&log_mutex);
2508
2509 writer_print_section_footer(w);
2510
2511 return 0;
2512}
2513
2514 static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int packet_idx)
2515{
2516 char val_str[128];
2517 AVStream *st = ifile->streams[pkt->stream_index].st;
2518 AVBPrint pbuf;
2519 const char *s;
2520
2521 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2522
2523 writer_print_section_header(w, SECTION_ID_PACKET);
2524
2525 s = av_get_media_type_string(st->codecpar->codec_type);
2526 if (s) print_str ("codec_type", s);
2527 else print_str_opt("codec_type", "unknown");
2528 print_int("stream_index", pkt->stream_index);
2529 print_ts ("pts", pkt->pts);
2530 print_time("pts_time", pkt->pts, &st->time_base);
2531 print_ts ("dts", pkt->dts);
2532 print_time("dts_time", pkt->dts, &st->time_base);
2533 print_duration_ts("duration", pkt->duration);
2534 print_duration_time("duration_time", pkt->duration, &st->time_base);
2535 print_val("size", pkt->size, unit_byte_str);
2536 if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos);
2537 else print_str_opt("pos", "N/A");
2538 print_fmt("flags", "%c%c%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_',
2539 pkt->flags & AV_PKT_FLAG_DISCARD ? 'D' : '_',
2540 pkt->flags & AV_PKT_FLAG_CORRUPT ? 'C' : '_');
2541 if (do_show_data)
2542 writer_print_data(w, "data", pkt->data, pkt->size);
2543 writer_print_data_hash(w, "data_hash", pkt->data, pkt->size);
2544
2545 if (pkt->side_data_elems) {
2546 size_t size;
2547 const uint8_t *side_metadata;
2548
2549 side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
2550 if (side_metadata && size && do_show_packet_tags) {
2551 AVDictionary *dict = NULL;
2552 if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
2553 show_tags(w, dict, SECTION_ID_PACKET_TAGS);
2554 av_dict_free(&dict);
2555 }
2556
2557 print_pkt_side_data(w, st->codecpar, pkt->side_data, pkt->side_data_elems,
2558 SECTION_ID_PACKET_SIDE_DATA_LIST,
2559 SECTION_ID_PACKET_SIDE_DATA);
2560 }
2561
2562 writer_print_section_footer(w);
2563
2564 av_bprint_finalize(&pbuf, NULL);
2565 fflush(stdout);
2566}
2567
2568 static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream,
2569 AVFormatContext *fmt_ctx)
2570{
2571 AVBPrint pbuf;
2572
2573 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2574
2575 writer_print_section_header(w, SECTION_ID_SUBTITLE);
2576
2577 print_str ("media_type", "subtitle");
2578 print_ts ("pts", sub->pts);
2579 print_time("pts_time", sub->pts, &AV_TIME_BASE_Q);
2580 print_int ("format", sub->format);
2581 print_int ("start_display_time", sub->start_display_time);
2582 print_int ("end_display_time", sub->end_display_time);
2583 print_int ("num_rects", sub->num_rects);
2584
2585 writer_print_section_footer(w);
2586
2587 av_bprint_finalize(&pbuf, NULL);
2588 fflush(stdout);
2589}
2590
2591 static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
2592 AVFormatContext *fmt_ctx)
2593{
2594 AVBPrint pbuf;
2595 char val_str[128];
2596 const char *s;
2597 int i;
2598
2599 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2600
2601 writer_print_section_header(w, SECTION_ID_FRAME);
2602
2603 s = av_get_media_type_string(stream->codecpar->codec_type);
2604 if (s) print_str ("media_type", s);
2605 else print_str_opt("media_type", "unknown");
2606 print_int("stream_index", stream->index);
2607 print_int("key_frame", frame->key_frame);
2608 print_ts ("pts", frame->pts);
2609 print_time("pts_time", frame->pts, &stream->time_base);
2610 print_ts ("pkt_dts", frame->pkt_dts);
2611 print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
2612 print_ts ("best_effort_timestamp", frame->best_effort_timestamp);
2613 print_time("best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
2614#if LIBAVUTIL_VERSION_MAJOR < 59
2615 AV_NOWARN_DEPRECATED(
2616 print_duration_ts ("pkt_duration", frame->pkt_duration);
2617 print_duration_time("pkt_duration_time", frame->pkt_duration, &stream->time_base);
2618 )
2619#endif
2620 print_duration_ts ("duration", frame->duration);
2621 print_duration_time("duration_time", frame->duration, &stream->time_base);
2622 if (frame->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, frame->pkt_pos);
2623 else print_str_opt("pkt_pos", "N/A");
2624 if (frame->pkt_size != -1) print_val ("pkt_size", frame->pkt_size, unit_byte_str);
2625 else print_str_opt("pkt_size", "N/A");
2626
2627 switch (stream->codecpar->codec_type) {
2628 AVRational sar;
2629
2630 case AVMEDIA_TYPE_VIDEO:
2631 print_int("width", frame->width);
2632 print_int("height", frame->height);
2633 s = av_get_pix_fmt_name(frame->format);
2634 if (s) print_str ("pix_fmt", s);
2635 else print_str_opt("pix_fmt", "unknown");
2636 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
2637 if (sar.num) {
2638 print_q("sample_aspect_ratio", sar, ':');
2639 } else {
2640 print_str_opt("sample_aspect_ratio", "N/A");
2641 }
2642 print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
2643#if LIBAVUTIL_VERSION_MAJOR < 59
2644 AV_NOWARN_DEPRECATED(
2645 print_int("coded_picture_number", frame->coded_picture_number);
2646 print_int("display_picture_number", frame->display_picture_number);
2647 )
2648#endif
2649 print_int("interlaced_frame", frame->interlaced_frame);
2650 print_int("top_field_first", frame->top_field_first);
2651 print_int("repeat_pict", frame->repeat_pict);
2652
2653 print_color_range(w, frame->color_range);
2654 print_color_space(w, frame->colorspace);
2655 print_primaries(w, frame->color_primaries);
2656 print_color_trc(w, frame->color_trc);
2657 print_chroma_location(w, frame->chroma_location);
2658 break;
2659
2660 case AVMEDIA_TYPE_AUDIO:
2661 s = av_get_sample_fmt_name(frame->format);
2662 if (s) print_str ("sample_fmt", s);
2663 else print_str_opt("sample_fmt", "unknown");
2664 print_int("nb_samples", frame->nb_samples);
2665 print_int("channels", frame->ch_layout.nb_channels);
2666 if (frame->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
2667 av_channel_layout_describe(&frame->ch_layout, val_str, sizeof(val_str));
2668 print_str ("channel_layout", val_str);
2669 } else
2670 print_str_opt("channel_layout", "unknown");
2671 break;
2672 }
2673 if (do_show_frame_tags)
2674 show_tags(w, frame->metadata, SECTION_ID_FRAME_TAGS);
2675 if (do_show_log)
2676 show_log(w, SECTION_ID_FRAME_LOGS, SECTION_ID_FRAME_LOG, do_show_log);
2677 if (frame->nb_side_data) {
2678 writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_LIST);
2679 for (i = 0; i < frame->nb_side_data; i++) {
2680 AVFrameSideData *sd = frame->side_data[i];
2681 const char *name;
2682
2683 writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA);
2684 name = av_frame_side_data_name(sd->type);
2685 print_str("side_data_type", name ? name : "unknown");
2686 if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2687 double rotation = av_display_rotation_get((int32_t *)sd->data);
2688 if (isnan(rotation))
2689 rotation = 0;
2690 writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
2691 print_int("rotation", rotation);
2692 } else if (sd->type == AV_FRAME_DATA_AFD && sd->size > 0) {
2693 print_int("active_format", *sd->data);
2694 } else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
2695 char tcbuf[AV_TIMECODE_STR_SIZE];
2696 av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
2697 print_str("timecode", tcbuf);
2698 } else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
2699 uint32_t *tc = (uint32_t*)sd->data;
2700 int m = FFMIN(tc[0],3);
2701 writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST);
2702 for (int j = 1; j <= m ; j++) {
2703 char tcbuf[AV_TIMECODE_STR_SIZE];
2704 av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
2705 writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_TIMECODE);
2706 print_str("value", tcbuf);
2707 writer_print_section_footer(w);
2708 }
2709 writer_print_section_footer(w);
2710 } else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
2711 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2712
2713 if (metadata->has_primaries) {
2714 print_q("red_x", metadata->display_primaries[0][0], '/');
2715 print_q("red_y", metadata->display_primaries[0][1], '/');
2716 print_q("green_x", metadata->display_primaries[1][0], '/');
2717 print_q("green_y", metadata->display_primaries[1][1], '/');
2718 print_q("blue_x", metadata->display_primaries[2][0], '/');
2719 print_q("blue_y", metadata->display_primaries[2][1], '/');
2720
2721 print_q("white_point_x", metadata->white_point[0], '/');
2722 print_q("white_point_y", metadata->white_point[1], '/');
2723 }
2724
2725 if (metadata->has_luminance) {
2726 print_q("min_luminance", metadata->min_luminance, '/');
2727 print_q("max_luminance", metadata->max_luminance, '/');
2728 }
2729 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
2730 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
2731 print_dynamic_hdr10_plus(w, metadata);
2732 } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
2733 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2734 print_int("max_content", metadata->MaxCLL);
2735 print_int("max_average", metadata->MaxFALL);
2736 } else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
2737 const AVDictionaryEntry *tag = av_dict_get(sd->metadata, "name", NULL, AV_DICT_MATCH_CASE);
2738 if (tag)
2739 print_str(tag->key, tag->value);
2740 print_int("size", sd->size);
2741 } else if (sd->type == AV_FRAME_DATA_DOVI_METADATA) {
2742 print_dovi_metadata(w, (const AVDOVIMetadata *)sd->data);
2743 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_VIVID) {
2744 AVDynamicHDRVivid *metadata = (AVDynamicHDRVivid *)sd->data;
2745 print_dynamic_hdr_vivid(w, metadata);
2746 } else if (sd->type == AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
2747 print_ambient_viewing_environment(
2748 w, (const AVAmbientViewingEnvironment *)sd->data);
2749 }
2750 writer_print_section_footer(w);
2751 }
2752 writer_print_section_footer(w);
2753 }
2754
2755 writer_print_section_footer(w);
2756
2757 av_bprint_finalize(&pbuf, NULL);
2758 fflush(stdout);
2759}
2760
2761 static av_always_inline int process_frame(WriterContext *w,
2762 InputFile *ifile,
2763 AVFrame *frame, const AVPacket *pkt,
2764 int *packet_new)
2765{
2766 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2767 AVCodecContext *dec_ctx = ifile->streams[pkt->stream_index].dec_ctx;
2768 AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar;
2769 AVSubtitle sub;
2770 int ret = 0, got_frame = 0;
2771
2772 clear_log(1);
2773 if (dec_ctx) {
2774 switch (par->codec_type) {
2775 case AVMEDIA_TYPE_VIDEO:
2776 case AVMEDIA_TYPE_AUDIO:
2777 if (*packet_new) {
2778 ret = avcodec_send_packet(dec_ctx, pkt);
2779 if (ret == AVERROR(EAGAIN)) {
2780 ret = 0;
2781 } else if (ret >= 0 || ret == AVERROR_EOF) {
2782 ret = 0;
2783 *packet_new = 0;
2784 }
2785 }
2786 if (ret >= 0) {
2787 ret = avcodec_receive_frame(dec_ctx, frame);
2788 if (ret >= 0) {
2789 got_frame = 1;
2790 } else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
2791 ret = 0;
2792 }
2793 }
2794 break;
2795
2796 case AVMEDIA_TYPE_SUBTITLE:
2797 if (*packet_new)
2798 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
2799 *packet_new = 0;
2800 break;
2801 default:
2802 *packet_new = 0;
2803 }
2804 } else {
2805 *packet_new = 0;
2806 }
2807
2808 if (ret < 0)
2809 return ret;
2810 if (got_frame) {
2811 int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
2812 nb_streams_frames[pkt->stream_index]++;
2813 if (do_show_frames) {
2814 if (is_sub) {
2815 show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
2816 } else {
2817 show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);
2818 }
2819 }
2820 if (is_sub) {
2821 avsubtitle_free(&sub);
2822 }
2823 }
2824 return got_frame || *packet_new;
2825}
2826
2827 static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
2828{
2829 av_log(log_ctx, log_level, "id:%d", interval->id);
2830
2831 if (interval->has_start) {
2832 av_log(log_ctx, log_level, " start:%s%s", interval->start_is_offset ? "+" : "",
2833 av_ts2timestr(interval->start, &AV_TIME_BASE_Q));
2834 } else {
2835 av_log(log_ctx, log_level, " start:N/A");
2836 }
2837
2838 if (interval->has_end) {
2839 av_log(log_ctx, log_level, " end:%s", interval->end_is_offset ? "+" : "");
2840 if (interval->duration_frames)
2841 av_log(log_ctx, log_level, "#%"PRId64, interval->end);
2842 else
2843 av_log(log_ctx, log_level, "%s", av_ts2timestr(interval->end, &AV_TIME_BASE_Q));
2844 } else {
2845 av_log(log_ctx, log_level, " end:N/A");
2846 }
2847
2848 av_log(log_ctx, log_level, "\n");
2849}
2850
2851 static int read_interval_packets(WriterContext *w, InputFile *ifile,
2852 const ReadInterval *interval, int64_t *cur_ts)
2853{
2854 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2855 AVPacket *pkt = NULL;
2856 AVFrame *frame = NULL;
2857 int ret = 0, i = 0, frame_count = 0;
2858 int64_t start = -INT64_MAX, end = interval->end;
2859 int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
2860
2861 av_log(NULL, AV_LOG_VERBOSE, "Processing read interval ");
2862 log_read_interval(interval, NULL, AV_LOG_VERBOSE);
2863
2864 if (interval->has_start) {
2865 int64_t target;
2866 if (interval->start_is_offset) {
2867 if (*cur_ts == AV_NOPTS_VALUE) {
2868 av_log(NULL, AV_LOG_ERROR,
2869 "Could not seek to relative position since current "
2870 "timestamp is not defined\n");
2871 ret = AVERROR(EINVAL);
2872 goto end;
2873 }
2874 target = *cur_ts + interval->start;
2875 } else {
2876 target = interval->start;
2877 }
2878
2879 av_log(NULL, AV_LOG_VERBOSE, "Seeking to read interval start point %s\n",
2880 av_ts2timestr(target, &AV_TIME_BASE_Q));
2881 if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
2882 av_log(NULL, AV_LOG_ERROR, "Could not seek to position %"PRId64": %s\n",
2883 interval->start, av_err2str(ret));
2884 goto end;
2885 }
2886 }
2887
2888 frame = av_frame_alloc();
2889 if (!frame) {
2890 ret = AVERROR(ENOMEM);
2891 goto end;
2892 }
2893 pkt = av_packet_alloc();
2894 if (!pkt) {
2895 ret = AVERROR(ENOMEM);
2896 goto end;
2897 }
2898 while (!av_read_frame(fmt_ctx, pkt)) {
2899 if (fmt_ctx->nb_streams > nb_streams) {
2900 REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams);
2901 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);
2902 REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams);
2903 nb_streams = fmt_ctx->nb_streams;
2904 }
2905 if (selected_streams[pkt->stream_index]) {
2906 AVRational tb = ifile->streams[pkt->stream_index].st->time_base;
2907 int64_t pts = pkt->pts != AV_NOPTS_VALUE ? pkt->pts : pkt->dts;
2908
2909 if (pts != AV_NOPTS_VALUE)
2910 *cur_ts = av_rescale_q(pts, tb, AV_TIME_BASE_Q);
2911
2912 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
2913 start = *cur_ts;
2914 has_start = 1;
2915 }
2916
2917 if (has_start && !has_end && interval->end_is_offset) {
2918 end = start + interval->end;
2919 has_end = 1;
2920 }
2921
2922 if (interval->end_is_offset && interval->duration_frames) {
2923 if (frame_count >= interval->end)
2924 break;
2925 } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
2926 break;
2927 }
2928
2929 frame_count++;
2930 if (do_read_packets) {
2931 if (do_show_packets)
2932 show_packet(w, ifile, pkt, i++);
2933 nb_streams_packets[pkt->stream_index]++;
2934 }
2935 if (do_read_frames) {
2936 int packet_new = 1;
2937 while (process_frame(w, ifile, frame, pkt, &packet_new) > 0);
2938 }
2939 }
2940 av_packet_unref(pkt);
2941 }
2942 av_packet_unref(pkt);
2943 //Flush remaining frames that are cached in the decoder
2944 for (i = 0; i < ifile->nb_streams; i++) {
2945 pkt->stream_index = i;
2946 if (do_read_frames) {
2947 while (process_frame(w, ifile, frame, pkt, &(int){1}) > 0);
2948 if (ifile->streams[i].dec_ctx)
2949 avcodec_flush_buffers(ifile->streams[i].dec_ctx);
2950 }
2951 }
2952
2953end:
2954 av_frame_free(&frame);
2955 av_packet_free(&pkt);
2956 if (ret < 0) {
2957 av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval ");
2958 log_read_interval(interval, NULL, AV_LOG_ERROR);
2959 }
2960 return ret;
2961}
2962
2963 static int read_packets(WriterContext *w, InputFile *ifile)
2964{
2965 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2966 int i, ret = 0;
2967 int64_t cur_ts = fmt_ctx->start_time;
2968
2969 if (read_intervals_nb == 0) {
2970 ReadInterval interval = (ReadInterval) { .has_start = 0, .has_end = 0 };
2971 ret = read_interval_packets(w, ifile, &interval, &cur_ts);
2972 } else {
2973 for (i = 0; i < read_intervals_nb; i++) {
2974 ret = read_interval_packets(w, ifile, &read_intervals[i], &cur_ts);
2975 if (ret < 0)
2976 break;
2977 }
2978 }
2979
2980 return ret;
2981}
2982
2983 static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int in_program)
2984{
2985 AVStream *stream = ist->st;
2986 AVCodecParameters *par;
2987 AVCodecContext *dec_ctx;
2988 char val_str[128];
2989 const char *s;
2990 AVRational sar, dar;
2991 AVBPrint pbuf;
2992 const AVCodecDescriptor *cd;
2993 int ret = 0;
2994 const char *profile = NULL;
2995
2996 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2997
2998 writer_print_section_header(w, in_program ? SECTION_ID_PROGRAM_STREAM : SECTION_ID_STREAM);
2999
3000 print_int("index", stream->index);
3001
3002 par = stream->codecpar;
3003 dec_ctx = ist->dec_ctx;
3004 if ((cd = avcodec_descriptor_get(par->codec_id))) {
3005 print_str("codec_name", cd->name);
3006 if (!do_bitexact) {
3007 print_str("codec_long_name",
3008 cd->long_name ? cd->long_name : "unknown");
3009 }
3010 } else {
3011 print_str_opt("codec_name", "unknown");
3012 if (!do_bitexact) {
3013 print_str_opt("codec_long_name", "unknown");
3014 }
3015 }
3016
3017 if (!do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
3018 print_str("profile", profile);
3019 else {
3020 if (par->profile != FF_PROFILE_UNKNOWN) {
3021 char profile_num[12];
3022 snprintf(profile_num, sizeof(profile_num), "%d", par->profile);
3023 print_str("profile", profile_num);
3024 } else
3025 print_str_opt("profile", "unknown");
3026 }
3027
3028 s = av_get_media_type_string(par->codec_type);
3029 if (s) print_str ("codec_type", s);
3030 else print_str_opt("codec_type", "unknown");
3031
3032 /* print AVI/FourCC tag */
3033 print_str("codec_tag_string", av_fourcc2str(par->codec_tag));
3034 print_fmt("codec_tag", "0x%04"PRIx32, par->codec_tag);
3035
3036 switch (par->codec_type) {
3037 case AVMEDIA_TYPE_VIDEO:
3038 print_int("width", par->width);
3039 print_int("height", par->height);
3040 if (dec_ctx) {
3041 print_int("coded_width", dec_ctx->coded_width);
3042 print_int("coded_height", dec_ctx->coded_height);
3043 print_int("closed_captions", !!(dec_ctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS));
3044 print_int("film_grain", !!(dec_ctx->properties & FF_CODEC_PROPERTY_FILM_GRAIN));
3045 }
3046 print_int("has_b_frames", par->video_delay);
3047 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
3048 if (sar.num) {
3049 print_q("sample_aspect_ratio", sar, ':');
3050 av_reduce(&dar.num, &dar.den,
3051 par->width * sar.num,
3052 par->height * sar.den,
3053 1024*1024);
3054 print_q("display_aspect_ratio", dar, ':');
3055 } else {
3056 print_str_opt("sample_aspect_ratio", "N/A");
3057 print_str_opt("display_aspect_ratio", "N/A");
3058 }
3059 s = av_get_pix_fmt_name(par->format);
3060 if (s) print_str ("pix_fmt", s);
3061 else print_str_opt("pix_fmt", "unknown");
3062 print_int("level", par->level);
3063
3064 print_color_range(w, par->color_range);
3065 print_color_space(w, par->color_space);
3066 print_color_trc(w, par->color_trc);
3067 print_primaries(w, par->color_primaries);
3068 print_chroma_location(w, par->chroma_location);
3069
3070 if (par->field_order == AV_FIELD_PROGRESSIVE)
3071 print_str("field_order", "progressive");
3072 else if (par->field_order == AV_FIELD_TT)
3073 print_str("field_order", "tt");
3074 else if (par->field_order == AV_FIELD_BB)
3075 print_str("field_order", "bb");
3076 else if (par->field_order == AV_FIELD_TB)
3077 print_str("field_order", "tb");
3078 else if (par->field_order == AV_FIELD_BT)
3079 print_str("field_order", "bt");
3080 else
3081 print_str_opt("field_order", "unknown");
3082
3083 if (dec_ctx)
3084 print_int("refs", dec_ctx->refs);
3085 break;
3086
3087 case AVMEDIA_TYPE_AUDIO:
3088 s = av_get_sample_fmt_name(par->format);
3089 if (s) print_str ("sample_fmt", s);
3090 else print_str_opt("sample_fmt", "unknown");
3091 print_val("sample_rate", par->sample_rate, unit_hertz_str);
3092 print_int("channels", par->ch_layout.nb_channels);
3093
3094 if (par->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
3095 av_channel_layout_describe(&par->ch_layout, val_str, sizeof(val_str));
3096 print_str ("channel_layout", val_str);
3097 } else {
3098 print_str_opt("channel_layout", "unknown");
3099 }
3100
3101 print_int("bits_per_sample", av_get_bits_per_sample(par->codec_id));
3102
3103 print_int("initial_padding", par->initial_padding);
3104 break;
3105
3106 case AVMEDIA_TYPE_SUBTITLE:
3107 if (par->width)
3108 print_int("width", par->width);
3109 else
3110 print_str_opt("width", "N/A");
3111 if (par->height)
3112 print_int("height", par->height);
3113 else
3114 print_str_opt("height", "N/A");
3115 break;
3116 }
3117
3118 if (dec_ctx && dec_ctx->codec->priv_class && show_private_data) {
3119 const AVOption *opt = NULL;
3120 while ((opt = av_opt_next(dec_ctx->priv_data,opt))) {
3121 uint8_t *str;
3122 if (!(opt->flags & AV_OPT_FLAG_EXPORT)) continue;
3123 if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
3124 print_str(opt->name, str);
3125 av_free(str);
3126 }
3127 }
3128 }
3129
3130 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
3131 else print_str_opt("id", "N/A");
3132 print_q("r_frame_rate", stream->r_frame_rate, '/');
3133 print_q("avg_frame_rate", stream->avg_frame_rate, '/');
3134 print_q("time_base", stream->time_base, '/');
3135 print_ts ("start_pts", stream->start_time);
3136 print_time("start_time", stream->start_time, &stream->time_base);
3137 print_ts ("duration_ts", stream->duration);
3138 print_time("duration", stream->duration, &stream->time_base);
3139 if (par->bit_rate > 0) print_val ("bit_rate", par->bit_rate, unit_bit_per_second_str);
3140 else print_str_opt("bit_rate", "N/A");
3141 if (dec_ctx && dec_ctx->rc_max_rate > 0)
3142 print_val ("max_bit_rate", dec_ctx->rc_max_rate, unit_bit_per_second_str);
3143 else
3144 print_str_opt("max_bit_rate", "N/A");
3145 if (dec_ctx && dec_ctx->bits_per_raw_sample > 0) print_fmt("bits_per_raw_sample", "%d", dec_ctx->bits_per_raw_sample);
3146 else print_str_opt("bits_per_raw_sample", "N/A");
3147 if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
3148 else print_str_opt("nb_frames", "N/A");
3149 if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
3150 else print_str_opt("nb_read_frames", "N/A");
3151 if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
3152 else print_str_opt("nb_read_packets", "N/A");
3153 if (do_show_data)
3154 writer_print_data(w, "extradata", par->extradata,
3155 par->extradata_size);
3156
3157 if (par->extradata_size > 0) {
3158 print_int("extradata_size", par->extradata_size);
3159 writer_print_data_hash(w, "extradata_hash", par->extradata,
3160 par->extradata_size);
3161 }
3162
3163 /* Print disposition information */
3164#define PRINT_DISPOSITION(flagname, name) do { \
3165 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
3166 } while (0)
3167
3168 if (do_show_stream_disposition) {
3169 writer_print_section_header(w, in_program ? SECTION_ID_PROGRAM_STREAM_DISPOSITION : SECTION_ID_STREAM_DISPOSITION);
3170 PRINT_DISPOSITION(DEFAULT, "default");
3171 PRINT_DISPOSITION(DUB, "dub");
3172 PRINT_DISPOSITION(ORIGINAL, "original");
3173 PRINT_DISPOSITION(COMMENT, "comment");
3174 PRINT_DISPOSITION(LYRICS, "lyrics");
3175 PRINT_DISPOSITION(KARAOKE, "karaoke");
3176 PRINT_DISPOSITION(FORCED, "forced");
3177 PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired");
3178 PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired");
3179 PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects");
3180 PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
3181 PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails");
3182 PRINT_DISPOSITION(CAPTIONS, "captions");
3183 PRINT_DISPOSITION(DESCRIPTIONS, "descriptions");
3184 PRINT_DISPOSITION(METADATA, "metadata");
3185 PRINT_DISPOSITION(DEPENDENT, "dependent");
3186 PRINT_DISPOSITION(STILL_IMAGE, "still_image");
3187 writer_print_section_footer(w);
3188 }
3189
3190 if (do_show_stream_tags)
3191 ret = show_tags(w, stream->metadata, in_program ? SECTION_ID_PROGRAM_STREAM_TAGS : SECTION_ID_STREAM_TAGS);
3192
3193 if (stream->nb_side_data) {
3194 print_pkt_side_data(w, stream->codecpar, stream->side_data, stream->nb_side_data,
3195 SECTION_ID_STREAM_SIDE_DATA_LIST,
3196 SECTION_ID_STREAM_SIDE_DATA);
3197 }
3198
3199 writer_print_section_footer(w);
3200 av_bprint_finalize(&pbuf, NULL);
3201 fflush(stdout);
3202
3203 return ret;
3204}
3205
3206 static int show_streams(WriterContext *w, InputFile *ifile)
3207{
3208 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3209 int i, ret = 0;
3210
3211 writer_print_section_header(w, SECTION_ID_STREAMS);
3212 for (i = 0; i < ifile->nb_streams; i++)
3213 if (selected_streams[i]) {
3214 ret = show_stream(w, fmt_ctx, i, &ifile->streams[i], 0);
3215 if (ret < 0)
3216 break;
3217 }
3218 writer_print_section_footer(w);
3219
3220 return ret;
3221}
3222
3223 static int show_program(WriterContext *w, InputFile *ifile, AVProgram *program)
3224{
3225 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3226 int i, ret = 0;
3227
3228 writer_print_section_header(w, SECTION_ID_PROGRAM);
3229 print_int("program_id", program->id);
3230 print_int("program_num", program->program_num);
3231 print_int("nb_streams", program->nb_stream_indexes);
3232 print_int("pmt_pid", program->pmt_pid);
3233 print_int("pcr_pid", program->pcr_pid);
3234 if (do_show_program_tags)
3235 ret = show_tags(w, program->metadata, SECTION_ID_PROGRAM_TAGS);
3236 if (ret < 0)
3237 goto end;
3238
3239 writer_print_section_header(w, SECTION_ID_PROGRAM_STREAMS);
3240 for (i = 0; i < program->nb_stream_indexes; i++) {
3241 if (selected_streams[program->stream_index[i]]) {
3242 ret = show_stream(w, fmt_ctx, program->stream_index[i], &ifile->streams[program->stream_index[i]], 1);
3243 if (ret < 0)
3244 break;
3245 }
3246 }
3247 writer_print_section_footer(w);
3248
3249end:
3250 writer_print_section_footer(w);
3251 return ret;
3252}
3253
3254 static int show_programs(WriterContext *w, InputFile *ifile)
3255{
3256 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3257 int i, ret = 0;
3258
3259 writer_print_section_header(w, SECTION_ID_PROGRAMS);
3260 for (i = 0; i < fmt_ctx->nb_programs; i++) {
3261 AVProgram *program = fmt_ctx->programs[i];
3262 if (!program)
3263 continue;
3264 ret = show_program(w, ifile, program);
3265 if (ret < 0)
3266 break;
3267 }
3268 writer_print_section_footer(w);
3269 return ret;
3270}
3271
3272 static int show_chapters(WriterContext *w, InputFile *ifile)
3273{
3274 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3275 int i, ret = 0;
3276
3277 writer_print_section_header(w, SECTION_ID_CHAPTERS);
3278 for (i = 0; i < fmt_ctx->nb_chapters; i++) {
3279 AVChapter *chapter = fmt_ctx->chapters[i];
3280
3281 writer_print_section_header(w, SECTION_ID_CHAPTER);
3282 print_int("id", chapter->id);
3283 print_q ("time_base", chapter->time_base, '/');
3284 print_int("start", chapter->start);
3285 print_time("start_time", chapter->start, &chapter->time_base);
3286 print_int("end", chapter->end);
3287 print_time("end_time", chapter->end, &chapter->time_base);
3288 if (do_show_chapter_tags)
3289 ret = show_tags(w, chapter->metadata, SECTION_ID_CHAPTER_TAGS);
3290 writer_print_section_footer(w);
3291 }
3292 writer_print_section_footer(w);
3293
3294 return ret;
3295}
3296
3297 static int show_format(WriterContext *w, InputFile *ifile)
3298{
3299 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3300 char val_str[128];
3301 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
3302 int ret = 0;
3303
3304 writer_print_section_header(w, SECTION_ID_FORMAT);
3305 print_str_validate("filename", fmt_ctx->url);
3306 print_int("nb_streams", fmt_ctx->nb_streams);
3307 print_int("nb_programs", fmt_ctx->nb_programs);
3308 print_str("format_name", fmt_ctx->iformat->name);
3309 if (!do_bitexact) {
3310 if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
3311 else print_str_opt("format_long_name", "unknown");
3312 }
3313 print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
3314 print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
3315 if (size >= 0) print_val ("size", size, unit_byte_str);
3316 else print_str_opt("size", "N/A");
3317 if (fmt_ctx->bit_rate > 0) print_val ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
3318 else print_str_opt("bit_rate", "N/A");
3319 print_int("probe_score", fmt_ctx->probe_score);
3320 if (do_show_format_tags)
3321 ret = show_tags(w, fmt_ctx->metadata, SECTION_ID_FORMAT_TAGS);
3322
3323 writer_print_section_footer(w);
3324 fflush(stdout);
3325 return ret;
3326}
3327
3328 static void show_error(WriterContext *w, int err)
3329{
3330 writer_print_section_header(w, SECTION_ID_ERROR);
3331 print_int("code", err);
3332 print_str("string", av_err2str(err));
3333 writer_print_section_footer(w);
3334}
3335
3336 static int open_input_file(InputFile *ifile, const char *filename,
3337 const char *print_filename)
3338{
3339 int err, i;
3340 AVFormatContext *fmt_ctx = NULL;
3341 const AVDictionaryEntry *t = NULL;
3342 int scan_all_pmts_set = 0;
3343
3344 fmt_ctx = avformat_alloc_context();
3345 if (!fmt_ctx)
3346 report_and_exit(AVERROR(ENOMEM));
3347
3348 if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
3349 av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
3350 scan_all_pmts_set = 1;
3351 }
3352 if ((err = avformat_open_input(&fmt_ctx, filename,
3353 iformat, &format_opts)) < 0) {
3354 print_error(filename, err);
3355 return err;
3356 }
3357 if (print_filename) {
3358 av_freep(&fmt_ctx->url);
3359 fmt_ctx->url = av_strdup(print_filename);
3360 }
3361 ifile->fmt_ctx = fmt_ctx;
3362 if (scan_all_pmts_set)
3363 av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
3364 while ((t = av_dict_iterate(format_opts, t)))
3365 av_log(NULL, AV_LOG_WARNING, "Option %s skipped - not known to demuxer.\n", t->key);
3366
3367 if (find_stream_info) {
3368 AVDictionary **opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
3369 int orig_nb_streams = fmt_ctx->nb_streams;
3370
3371 err = avformat_find_stream_info(fmt_ctx, opts);
3372
3373 for (i = 0; i < orig_nb_streams; i++)
3374 av_dict_free(&opts[i]);
3375 av_freep(&opts);
3376
3377 if (err < 0) {
3378 print_error(filename, err);
3379 return err;
3380 }
3381 }
3382
3383 av_dump_format(fmt_ctx, 0, filename, 0);
3384
3385 ifile->streams = av_calloc(fmt_ctx->nb_streams, sizeof(*ifile->streams));
3386 if (!ifile->streams)
3387 exit(1);
3388 ifile->nb_streams = fmt_ctx->nb_streams;
3389
3390 /* bind a decoder to each input stream */
3391 for (i = 0; i < fmt_ctx->nb_streams; i++) {
3392 InputStream *ist = &ifile->streams[i];
3393 AVStream *stream = fmt_ctx->streams[i];
3394 const AVCodec *codec;
3395
3396 ist->st = stream;
3397
3398 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
3399 av_log(NULL, AV_LOG_WARNING,
3400 "Failed to probe codec for input stream %d\n",
3401 stream->index);
3402 continue;
3403 }
3404
3405 codec = avcodec_find_decoder(stream->codecpar->codec_id);
3406 if (!codec) {
3407 av_log(NULL, AV_LOG_WARNING,
3408 "Unsupported codec with id %d for input stream %d\n",
3409 stream->codecpar->codec_id, stream->index);
3410 continue;
3411 }
3412 {
3413 AVDictionary *opts = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
3414 fmt_ctx, stream, codec);
3415
3416 ist->dec_ctx = avcodec_alloc_context3(codec);
3417 if (!ist->dec_ctx)
3418 exit(1);
3419
3420 err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
3421 if (err < 0)
3422 exit(1);
3423
3424 if (do_show_log) {
3425 // For loging it is needed to disable at least frame threads as otherwise
3426 // the log information would need to be reordered and matches up to contexts and frames
3427 // That is in fact possible but not trivial
3428 av_dict_set(&codec_opts, "threads", "1", 0);
3429 }
3430
3431 ist->dec_ctx->pkt_timebase = stream->time_base;
3432
3433 if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) {
3434 av_log(NULL, AV_LOG_WARNING, "Could not open codec for input stream %d\n",
3435 stream->index);
3436 exit(1);
3437 }
3438
3439 if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
3440 av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
3441 t->key, stream->index);
3442 return AVERROR_OPTION_NOT_FOUND;
3443 }
3444 }
3445 }
3446
3447 ifile->fmt_ctx = fmt_ctx;
3448 return 0;
3449}
3450
3451 static void close_input_file(InputFile *ifile)
3452{
3453 int i;
3454
3455 /* close decoder for each stream */
3456 for (i = 0; i < ifile->nb_streams; i++)
3457 avcodec_free_context(&ifile->streams[i].dec_ctx);
3458
3459 av_freep(&ifile->streams);
3460 ifile->nb_streams = 0;
3461
3462 avformat_close_input(&ifile->fmt_ctx);
3463}
3464
3465 static int probe_file(WriterContext *wctx, const char *filename,
3466 const char *print_filename)
3467{
3468 InputFile ifile = { 0 };
3469 int ret, i;
3470 int section_id;
3471
3472 do_read_frames = do_show_frames || do_count_frames;
3473 do_read_packets = do_show_packets || do_count_packets;
3474
3475 ret = open_input_file(&ifile, filename, print_filename);
3476 if (ret < 0)
3477 goto end;
3478
3479#define CHECK_END if (ret < 0) goto end
3480
3481 nb_streams = ifile.fmt_ctx->nb_streams;
3482 REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);
3483 REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);
3484 REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams);
3485
3486 for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
3487 if (stream_specifier) {
3488 ret = avformat_match_stream_specifier(ifile.fmt_ctx,
3489 ifile.fmt_ctx->streams[i],
3490 stream_specifier);
3491 CHECK_END;
3492 else
3493 selected_streams[i] = ret;
3494 ret = 0;
3495 } else {
3496 selected_streams[i] = 1;
3497 }
3498 if (!selected_streams[i])
3499 ifile.fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
3500 }
3501
3502 if (do_read_frames || do_read_packets) {
3503 if (do_show_frames && do_show_packets &&
3504 wctx->writer->flags & WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER)
3505 section_id = SECTION_ID_PACKETS_AND_FRAMES;
3506 else if (do_show_packets && !do_show_frames)
3507 section_id = SECTION_ID_PACKETS;
3508 else // (!do_show_packets && do_show_frames)
3509 section_id = SECTION_ID_FRAMES;
3510 if (do_show_frames || do_show_packets)
3511 writer_print_section_header(wctx, section_id);
3512 ret = read_packets(wctx, &ifile);
3513 if (do_show_frames || do_show_packets)
3514 writer_print_section_footer(wctx);
3515 CHECK_END;
3516 }
3517
3518 if (do_show_programs) {
3519 ret = show_programs(wctx, &ifile);
3520 CHECK_END;
3521 }
3522
3523 if (do_show_streams) {
3524 ret = show_streams(wctx, &ifile);
3525 CHECK_END;
3526 }
3527 if (do_show_chapters) {
3528 ret = show_chapters(wctx, &ifile);
3529 CHECK_END;
3530 }
3531 if (do_show_format) {
3532 ret = show_format(wctx, &ifile);
3533 CHECK_END;
3534 }
3535
3536end:
3537 if (ifile.fmt_ctx)
3538 close_input_file(&ifile);
3539 av_freep(&nb_streams_frames);
3540 av_freep(&nb_streams_packets);
3541 av_freep(&selected_streams);
3542
3543 return ret;
3544}
3545
3546 static void show_usage(void)
3547{
3548 av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
3549 av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] INPUT_FILE\n", program_name);
3550 av_log(NULL, AV_LOG_INFO, "\n");
3551}
3552
3553 static void ffprobe_show_program_version(WriterContext *w)
3554{
3555 AVBPrint pbuf;
3556 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3557
3558 writer_print_section_header(w, SECTION_ID_PROGRAM_VERSION);
3559 print_str("version", FFMPEG_VERSION);
3560 print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
3561 program_birth_year, CONFIG_THIS_YEAR);
3562 print_str("compiler_ident", CC_IDENT);
3563 print_str("configuration", FFMPEG_CONFIGURATION);
3564 writer_print_section_footer(w);
3565
3566 av_bprint_finalize(&pbuf, NULL);
3567}
3568
3569#define SHOW_LIB_VERSION(libname, LIBNAME) \
3570 do { \
3571 if (CONFIG_##LIBNAME) { \
3572 unsigned int version = libname##_version(); \
3573 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3574 print_str("name", "lib" #libname); \
3575 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3576 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3577 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3578 print_int("version", version); \
3579 print_str("ident", LIB##LIBNAME##_IDENT); \
3580 writer_print_section_footer(w); \
3581 } \
3582 } while (0)
3583
3584 static void ffprobe_show_library_versions(WriterContext *w)
3585{
3586 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSIONS);
3587 SHOW_LIB_VERSION(avutil, AVUTIL);
3588 SHOW_LIB_VERSION(avcodec, AVCODEC);
3589 SHOW_LIB_VERSION(avformat, AVFORMAT);
3590 SHOW_LIB_VERSION(avdevice, AVDEVICE);
3591 SHOW_LIB_VERSION(avfilter, AVFILTER);
3592 SHOW_LIB_VERSION(swscale, SWSCALE);
3593 SHOW_LIB_VERSION(swresample, SWRESAMPLE);
3594 writer_print_section_footer(w);
3595}
3596
3597#define PRINT_PIX_FMT_FLAG(flagname, name) \
3598 do { \
3599 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3600 } while (0)
3601
3602 static void ffprobe_show_pixel_formats(WriterContext *w)
3603{
3604 const AVPixFmtDescriptor *pixdesc = NULL;
3605 int i, n;
3606
3607 writer_print_section_header(w, SECTION_ID_PIXEL_FORMATS);
3608 while ((pixdesc = av_pix_fmt_desc_next(pixdesc))) {
3609 writer_print_section_header(w, SECTION_ID_PIXEL_FORMAT);
3610 print_str("name", pixdesc->name);
3611 print_int("nb_components", pixdesc->nb_components);
3612 if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
3613 print_int ("log2_chroma_w", pixdesc->log2_chroma_w);
3614 print_int ("log2_chroma_h", pixdesc->log2_chroma_h);
3615 } else {
3616 print_str_opt("log2_chroma_w", "N/A");
3617 print_str_opt("log2_chroma_h", "N/A");
3618 }
3619 n = av_get_bits_per_pixel(pixdesc);
3620 if (n) print_int ("bits_per_pixel", n);
3621 else print_str_opt("bits_per_pixel", "N/A");
3622 if (do_show_pixel_format_flags) {
3623 writer_print_section_header(w, SECTION_ID_PIXEL_FORMAT_FLAGS);
3624 PRINT_PIX_FMT_FLAG(BE, "big_endian");
3625 PRINT_PIX_FMT_FLAG(PAL, "palette");
3626 PRINT_PIX_FMT_FLAG(BITSTREAM, "bitstream");
3627 PRINT_PIX_FMT_FLAG(HWACCEL, "hwaccel");
3628 PRINT_PIX_FMT_FLAG(PLANAR, "planar");
3629 PRINT_PIX_FMT_FLAG(RGB, "rgb");
3630 PRINT_PIX_FMT_FLAG(ALPHA, "alpha");
3631 writer_print_section_footer(w);
3632 }
3633 if (do_show_pixel_format_components && (pixdesc->nb_components > 0)) {
3634 writer_print_section_header(w, SECTION_ID_PIXEL_FORMAT_COMPONENTS);
3635 for (i = 0; i < pixdesc->nb_components; i++) {
3636 writer_print_section_header(w, SECTION_ID_PIXEL_FORMAT_COMPONENT);
3637 print_int("index", i + 1);
3638 print_int("bit_depth", pixdesc->comp[i].depth);
3639 writer_print_section_footer(w);
3640 }
3641 writer_print_section_footer(w);
3642 }
3643 writer_print_section_footer(w);
3644 }
3645 writer_print_section_footer(w);
3646}
3647
3648 static int opt_show_optional_fields(void *optctx, const char *opt, const char *arg)
3649{
3650 if (!av_strcasecmp(arg, "always")) show_optional_fields = SHOW_OPTIONAL_FIELDS_ALWAYS;
3651 else if (!av_strcasecmp(arg, "never")) show_optional_fields = SHOW_OPTIONAL_FIELDS_NEVER;
3652 else if (!av_strcasecmp(arg, "auto")) show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO;
3653
3654 if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto"))
3655 show_optional_fields = parse_number_or_die("show_optional_fields", arg, OPT_INT, SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS);
3656 return 0;
3657}
3658
3659 static int opt_format(void *optctx, const char *opt, const char *arg)
3660{
3661 iformat = av_find_input_format(arg);
3662 if (!iformat) {
3663 av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
3664 return AVERROR(EINVAL);
3665 }
3666 return 0;
3667}
3668
3669 static inline void mark_section_show_entries(SectionID section_id,
3670 int show_all_entries, AVDictionary *entries)
3671{
3672 struct section *section = &sections[section_id];
3673
3674 section->show_all_entries = show_all_entries;
3675 if (show_all_entries) {
3676 SectionID *id;
3677 for (id = section->children_ids; *id != -1; id++)
3678 mark_section_show_entries(*id, show_all_entries, entries);
3679 } else {
3680 av_dict_copy(&section->entries_to_show, entries, 0);
3681 }
3682}
3683
3684 static int match_section(const char *section_name,
3685 int show_all_entries, AVDictionary *entries)
3686{
3687 int i, ret = 0;
3688
3689 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
3690 const struct section *section = &sections[i];
3691 if (!strcmp(section_name, section->name) ||
3692 (section->unique_name && !strcmp(section_name, section->unique_name))) {
3693 av_log(NULL, AV_LOG_DEBUG,
3694 "'%s' matches section with unique name '%s'\n", section_name,
3695 (char *)av_x_if_null(section->unique_name, section->name));
3696 ret++;
3697 mark_section_show_entries(section->id, show_all_entries, entries);
3698 }
3699 }
3700 return ret;
3701}
3702
3703 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
3704{
3705 const char *p = arg;
3706 int ret = 0;
3707
3708 while (*p) {
3709 AVDictionary *entries = NULL;
3710 char *section_name = av_get_token(&p, "=:");
3711 int show_all_entries = 0;
3712
3713 if (!section_name) {
3714 av_log(NULL, AV_LOG_ERROR,
3715 "Missing section name for option '%s'\n", opt);
3716 return AVERROR(EINVAL);
3717 }
3718
3719 if (*p == '=') {
3720 p++;
3721 while (*p && *p != ':') {
3722 char *entry = av_get_token(&p, ",:");
3723 if (!entry)
3724 break;
3725 av_log(NULL, AV_LOG_VERBOSE,
3726 "Adding '%s' to the entries to show in section '%s'\n",
3727 entry, section_name);
3728 av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
3729 if (*p == ',')
3730 p++;
3731 }
3732 } else {
3733 show_all_entries = 1;
3734 }
3735
3736 ret = match_section(section_name, show_all_entries, entries);
3737 if (ret == 0) {
3738 av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
3739 ret = AVERROR(EINVAL);
3740 }
3741 av_dict_free(&entries);
3742 av_free(section_name);
3743
3744 if (ret <= 0)
3745 break;
3746 if (*p)
3747 p++;
3748 }
3749
3750 return ret;
3751}
3752
3753 static void opt_input_file(void *optctx, const char *arg)
3754{
3755 if (input_filename) {
3756 av_log(NULL, AV_LOG_ERROR,
3757 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3758 arg, input_filename);
3759 exit_program(1);
3760 }
3761 if (!strcmp(arg, "-"))
3762 arg = "fd:";
3763 input_filename = arg;
3764}
3765
3766 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
3767{
3768 opt_input_file(optctx, arg);
3769 return 0;
3770}
3771
3772 static void opt_output_file(void *optctx, const char *arg)
3773{
3774 if (output_filename) {
3775 av_log(NULL, AV_LOG_ERROR,
3776 "Argument '%s' provided as output filename, but '%s' was already specified.\n",
3777 arg, output_filename);
3778 exit_program(1);
3779 }
3780 if (!strcmp(arg, "-"))
3781 arg = "fd:";
3782 output_filename = arg;
3783}
3784
3785 static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
3786{
3787 opt_output_file(optctx, arg);
3788 return 0;
3789}
3790
3791 static int opt_print_filename(void *optctx, const char *opt, const char *arg)
3792{
3793 print_input_filename = arg;
3794 return 0;
3795}
3796
3797 void show_help_default_ffprobe(const char *opt, const char *arg)
3798{
3799 show_usage();
3800 show_help_options(ffprobe_options, "Main options:", 0, 0, 0);
3801 av_log(NULL, AV_LOG_STDERR, "\n");
3802
3803 show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
3804 show_help_children(avcodec_get_class(), AV_OPT_FLAG_DECODING_PARAM);
3805}
3806
3812 static int parse_read_interval(const char *interval_spec,
3813 ReadInterval *interval)
3814{
3815 int ret = 0;
3816 char *next, *p, *spec = av_strdup(interval_spec);
3817 if (!spec)
3818 return AVERROR(ENOMEM);
3819
3820 if (!*spec) {
3821 av_log(NULL, AV_LOG_ERROR, "Invalid empty interval specification\n");
3822 ret = AVERROR(EINVAL);
3823 goto end;
3824 }
3825
3826 p = spec;
3827 next = strchr(spec, '%');
3828 if (next)
3829 *next++ = 0;
3830
3831 /* parse first part */
3832 if (*p) {
3833 interval->has_start = 1;
3834
3835 if (*p == '+') {
3836 interval->start_is_offset = 1;
3837 p++;
3838 } else {
3839 interval->start_is_offset = 0;
3840 }
3841
3842 ret = av_parse_time(&interval->start, p, 1);
3843 if (ret < 0) {
3844 av_log(NULL, AV_LOG_ERROR, "Invalid interval start specification '%s'\n", p);
3845 goto end;
3846 }
3847 } else {
3848 interval->has_start = 0;
3849 }
3850
3851 /* parse second part */
3852 p = next;
3853 if (p && *p) {
3854 int64_t us;
3855 interval->has_end = 1;
3856
3857 if (*p == '+') {
3858 interval->end_is_offset = 1;
3859 p++;
3860 } else {
3861 interval->end_is_offset = 0;
3862 }
3863
3864 if (interval->end_is_offset && *p == '#') {
3865 long long int lli;
3866 char *tail;
3867 interval->duration_frames = 1;
3868 p++;
3869 lli = strtoll(p, &tail, 10);
3870 if (*tail || lli < 0) {
3871 av_log(NULL, AV_LOG_ERROR,
3872 "Invalid or negative value '%s' for duration number of frames\n", p);
3873 goto end;
3874 }
3875 interval->end = lli;
3876 } else {
3877 interval->duration_frames = 0;
3878 ret = av_parse_time(&us, p, 1);
3879 if (ret < 0) {
3880 av_log(NULL, AV_LOG_ERROR, "Invalid interval end/duration specification '%s'\n", p);
3881 goto end;
3882 }
3883 interval->end = us;
3884 }
3885 } else {
3886 interval->has_end = 0;
3887 }
3888
3889end:
3890 av_free(spec);
3891 return ret;
3892}
3893
3894 static int parse_read_intervals(const char *intervals_spec)
3895{
3896 int ret, n, i;
3897 char *p, *spec = av_strdup(intervals_spec);
3898 if (!spec)
3899 return AVERROR(ENOMEM);
3900
3901 /* preparse specification, get number of intervals */
3902 for (n = 0, p = spec; *p; p++)
3903 if (*p == ',')
3904 n++;
3905 n++;
3906
3907 read_intervals = av_malloc_array(n, sizeof(*read_intervals));
3908 if (!read_intervals) {
3909 ret = AVERROR(ENOMEM);
3910 goto end;
3911 }
3912 read_intervals_nb = n;
3913
3914 /* parse intervals */
3915 p = spec;
3916 for (i = 0; p; i++) {
3917 char *next;
3918
3919 av_assert0(i < read_intervals_nb);
3920 next = strchr(p, ',');
3921 if (next)
3922 *next++ = 0;
3923
3924 read_intervals[i].id = i;
3925 ret = parse_read_interval(p, &read_intervals[i]);
3926 if (ret < 0) {
3927 av_log(NULL, AV_LOG_ERROR, "Error parsing read interval #%d '%s'\n",
3928 i, p);
3929 goto end;
3930 }
3931 av_log(NULL, AV_LOG_VERBOSE, "Parsed log interval ");
3932 log_read_interval(&read_intervals[i], NULL, AV_LOG_VERBOSE);
3933 p = next;
3934 }
3935 av_assert0(i == read_intervals_nb);
3936
3937end:
3938 av_free(spec);
3939 return ret;
3940}
3941
3942 static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
3943{
3944 return parse_read_intervals(arg);
3945}
3946
3947 static int opt_pretty(void *optctx, const char *opt, const char *arg)
3948{
3949 show_value_unit = 1;
3950 use_value_prefix = 1;
3951 use_byte_value_binary_prefix = 1;
3952 use_value_sexagesimal_format = 1;
3953 return 0;
3954}
3955
3956 static void print_section(SectionID id, int level)
3957{
3958 const SectionID *pid;
3959 const struct section *section = &sections[id];
3960 av_log(NULL, AV_LOG_STDERR, "%c%c%c",
3961 section->flags & SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
3962 section->flags & SECTION_FLAG_IS_ARRAY ? 'A' : '.',
3963 section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS ? 'V' : '.');
3964 av_log(NULL, AV_LOG_STDERR, "%*c %s", level * 4, ' ', section->name);
3965 if (section->unique_name)
3966 av_log(NULL, AV_LOG_STDERR, "/%s", section->unique_name);
3967 av_log(NULL, AV_LOG_STDERR, "\n");
3968
3969 for (pid = section->children_ids; *pid != -1; pid++)
3970 print_section(*pid, level+1);
3971}
3972
3973 static int opt_sections(void *optctx, const char *opt, const char *arg)
3974{
3975 av_log(NULL, AV_LOG_STDERR, "Sections:\n"
3976 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3977 ".A. = Section contains an array of elements of the same type\n"
3978 "..V = Section may contain a variable number of fields with variable keys\n"
3979 "FLAGS NAME/UNIQUE_NAME\n"
3980 "---\n");
3981 print_section(SECTION_ID_ROOT, 0);
3982 return 0;
3983}
3984
3985 static int opt_show_versions(void *optctx, const char *opt, const char *arg)
3986{
3987 mark_section_show_entries(SECTION_ID_PROGRAM_VERSION, 1, NULL);
3988 mark_section_show_entries(SECTION_ID_LIBRARY_VERSION, 1, NULL);
3989 return 0;
3990}
3991
3992#define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3993 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3994 { \
3995 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3996 return 0; \
3997 }
3998
3999 DEFINE_OPT_SHOW_SECTION(chapters, CHAPTERS)
4000 DEFINE_OPT_SHOW_SECTION(error, ERROR)
4001 DEFINE_OPT_SHOW_SECTION(format, FORMAT)
4002 DEFINE_OPT_SHOW_SECTION(frames, FRAMES)
4003 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS)
4004 DEFINE_OPT_SHOW_SECTION(packets, PACKETS)
4005 DEFINE_OPT_SHOW_SECTION(pixel_formats, PIXEL_FORMATS)
4006 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION)
4007 DEFINE_OPT_SHOW_SECTION(streams, STREAMS)
4008 DEFINE_OPT_SHOW_SECTION(programs, PROGRAMS)
4009
4010static inline int check_section_show_entries(int section_id)
4011{
4012 int *id;
4013 struct section *section = &sections[section_id];
4014 if (sections[section_id].show_all_entries || sections[section_id].entries_to_show)
4015 return 1;
4016 for (id = section->children_ids; *id != -1; id++)
4017 if (check_section_show_entries(*id))
4018 return 1;
4019 return 0;
4020}
4021
4022#define SET_DO_SHOW(id, varname) do { \
4023 if (check_section_show_entries(SECTION_ID_##id)) \
4024 do_show_##varname = 1; \
4025 } while (0)
4026
4027 void ffprobe_var_cleanup() {
4028 main_ffprobe_return_code = 0;
4029 longjmp_value = 0;
4030
4031 do_bitexact = 0;
4032 do_count_frames = 0;
4033 do_count_packets = 0;
4034 do_read_frames = 0;
4035 do_read_packets = 0;
4036 do_show_chapters = 0;
4037 do_show_error = 0;
4038 do_show_format = 0;
4039 do_show_frames = 0;
4040 do_show_packets = 0;
4041 do_show_programs = 0;
4042 do_show_streams = 0;
4043 do_show_stream_disposition = 0;
4044 do_show_data = 0;
4045 do_show_program_version = 0;
4046 do_show_library_versions = 0;
4047 do_show_pixel_formats = 0;
4048 do_show_pixel_format_flags = 0;
4049 do_show_pixel_format_components = 0;
4050 do_show_log = 0;
4051
4052 do_show_chapter_tags = 0;
4053 do_show_format_tags = 0;
4054 do_show_frame_tags = 0;
4055 do_show_program_tags = 0;
4056 do_show_stream_tags = 0;
4057 do_show_packet_tags = 0;
4058
4059 show_value_unit = 0;
4060 use_value_prefix = 0;
4061 use_byte_value_binary_prefix = 0;
4062 use_value_sexagesimal_format = 0;
4063 show_private_data = 1;
4064
4065 print_format = NULL;
4066 stream_specifier = NULL;
4067 show_data_hash = NULL;
4068
4069 read_intervals = NULL;
4070 read_intervals_nb = 0;
4071 find_stream_info = 1;
4072
4073 ffprobe_options = NULL;
4074
4075 input_filename = NULL;
4076 print_input_filename = NULL;
4077 iformat = NULL;
4078
4079 hash = NULL;
4080
4081 main_ffprobe_return_code = 0;
4082
4083 nb_streams = 0;
4084 nb_streams_packets = NULL;
4085 nb_streams_frames = NULL;
4086 selected_streams = NULL;
4087
4088 log_buffer = NULL;
4089 log_buffer_size = 0;
4090
4091 for (int i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
4092 sections[i].show_all_entries = 0;
4093 }
4094}
4095
4096 int ffprobe_execute(int argc, char **argv)
4097{
4098 char _program_name[] = "ffprobe";
4099 program_name = (char*)&_program_name;
4100 program_birth_year = 2007;
4101
4102 OptionDef options[] = {
4103 { "L", OPT_EXIT, { .func_arg = show_license }, "show license" },
4104 { "h", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" },
4105 { "?", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" },
4106 { "help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" },
4107 { "-help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" },
4108 { "version", OPT_EXIT, { .func_arg = show_version }, "show version" },
4109 { "buildconf", OPT_EXIT, { .func_arg = show_buildconf }, "show build configuration" },
4110 { "formats", OPT_EXIT, { .func_arg = show_formats }, "show available formats" },
4111 { "muxers", OPT_EXIT, { .func_arg = show_muxers }, "show available muxers" },
4112 { "demuxers", OPT_EXIT, { .func_arg = show_demuxers }, "show available demuxers" },
4113 { "devices", OPT_EXIT, { .func_arg = show_devices }, "show available devices" },
4114 { "codecs", OPT_EXIT, { .func_arg = show_codecs }, "show available codecs" },
4115 { "decoders", OPT_EXIT, { .func_arg = show_decoders }, "show available decoders" },
4116 { "encoders", OPT_EXIT, { .func_arg = show_encoders }, "show available encoders" },
4117 { "bsfs", OPT_EXIT, { .func_arg = show_bsfs }, "show available bit stream filters" },
4118 { "protocols", OPT_EXIT, { .func_arg = show_protocols }, "show available protocols" },
4119 { "filters", OPT_EXIT, { .func_arg = show_filters }, "show available filters" },
4120 { "pix_fmts", OPT_EXIT, { .func_arg = show_pix_fmts }, "show available pixel formats" },
4121 { "layouts", OPT_EXIT, { .func_arg = show_layouts }, "show standard channel layouts" },
4122 { "sample_fmts", OPT_EXIT, { .func_arg = show_sample_fmts }, "show available audio sample formats" },
4123 { "dispositions", OPT_EXIT, { .func_arg = show_dispositions}, "show available stream dispositions" },
4124 { "colors", OPT_EXIT, { .func_arg = show_colors }, "show available color names" },
4125 { "loglevel", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" },
4126 { "v", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" },
4127 { "report", 0, { .func_arg = opt_report }, "generate a report" },
4128 { "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" },
4129 { "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" },
4130 { "cpucount", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpucount }, "force specific cpu count", "count" },
4131 { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" },
4132
4133 #if CONFIG_AVDEVICE
4134 { "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources },
4135 "list sources of the input device", "device" },
4136 { "sinks" , OPT_EXIT | HAS_ARG, { .func_arg = show_sinks },
4137 "list sinks of the output device", "device" },
4138 #endif
4139
4140 { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
4141 { "unit", OPT_BOOL, {&show_value_unit}, "show unit of the displayed values" },
4142 { "prefix", OPT_BOOL, {&use_value_prefix}, "use SI prefixes for the displayed values" },
4143 { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
4144 "use binary prefixes for byte units" },
4145 { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
4146 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
4147 { "pretty", 0, {.func_arg = opt_pretty},
4148 "prettify the format of displayed values, make it more human readable" },
4149 { "print_format", OPT_STRING | HAS_ARG, { &print_format },
4150 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
4151 { "of", OPT_STRING | HAS_ARG, { &print_format }, "alias for -print_format", "format" },
4152 { "select_streams", OPT_STRING | HAS_ARG, { &stream_specifier }, "select the specified streams", "stream_specifier" },
4153 { "sections", OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
4154 { "show_data", OPT_BOOL, { &do_show_data }, "show packets data" },
4155 { "show_data_hash", OPT_STRING | HAS_ARG, { &show_data_hash }, "show packets data hash" },
4156 { "show_error", 0, { .func_arg = &opt_show_error }, "show probing error" },
4157 { "show_format", 0, { .func_arg = &opt_show_format }, "show format/container info" },
4158 { "show_frames", 0, { .func_arg = &opt_show_frames }, "show frames info" },
4159 { "show_entries", HAS_ARG, {.func_arg = opt_show_entries},
4160 "show a set of specified entries", "entry_list" },
4161 #if HAVE_THREADS
4162 { "show_log", OPT_INT|HAS_ARG, { &do_show_log }, "show log" },
4163 #endif
4164 { "show_packets", 0, { .func_arg = &opt_show_packets }, "show packets info" },
4165 { "show_programs", 0, { .func_arg = &opt_show_programs }, "show programs info" },
4166 { "show_streams", 0, { .func_arg = &opt_show_streams }, "show streams info" },
4167 { "show_chapters", 0, { .func_arg = &opt_show_chapters }, "show chapters info" },
4168 { "count_frames", OPT_BOOL, { &do_count_frames }, "count the number of frames per stream" },
4169 { "count_packets", OPT_BOOL, { &do_count_packets }, "count the number of packets per stream" },
4170 { "show_program_version", 0, { .func_arg = &opt_show_program_version }, "show ffprobe version" },
4171 { "show_library_versions", 0, { .func_arg = &opt_show_library_versions }, "show library versions" },
4172 { "show_versions", 0, { .func_arg = &opt_show_versions }, "show program and library versions" },
4173 { "show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats }, "show pixel format descriptions" },
4174 { "show_optional_fields", HAS_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" },
4175 { "show_private_data", OPT_BOOL, { &show_private_data }, "show private data" },
4176 { "private", OPT_BOOL, { &show_private_data }, "same as show_private_data" },
4177 { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" },
4178 { "read_intervals", HAS_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
4179 { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
4180 { "o", HAS_ARG, {.func_arg = opt_output_file_o}, "write to specified output", "output_file"},
4181 { "print_filename", HAS_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"},
4182 { "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
4183 "read and decode the streams to fill missing information with heuristics" },
4184 { NULL, },
4185 };
4186
4187 const Writer *w;
4188 WriterContext *wctx;
4189 char *buf;
4190 char *w_name = NULL, *w_args = NULL;
4191 int ret, input_ret, i;
4192
4193 int savedCode = setjmp(ex_buf__);
4194 if (savedCode == 0) {
4195
4196 ffprobe_var_cleanup();
4197
4198 init_dynload();
4199
4200 #if HAVE_THREADS
4201 ret = pthread_mutex_init(&log_mutex, NULL);
4202 if (ret != 0) {
4203 goto end;
4204 }
4205 #endif
4206 av_log_set_flags(AV_LOG_SKIP_REPEATED);
4207 register_exit(ffprobe_cleanup);
4208
4209 ffprobe_options = options;
4210 parse_loglevel(argc, argv, options);
4211 avformat_network_init();
4212 #if CONFIG_AVDEVICE
4213 avdevice_register_all();
4214 #endif
4215
4216 show_banner(argc, argv, options);
4217 parse_options(NULL, argc, argv, options, opt_input_file);
4218
4219 if (do_show_log)
4220 av_log_set_callback(log_callback);
4221
4222 /* mark things to show, based on -show_entries */
4223 SET_DO_SHOW(CHAPTERS, chapters);
4224 SET_DO_SHOW(ERROR, error);
4225 SET_DO_SHOW(FORMAT, format);
4226 SET_DO_SHOW(FRAMES, frames);
4227 SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
4228 SET_DO_SHOW(PACKETS, packets);
4229 SET_DO_SHOW(PIXEL_FORMATS, pixel_formats);
4230 SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
4231 SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
4232 SET_DO_SHOW(PROGRAM_VERSION, program_version);
4233 SET_DO_SHOW(PROGRAMS, programs);
4234 SET_DO_SHOW(STREAMS, streams);
4235 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
4236 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
4237
4238 SET_DO_SHOW(CHAPTER_TAGS, chapter_tags);
4239 SET_DO_SHOW(FORMAT_TAGS, format_tags);
4240 SET_DO_SHOW(FRAME_TAGS, frame_tags);
4241 SET_DO_SHOW(PROGRAM_TAGS, program_tags);
4242 SET_DO_SHOW(STREAM_TAGS, stream_tags);
4243 SET_DO_SHOW(PROGRAM_STREAM_TAGS, stream_tags);
4244 SET_DO_SHOW(PACKET_TAGS, packet_tags);
4245
4246 if (do_bitexact && (do_show_program_version || do_show_library_versions)) {
4247 av_log(NULL, AV_LOG_ERROR,
4248 "-bitexact and -show_program_version or -show_library_versions "
4249 "options are incompatible\n");
4250 ret = AVERROR(EINVAL);
4251 goto end;
4252 }
4253
4254 writer_register_all();
4255
4256 if (!print_format)
4257 print_format = av_strdup("default");
4258 if (!print_format) {
4259 ret = AVERROR(ENOMEM);
4260 goto end;
4261 }
4262 w_name = av_strtok(print_format, "=", &buf);
4263 if (!w_name) {
4264 av_log(NULL, AV_LOG_ERROR,
4265 "No name specified for the output format\n");
4266 ret = AVERROR(EINVAL);
4267 goto end;
4268 }
4269 w_args = buf;
4270
4271 if (show_data_hash) {
4272 if ((ret = av_hash_alloc(&hash, show_data_hash)) < 0) {
4273 if (ret == AVERROR(EINVAL)) {
4274 const char *n;
4275 av_log(NULL, AV_LOG_ERROR,
4276 "Unknown hash algorithm '%s'\nKnown algorithms:",
4277 show_data_hash);
4278 for (i = 0; (n = av_hash_names(i)); i++)
4279 av_log(NULL, AV_LOG_ERROR, " %s", n);
4280 av_log(NULL, AV_LOG_ERROR, "\n");
4281 }
4282 goto end;
4283 }
4284 }
4285
4286 w = writer_get_by_name(w_name);
4287 if (!w) {
4288 av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
4289 ret = AVERROR(EINVAL);
4290 goto end;
4291 }
4292
4293 if ((ret = writer_open(&wctx, w, w_args,
4294 sections, FF_ARRAY_ELEMS(sections), output_filename)) >= 0) {
4295 if (w == &xml_writer)
4296 wctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;
4297
4298 writer_print_section_header(wctx, SECTION_ID_ROOT);
4299
4300 if (do_show_program_version)
4301 ffprobe_show_program_version(wctx);
4302 if (do_show_library_versions)
4303 ffprobe_show_library_versions(wctx);
4304 if (do_show_pixel_formats)
4305 ffprobe_show_pixel_formats(wctx);
4306
4307 if (!input_filename &&
4308 ((do_show_format || do_show_programs || do_show_streams || do_show_chapters || do_show_packets || do_show_error) ||
4309 (!do_show_program_version && !do_show_library_versions && !do_show_pixel_formats))) {
4310 show_usage();
4311 av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
4312 av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
4313 ret = AVERROR(EINVAL);
4314 } else if (input_filename) {
4315 ret = probe_file(wctx, input_filename, print_input_filename);
4316 if (ret < 0 && do_show_error)
4317 show_error(wctx, ret);
4318 }
4319
4320 input_ret = ret;
4321
4322 writer_print_section_footer(wctx);
4323 ret = writer_close(&wctx);
4324 if (ret < 0)
4325 av_log(NULL, AV_LOG_ERROR, "Writing output failed: %s\n", av_err2str(ret));
4326
4327 ret = FFMIN(ret, input_ret);
4328 }
4329
4330 main_ffprobe_return_code = ret < 0;
4331
4332 } else {
4333 main_ffprobe_return_code = longjmp_value;
4334 }
4335
4336end:
4337 av_freep(&print_format);
4338 av_freep(&read_intervals);
4339 av_hash_freep(&hash);
4340
4341 uninit_opts();
4342 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
4343 av_dict_free(&(sections[i].entries_to_show));
4344
4345 avformat_network_deinit();
4346
4347 return main_ffprobe_return_code;
4348}
ffmpegkit_exception.h
ex_buf__
__thread jmp_buf ex_buf__
Definition ffmpegkit_exception.m:23
exit_program
void exit_program(int ret)
Definition fftools_cmdutils.c:145
show_help_children
void show_help_children(const AVClass *class, int flags)
Definition fftools_cmdutils.c:219
codec_opts
__thread AVDictionary * codec_opts
Definition fftools_cmdutils.c:110
init_dynload
void init_dynload(void)
Definition fftools_cmdutils.c:123
show_help_options
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Definition fftools_cmdutils.c:190
format_opts
__thread AVDictionary * format_opts
Definition fftools_cmdutils.c:110
print_error
void print_error(const char *filename, int err)
Definition fftools_cmdutils.c:858
report_and_exit
void report_and_exit(int ret)
Definition fftools_cmdutils.c:139
program_name
__thread char * program_name
Definition fftools_cmdutils.c:105
parse_loglevel
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Definition fftools_cmdutils.c:528
program_birth_year
__thread int program_birth_year
Definition fftools_cmdutils.c:106
parse_options
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
Definition fftools_cmdutils.c:401
register_exit
void register_exit(void(*cb)(int ret))
Definition fftools_cmdutils.c:134
uninit_opts
void uninit_opts(void)
Definition fftools_cmdutils.c:115
filter_codec_opts
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec)
Definition fftools_cmdutils.c:954
hide_banner
__thread int hide_banner
Definition fftools_cmdutils.c:112
parse_number_or_die
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Definition fftools_cmdutils.c:157
setup_find_stream_info_opts
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Definition fftools_cmdutils.c:1012
fftools_cmdutils.h
OPT_BOOL
#define OPT_BOOL
Definition fftools_cmdutils.h:198
OPT_INT
#define OPT_INT
Definition fftools_cmdutils.h:203
AV_LOG_STDERR
#define AV_LOG_STDERR
Definition fftools_cmdutils.h:82
OPT_INPUT
#define OPT_INPUT
Definition fftools_cmdutils.h:214
OPT_STRING
#define OPT_STRING
Definition fftools_cmdutils.h:200
show_banner
void show_banner(int argc, char **argv, const OptionDef *options)
Definition fftools_opt_common.c:262
OPT_EXPERT
#define OPT_EXPERT
Definition fftools_cmdutils.h:199
OPT_EXIT
#define OPT_EXIT
Definition fftools_cmdutils.h:207
HAS_ARG
#define HAS_ARG
Definition fftools_cmdutils.h:197
d
d
Definition fftools_ffmpeg_filter.c:180
int
int
Definition fftools_ffmpeg_filter.c:180
show_usage
static void show_usage(void)
Definition fftools_ffprobe.c:3546
read_intervals_nb
__thread int read_intervals_nb
Definition fftools_ffprobe.c:174
writer_w8_avio
static void writer_w8_avio(WriterContext *wctx, int b)
Definition fftools_ffprobe.c:609
writer_w8
#define writer_w8(wctx_, b_)
Definition fftools_ffprobe.c:1001
log_callback
static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
Definition fftools_ffprobe.c:356
print_list_fmt
#define print_list_fmt(k, f, n, m,...)
Definition fftools_ffprobe.c:1923
do_show_library_versions
__thread int do_show_library_versions
Definition fftools_ffprobe.c:137
SectionID
SectionID
Definition fftools_ffprobe.c:198
SECTION_ID_FRAME_SIDE_DATA
@ SECTION_ID_FRAME_SIDE_DATA
Definition fftools_ffprobe.c:210
SECTION_ID_STREAM_TAGS
@ SECTION_ID_STREAM_TAGS
Definition fftools_ffprobe.c:244
SECTION_ID_PROGRAM_STREAM
@ SECTION_ID_PROGRAM_STREAM
Definition fftools_ffprobe.c:236
SECTION_ID_PACKET
@ SECTION_ID_PACKET
Definition fftools_ffprobe.c:221
SECTION_ID_PROGRAM_VERSION
@ SECTION_ID_PROGRAM_VERSION
Definition fftools_ffprobe.c:238
SECTION_ID_PIXEL_FORMAT_FLAGS
@ SECTION_ID_PIXEL_FORMAT_FLAGS
Definition fftools_ffprobe.c:228
SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
@ SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
Definition fftools_ffprobe.c:213
SECTION_ID_PROGRAM_TAGS
@ SECTION_ID_PROGRAM_TAGS
Definition fftools_ffprobe.c:237
SECTION_ID_PIXEL_FORMATS
@ SECTION_ID_PIXEL_FORMATS
Definition fftools_ffprobe.c:231
SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST
@ SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST
Definition fftools_ffprobe.c:215
SECTION_ID_STREAM
@ SECTION_ID_STREAM
Definition fftools_ffprobe.c:241
SECTION_ID_LIBRARY_VERSION
@ SECTION_ID_LIBRARY_VERSION
Definition fftools_ffprobe.c:219
SECTION_ID_NONE
@ SECTION_ID_NONE
Definition fftools_ffprobe.c:199
SECTION_ID_FRAMES
@ SECTION_ID_FRAMES
Definition fftools_ffprobe.c:207
SECTION_ID_STREAM_SIDE_DATA
@ SECTION_ID_STREAM_SIDE_DATA
Definition fftools_ffprobe.c:246
SECTION_ID_PACKETS_AND_FRAMES
@ SECTION_ID_PACKETS_AND_FRAMES
Definition fftools_ffprobe.c:224
SECTION_ID_PACKET_SIDE_DATA_LIST
@ SECTION_ID_PACKET_SIDE_DATA_LIST
Definition fftools_ffprobe.c:225
SECTION_ID_PROGRAM_STREAM_DISPOSITION
@ SECTION_ID_PROGRAM_STREAM_DISPOSITION
Definition fftools_ffprobe.c:232
SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST
@ SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST
Definition fftools_ffprobe.c:211
SECTION_ID_FRAME_SIDE_DATA_PIECE
@ SECTION_ID_FRAME_SIDE_DATA_PIECE
Definition fftools_ffprobe.c:216
SECTION_ID_PACKETS
@ SECTION_ID_PACKETS
Definition fftools_ffprobe.c:223
SECTION_ID_FRAME_TAGS
@ SECTION_ID_FRAME_TAGS
Definition fftools_ffprobe.c:208
SECTION_ID_LIBRARY_VERSIONS
@ SECTION_ID_LIBRARY_VERSIONS
Definition fftools_ffprobe.c:220
SECTION_ID_STREAM_SIDE_DATA_LIST
@ SECTION_ID_STREAM_SIDE_DATA_LIST
Definition fftools_ffprobe.c:245
SECTION_ID_PROGRAMS
@ SECTION_ID_PROGRAMS
Definition fftools_ffprobe.c:239
SECTION_ID_PROGRAM_STREAM_TAGS
@ SECTION_ID_PROGRAM_STREAM_TAGS
Definition fftools_ffprobe.c:233
SECTION_ID_FORMAT_TAGS
@ SECTION_ID_FORMAT_TAGS
Definition fftools_ffprobe.c:205
SECTION_ID_CHAPTERS
@ SECTION_ID_CHAPTERS
Definition fftools_ffprobe.c:202
SECTION_ID_FRAME_SIDE_DATA_TIMECODE
@ SECTION_ID_FRAME_SIDE_DATA_TIMECODE
Definition fftools_ffprobe.c:212
SECTION_ID_FRAME_LOGS
@ SECTION_ID_FRAME_LOGS
Definition fftools_ffprobe.c:218
SECTION_ID_PIXEL_FORMAT_COMPONENTS
@ SECTION_ID_PIXEL_FORMAT_COMPONENTS
Definition fftools_ffprobe.c:230
SECTION_ID_FORMAT
@ SECTION_ID_FORMAT
Definition fftools_ffprobe.c:204
SECTION_ID_PACKET_TAGS
@ SECTION_ID_PACKET_TAGS
Definition fftools_ffprobe.c:222
SECTION_ID_PIXEL_FORMAT_COMPONENT
@ SECTION_ID_PIXEL_FORMAT_COMPONENT
Definition fftools_ffprobe.c:229
SECTION_ID_SUBTITLE
@ SECTION_ID_SUBTITLE
Definition fftools_ffprobe.c:247
SECTION_ID_PIXEL_FORMAT
@ SECTION_ID_PIXEL_FORMAT
Definition fftools_ffprobe.c:227
SECTION_ID_FRAME_SIDE_DATA_LIST
@ SECTION_ID_FRAME_SIDE_DATA_LIST
Definition fftools_ffprobe.c:209
SECTION_ID_FRAME_SIDE_DATA_COMPONENT
@ SECTION_ID_FRAME_SIDE_DATA_COMPONENT
Definition fftools_ffprobe.c:214
SECTION_ID_STREAMS
@ SECTION_ID_STREAMS
Definition fftools_ffprobe.c:243
SECTION_ID_CHAPTER_TAGS
@ SECTION_ID_CHAPTER_TAGS
Definition fftools_ffprobe.c:201
SECTION_ID_ERROR
@ SECTION_ID_ERROR
Definition fftools_ffprobe.c:203
SECTION_ID_FRAME_LOG
@ SECTION_ID_FRAME_LOG
Definition fftools_ffprobe.c:217
SECTION_ID_FRAME
@ SECTION_ID_FRAME
Definition fftools_ffprobe.c:206
SECTION_ID_PACKET_SIDE_DATA
@ SECTION_ID_PACKET_SIDE_DATA
Definition fftools_ffprobe.c:226
SECTION_ID_STREAM_DISPOSITION
@ SECTION_ID_STREAM_DISPOSITION
Definition fftools_ffprobe.c:242
SECTION_ID_ROOT
@ SECTION_ID_ROOT
Definition fftools_ffprobe.c:240
SECTION_ID_CHAPTER
@ SECTION_ID_CHAPTER
Definition fftools_ffprobe.c:200
SECTION_ID_PROGRAM_STREAMS
@ SECTION_ID_PROGRAM_STREAMS
Definition fftools_ffprobe.c:235
SECTION_ID_PROGRAM
@ SECTION_ID_PROGRAM
Definition fftools_ffprobe.c:234
WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS
#define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS
Definition fftools_ffprobe.c:478
writer_get_name
static const char * writer_get_name(void *p)
Definition fftools_ffprobe.c:540
ini_print_str
static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
Definition fftools_ffprobe.c:1557
do_count_frames
__thread int do_count_frames
Definition fftools_ffprobe.c:123
ini_options
static const AVOption ini_options[]
Definition fftools_ffprobe.c:1489
do_show_program_version
__thread int do_show_program_version
Definition fftools_ffprobe.c:136
CHECK_END
#define CHECK_END
ini_print_int
static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
Definition fftools_ffprobe.c:1568
do_show_streams
__thread int do_show_streams
Definition fftools_ffprobe.c:133
bprint_bytes
static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
Definition fftools_ffprobe.c:601
SHOW_LIB_VERSION
#define SHOW_LIB_VERSION(libname, LIBNAME)
Definition fftools_ffprobe.c:3569
do_show_frame_tags
__thread int do_show_frame_tags
Definition fftools_ffprobe.c:145
use_byte_value_binary_prefix
__thread int use_byte_value_binary_prefix
Definition fftools_ffprobe.c:152
CHECK_COMPLIANCE
#define CHECK_COMPLIANCE(opt, opt_name)
print_ts
#define print_ts(k, v)
Definition fftools_ffprobe.c:1941
writer_print_data
static void writer_print_data(WriterContext *wctx, const char *name, const uint8_t *data, int size)
Definition fftools_ffprobe.c:932
ffprobe_options
__thread OptionDef * ffprobe_options
Definition fftools_ffprobe.c:304
json_init
static av_cold int json_init(WriterContext *wctx)
Definition fftools_ffprobe.c:1603
print_int
#define print_int(k, v)
Definition fftools_ffprobe.c:1935
writer_open
static int writer_open(WriterContext **wctx, const Writer *writer, const char *args, const struct section *sections, int nb_sections, const char *output)
Definition fftools_ffprobe.c:647
show_subtitle
static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream, AVFormatContext *fmt_ctx)
Definition fftools_ffprobe.c:2568
WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER
#define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER
Definition fftools_ffprobe.c:479
unit_second_str
static const char unit_second_str[]
Definition fftools_ffprobe.c:331
writer_printf_avio
static void writer_printf_avio(WriterContext *wctx, const char *fmt,...)
Definition fftools_ffprobe.c:619
read_packets
static int read_packets(WriterContext *w, InputFile *ifile)
Definition fftools_ffprobe.c:2963
SECTION_FLAG_IS_WRAPPER
#define SECTION_FLAG_IS_WRAPPER
the section only contains other sections, but has no data at its own level
Definition fftools_ffprobe.c:186
unit_byte_str
static const char unit_byte_str[]
Definition fftools_ffprobe.c:333
show_program
static int show_program(WriterContext *w, InputFile *ifile, AVProgram *program)
Definition fftools_ffprobe.c:3223
writer_put_str_printf
static void writer_put_str_printf(WriterContext *wctx, const char *str)
Definition fftools_ffprobe.c:633
print_primaries
static void print_primaries(WriterContext *w, enum AVColorPrimaries color_primaries)
Definition fftools_ffprobe.c:2432
ffprobe_show_library_versions
static void ffprobe_show_library_versions(WriterContext *w)
Definition fftools_ffprobe.c:3584
flat_writer
static const Writer flat_writer
Definition fftools_ffprobe.c:1468
writer_put_str
#define writer_put_str(wctx_, str_)
Definition fftools_ffprobe.c:1002
default_print_section_header
static void default_print_section_header(WriterContext *wctx)
Definition fftools_ffprobe.c:1077
read_interval_packets
static int read_interval_packets(WriterContext *w, InputFile *ifile, const ReadInterval *interval, int64_t *cur_ts)
Definition fftools_ffprobe.c:2851
SHOW_OPTIONAL_FIELDS_AUTO
#define SHOW_OPTIONAL_FIELDS_AUTO
Definition fftools_ffprobe.c:156
sections
static __thread struct section sections[]
Definition fftools_ffprobe.c:250
json_print_section_footer
static void json_print_section_footer(WriterContext *wctx)
Definition fftools_ffprobe.c:1674
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition fftools_ffprobe.c:504
do_show_stream_tags
__thread int do_show_stream_tags
Definition fftools_ffprobe.c:147
opt_format
static int opt_format(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3659
show_frame
static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, AVFormatContext *fmt_ctx)
Definition fftools_ffprobe.c:2591
opt_read_intervals
static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3942
SECTION_MAX_NB_CHILDREN
#define SECTION_MAX_NB_CHILDREN
Definition fftools_ffprobe.c:180
SECTION_FLAG_IS_ARRAY
#define SECTION_FLAG_IS_ARRAY
the section contains an array of elements of the same type
Definition fftools_ffprobe.c:187
do_show_data
__thread int do_show_data
Definition fftools_ffprobe.c:135
writer_print_data_hash
static void writer_print_data_hash(WriterContext *wctx, const char *name, const uint8_t *data, int size)
Definition fftools_ffprobe.c:960
default_options
static const AVOption default_options[]
Definition fftools_ffprobe.c:1057
validate_string
static int validate_string(WriterContext *wctx, char **dstp, const char *src)
Definition fftools_ffprobe.c:801
print_color_range
static void print_color_range(WriterContext *w, enum AVColorRange color_range)
Definition fftools_ffprobe.c:2412
pthread_mutex_lock
#define pthread_mutex_lock(a)
Definition fftools_ffprobe.c:102
print_dynamic_hdr_vivid
static void print_dynamic_hdr_vivid(WriterContext *w, const AVDynamicHDRVivid *metadata)
Definition fftools_ffprobe.c:2226
writer_close
static int writer_close(WriterContext **wctx)
Definition fftools_ffprobe.c:577
flat_print_int
static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
Definition fftools_ffprobe.c:1450
writer_print_integers
static void writer_print_integers(WriterContext *wctx, const char *name, uint8_t *data, int size, const char *format, int columns, int bytes, int offset_add)
Definition fftools_ffprobe.c:975
show_data_hash
__thread char * show_data_hash
Definition fftools_ffprobe.c:163
do_show_chapter_tags
__thread int do_show_chapter_tags
Definition fftools_ffprobe.c:143
compact_print_section_footer
static void compact_print_section_footer(WriterContext *wctx)
Definition fftools_ffprobe.c:1279
do_show_frames
__thread int do_show_frames
Definition fftools_ffprobe.c:130
xml_options
static const AVOption xml_options[]
Definition fftools_ffprobe.c:1763
print_ambient_viewing_environment
static void print_ambient_viewing_environment(WriterContext *w, const AVAmbientViewingEnvironment *env)
Definition fftools_ffprobe.c:2294
XML_INDENT
#define XML_INDENT()
Definition fftools_ffprobe.c:1794
log_buffer_size
__thread int log_buffer_size
Definition fftools_ffprobe.c:354
ffprobe_execute
int ffprobe_execute(int argc, char **argv)
Definition fftools_ffprobe.c:4096
parse_read_interval
static int parse_read_interval(const char *interval_spec, ReadInterval *interval)
Definition fftools_ffprobe.c:3812
writer_print_section_footer
static void writer_print_section_footer(WriterContext *wctx)
Definition fftools_ffprobe.c:773
csv_options
static const AVOption csv_options[]
Definition fftools_ffprobe.c:1329
compact_writer
static const Writer compact_writer
Definition fftools_ffprobe.c:1312
xml_init
static av_cold int xml_init(WriterContext *wctx)
Definition fftools_ffprobe.c:1773
stream_specifier
__thread char * stream_specifier
Definition fftools_ffprobe.c:162
flat_escape_value_str
static const char * flat_escape_value_str(AVBPrint *dst, const char *src)
Definition fftools_ffprobe.c:1406
unit_hertz_str
static const char unit_hertz_str[]
Definition fftools_ffprobe.c:332
print_color_space
static void print_color_space(WriterContext *w, enum AVColorSpace color_space)
Definition fftools_ffprobe.c:2422
show_streams
static int show_streams(WriterContext *w, InputFile *ifile)
Definition fftools_ffprobe.c:3206
print_section_header
#define print_section_header(s)
Definition fftools_ffprobe.c:1951
show_error
static void show_error(WriterContext *w, int err)
Definition fftools_ffprobe.c:3328
opt_pretty
static int opt_pretty(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3947
read_intervals
__thread ReadInterval * read_intervals
Definition fftools_ffprobe.c:173
print_str_validate
#define print_str_validate(k, v)
Definition fftools_ffprobe.c:1939
probe_file
static int probe_file(WriterContext *wctx, const char *filename, const char *print_filename)
Definition fftools_ffprobe.c:3465
input_filename
__thread const char * input_filename
Definition fftools_ffprobe.c:307
ffprobe_var_cleanup
void ffprobe_var_cleanup()
Definition fftools_ffprobe.c:4027
json_print_item_str
static void json_print_item_str(WriterContext *wctx, const char *key, const char *value)
Definition fftools_ffprobe.c:1696
SECTION_FLAG_HAS_VARIABLE_FIELDS
#define SECTION_FLAG_HAS_VARIABLE_FIELDS
Definition fftools_ffprobe.c:188
compact_print_section_header
static void compact_print_section_header(WriterContext *wctx)
Definition fftools_ffprobe.c:1247
print_chroma_location
static void print_chroma_location(WriterContext *w, enum AVChromaLocation chroma_location)
Definition fftools_ffprobe.c:2452
compact_options
static const AVOption compact_options[]
Definition fftools_ffprobe.c:1211
do_show_log
__thread int do_show_log
Definition fftools_ffprobe.c:141
opt_output_file
static void opt_output_file(void *optctx, const char *arg)
Definition fftools_ffprobe.c:3772
dec_val
double dec_val
Definition fftools_ffprobe.c:319
opt_show_optional_fields
static int opt_show_optional_fields(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3648
next_registered_writer_idx
__thread int next_registered_writer_idx
Definition fftools_ffprobe.c:1009
ini_print_section_header
static void ini_print_section_header(WriterContext *wctx)
Definition fftools_ffprobe.c:1524
json_print_int
static void json_print_int(WriterContext *wctx, const char *key, long long int value)
Definition fftools_ffprobe.c:1721
flat_print_section_header
static void flat_print_section_header(WriterContext *wctx)
Definition fftools_ffprobe.c:1424
selected_streams
__thread int * selected_streams
Definition fftools_ffprobe.c:339
unit_bit_per_second_str
static const char unit_bit_per_second_str[]
Definition fftools_ffprobe.c:334
StringValidation
StringValidation
Definition fftools_ffprobe.c:481
WRITER_STRING_VALIDATION_NB
@ WRITER_STRING_VALIDATION_NB
Definition fftools_ffprobe.c:485
WRITER_STRING_VALIDATION_REPLACE
@ WRITER_STRING_VALIDATION_REPLACE
Definition fftools_ffprobe.c:483
WRITER_STRING_VALIDATION_IGNORE
@ WRITER_STRING_VALIDATION_IGNORE
Definition fftools_ffprobe.c:484
WRITER_STRING_VALIDATION_FAIL
@ WRITER_STRING_VALIDATION_FAIL
Definition fftools_ffprobe.c:482
do_show_program_tags
__thread int do_show_program_tags
Definition fftools_ffprobe.c:146
do_count_packets
__thread int do_count_packets
Definition fftools_ffprobe.c:124
print_str
#define print_str(k, v)
Definition fftools_ffprobe.c:1937
do_read_frames
__thread int do_read_frames
Definition fftools_ffprobe.c:125
print_duration_ts
#define print_duration_ts(k, v)
Definition fftools_ffprobe.c:1943
flat_init
static av_cold int flat_init(WriterContext *wctx)
Definition fftools_ffprobe.c:1377
writer_w8_printf
static void writer_w8_printf(WriterContext *wctx, int b)
Definition fftools_ffprobe.c:628
writer_print_integer
static void writer_print_integer(WriterContext *wctx, const char *key, long long int val)
Definition fftools_ffprobe.c:790
xml_print_section_footer
static void xml_print_section_footer(WriterContext *wctx)
Definition fftools_ffprobe.c:1836
DEFINE_WRITER_CLASS
#define DEFINE_WRITER_CLASS(name)
Definition fftools_ffprobe.c:1034
hash
__thread struct AVHashContext * hash
Definition fftools_ffprobe.c:312
longjmp_value
__thread int longjmp_value
Definition fftools_cmdutils.c:113
ini_escape_str
static char * ini_escape_str(AVBPrint *dst, const char *src)
Definition fftools_ffprobe.c:1497
PRINT_STRING_OPT
#define PRINT_STRING_OPT
Definition fftools_ffprobe.c:856
csv_writer
static const Writer csv_writer
Definition fftools_ffprobe.c:1343
dec_str
const char * dec_str
Definition fftools_ffprobe.c:321
xml_print_str
static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
Definition fftools_ffprobe.c:1855
compact_print_int
static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
Definition fftools_ffprobe.c:1302
MAX_REGISTERED_WRITERS_NB
#define MAX_REGISTERED_WRITERS_NB
Definition fftools_ffprobe.c:1005
do_show_error
__thread int do_show_error
Definition fftools_ffprobe.c:128
print_str_opt
#define print_str_opt(k, v)
Definition fftools_ffprobe.c:1938
print_pkt_side_data
static void print_pkt_side_data(WriterContext *w, AVCodecParameters *par, const AVPacketSideData *side_data, int nb_side_data, SectionID id_data_list, SectionID id_data)
Definition fftools_ffprobe.c:2305
default_print_int
static void default_print_int(WriterContext *wctx, const char *key, long long int value)
Definition fftools_ffprobe.c:1124
si_prefixes
static const struct @4 si_prefixes[]
default_print_section_footer
static void default_print_section_footer(WriterContext *wctx)
Definition fftools_ffprobe.c:1102
do_bitexact
__thread int do_bitexact
Definition fftools_ffprobe.c:122
ffprobe_cleanup
static void ffprobe_cleanup(int ret)
Definition fftools_ffprobe.c:405
print_val
#define print_val(k, v, u)
Definition fftools_ffprobe.c:1944
do_show_format_tags
__thread int do_show_format_tags
Definition fftools_ffprobe.c:144
xml_print_section_header
static void xml_print_section_header(WriterContext *wctx)
Definition fftools_ffprobe.c:1796
show_private_data
__thread int show_private_data
Definition fftools_ffprobe.c:154
writer_printf
#define writer_printf(wctx_, fmt_,...)
Definition fftools_ffprobe.c:1003
show_format
static int show_format(WriterContext *w, InputFile *ifile)
Definition fftools_ffprobe.c:3297
writer_print_string
static int writer_print_string(WriterContext *wctx, const char *key, const char *val, int flags)
Definition fftools_ffprobe.c:859
log_buffer
__thread LogBuffer * log_buffer
Definition fftools_ffprobe.c:353
output_filename
__thread const char * output_filename
Definition fftools_ffprobe.c:310
registered_writers
__thread const Writer * registered_writers[MAX_REGISTERED_WRITERS_NB+1]
Definition fftools_ffprobe.c:1007
default_print_str
static void default_print_str(WriterContext *wctx, const char *key, const char *value)
Definition fftools_ffprobe.c:1115
DEFINE_OPT_SHOW_SECTION
#define DEFINE_OPT_SHOW_SECTION(section, target_section_id)
Definition fftools_ffprobe.c:3992
log_read_interval
static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
Definition fftools_ffprobe.c:2827
check_section_show_entries
static int check_section_show_entries(int section_id)
Definition fftools_ffprobe.c:4010
find_stream_info
__thread int find_stream_info
Definition fftools_ffprobe.c:176
flat_print_str
static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
Definition fftools_ffprobe.c:1455
writer_options
static const AVOption writer_options[]
Definition fftools_ffprobe.c:548
writer_put_str_avio
static void writer_put_str_avio(WriterContext *wctx, const char *str)
Definition fftools_ffprobe.c:614
SET_DO_SHOW
#define SET_DO_SHOW(id, varname)
Definition fftools_ffprobe.c:4022
print_q
#define print_q(k, v, s)
Definition fftools_ffprobe.c:1936
show_log
static int show_log(WriterContext *w, int section_ids, int section_id, int log_level)
Definition fftools_ffprobe.c:2479
ini_writer
static const Writer ini_writer
Definition fftools_ffprobe.c:1573
writer_register_all
static void writer_register_all(void)
Definition fftools_ffprobe.c:1905
print_color_trc
static void print_color_trc(WriterContext *w, enum AVColorTransferCharacteristic color_trc)
Definition fftools_ffprobe.c:2442
match_section
static int match_section(const char *section_name, int show_all_entries, AVDictionary *entries)
Definition fftools_ffprobe.c:3684
opt_show_entries
static int opt_show_entries(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3703
nb_streams_frames
__thread uint64_t * nb_streams_frames
Definition fftools_ffprobe.c:338
writer_print_rational
static void writer_print_rational(WriterContext *wctx, const char *key, AVRational q, char sep)
Definition fftools_ffprobe.c:897
process_frame
static av_always_inline int process_frame(WriterContext *w, InputFile *ifile, AVFrame *frame, const AVPacket *pkt, int *packet_new)
Definition fftools_ffprobe.c:2761
do_show_packet_tags
__thread int do_show_packet_tags
Definition fftools_ffprobe.c:148
show_value_unit
__thread int show_value_unit
Definition fftools_ffprobe.c:150
value_string
static char * value_string(char *buf, int buf_size, struct unit_value uv)
Definition fftools_ffprobe.c:421
close_input_file
static void close_input_file(InputFile *ifile)
Definition fftools_ffprobe.c:3451
csv_escape_str
static const char * csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition fftools_ffprobe.c:1172
print_section
static void print_section(SectionID id, int level)
Definition fftools_ffprobe.c:3956
pthread_mutex_unlock
#define pthread_mutex_unlock(a)
Definition fftools_ffprobe.c:106
c_escape_str
static const char * c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition fftools_ffprobe.c:1149
ffprobe_show_program_version
static void ffprobe_show_program_version(WriterContext *w)
Definition fftools_ffprobe.c:3553
json_escape_str
static const char * json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
Definition fftools_ffprobe.c:1613
print_dovi_metadata
static void print_dovi_metadata(WriterContext *w, const AVDOVIMetadata *dovi)
Definition fftools_ffprobe.c:1980
json_print_str
static void json_print_str(WriterContext *wctx, const char *key, const char *value)
Definition fftools_ffprobe.c:1708
show_tags
static int show_tags(WriterContext *w, AVDictionary *tags, int section_id)
Definition fftools_ffprobe.c:1962
opt_print_filename
static int opt_print_filename(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3791
json_writer
static const Writer json_writer
Definition fftools_ffprobe.c:1738
print_input_filename
__thread const char * print_input_filename
Definition fftools_ffprobe.c:308
compact_init
static av_cold int compact_init(WriterContext *wctx)
Definition fftools_ffprobe.c:1225
iformat
__thread const AVInputFormat * iformat
Definition fftools_ffprobe.c:309
opt_input_file_i
static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3766
show_stream
static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int in_program)
Definition fftools_ffprobe.c:2983
do_show_chapters
__thread int do_show_chapters
Definition fftools_ffprobe.c:127
print_duration_time
#define print_duration_time(k, v, tb)
Definition fftools_ffprobe.c:1942
nb_streams
__thread int nb_streams
Definition fftools_ffprobe.c:336
bin_str
const char * bin_str
Definition fftools_ffprobe.c:320
opt_input_file
static void opt_input_file(void *optctx, const char *arg)
Definition fftools_ffprobe.c:3753
bin_val
double bin_val
Definition fftools_ffprobe.c:318
do_show_programs
__thread int do_show_programs
Definition fftools_ffprobe.c:132
json_options
static const AVOption json_options[]
Definition fftools_ffprobe.c:1595
flat_escape_key_str
static const char * flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
Definition fftools_ffprobe.c:1391
main_ffprobe_return_code
__thread int main_ffprobe_return_code
Definition fftools_ffprobe.c:314
flat_options
static const AVOption flat_options[]
Definition fftools_ffprobe.c:1367
show_help_default_ffprobe
void show_help_default_ffprobe(const char *opt, const char *arg)
Definition fftools_ffprobe.c:3797
xml_print_int
static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
Definition fftools_ffprobe.c:1886
opt_output_file_o
static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3785
use_value_sexagesimal_format
__thread int use_value_sexagesimal_format
Definition fftools_ffprobe.c:153
do_show_pixel_format_flags
__thread int do_show_pixel_format_flags
Definition fftools_ffprobe.c:139
OFFSET
#define OFFSET(x)
Definition fftools_ffprobe.c:546
writer_printf_printf
static void writer_printf_printf(WriterContext *wctx, const char *fmt,...)
Definition fftools_ffprobe.c:638
ffprobe_show_pixel_formats
static void ffprobe_show_pixel_formats(WriterContext *w)
Definition fftools_ffprobe.c:3602
nb_streams_packets
__thread uint64_t * nb_streams_packets
Definition fftools_ffprobe.c:337
do_read_packets
__thread int do_read_packets
Definition fftools_ffprobe.c:126
use_value_prefix
__thread int use_value_prefix
Definition fftools_ffprobe.c:151
print_section_footer
#define print_section_footer(s)
Definition fftools_ffprobe.c:1952
writer_print_section_header
static void writer_print_section_header(WriterContext *wctx, int section_id)
Definition fftools_ffprobe.c:749
do_show_pixel_formats
__thread int do_show_pixel_formats
Definition fftools_ffprobe.c:138
show_programs
static int show_programs(WriterContext *w, InputFile *ifile)
Definition fftools_ffprobe.c:3254
upcase_string
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition fftools_ffprobe.c:1068
SHOW_OPTIONAL_FIELDS_ALWAYS
#define SHOW_OPTIONAL_FIELDS_ALWAYS
Definition fftools_ffprobe.c:158
print_format
__thread char * print_format
Definition fftools_ffprobe.c:161
open_input_file
static int open_input_file(InputFile *ifile, const char *filename, const char *print_filename)
Definition fftools_ffprobe.c:3336
writer_print_time
static void writer_print_time(WriterContext *wctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration)
Definition fftools_ffprobe.c:906
do_show_packets
__thread int do_show_packets
Definition fftools_ffprobe.c:131
mark_section_show_entries
static void mark_section_show_entries(SectionID section_id, int show_all_entries, AVDictionary *entries)
Definition fftools_ffprobe.c:3669
PRINT_STRING_VALIDATE
#define PRINT_STRING_VALIDATE
Definition fftools_ffprobe.c:857
json_print_section_header
static void json_print_section_header(WriterContext *wctx)
Definition fftools_ffprobe.c:1635
writer_register
static int writer_register(const Writer *writer)
Definition fftools_ffprobe.c:1011
print_time
#define print_time(k, v, tb)
Definition fftools_ffprobe.c:1940
do_show_pixel_format_components
__thread int do_show_pixel_format_components
Definition fftools_ffprobe.c:140
opt_sections
static int opt_sections(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3973
default_writer
static const Writer default_writer
Definition fftools_ffprobe.c:1133
do_show_format
__thread int do_show_format
Definition fftools_ffprobe.c:129
REALLOCZ_ARRAY_STREAM
#define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n)
Definition fftools_ffprobe.c:1954
show_optional_fields
__thread int show_optional_fields
Definition fftools_ffprobe.c:159
PRINT_DISPOSITION
#define PRINT_DISPOSITION(flagname, name)
writer_class
static const AVClass writer_class
Definition fftools_ffprobe.c:569
do_show_stream_disposition
__thread int do_show_stream_disposition
Definition fftools_ffprobe.c:134
clear_log
static void clear_log(int need_lock)
Definition fftools_ffprobe.c:2463
writer_print_ts
static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
Definition fftools_ffprobe.c:923
writer_get_by_name
static const Writer * writer_get_by_name(const char *name)
Definition fftools_ffprobe.c:1020
parse_read_intervals
static int parse_read_intervals(const char *intervals_spec)
Definition fftools_ffprobe.c:3894
PRINT_PIX_FMT_FLAG
#define PRINT_PIX_FMT_FLAG(flagname, name)
Definition fftools_ffprobe.c:3597
show_chapters
static int show_chapters(WriterContext *w, InputFile *ifile)
Definition fftools_ffprobe.c:3272
show_packet
static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int packet_idx)
Definition fftools_ffprobe.c:2514
xml_writer
static Writer xml_writer
Definition fftools_ffprobe.c:1893
opt_show_versions
static int opt_show_versions(void *optctx, const char *opt, const char *arg)
Definition fftools_ffprobe.c:3985
JSON_INDENT
#define JSON_INDENT()
Definition fftools_ffprobe.c:1633
compact_print_str
static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
Definition fftools_ffprobe.c:1289
writer_child_next
static void * writer_child_next(void *obj, void *prev)
Definition fftools_ffprobe.c:561
print_fmt
#define print_fmt(k, f,...)
Definition fftools_ffprobe.c:1917
none_escape_str
static const char * none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition fftools_ffprobe.c:1190
print_dynamic_hdr10_plus
static void print_dynamic_hdr10_plus(WriterContext *w, const AVDynamicHDRPlus *metadata)
Definition fftools_ffprobe.c:2127
SHOW_OPTIONAL_FIELDS_NEVER
#define SHOW_OPTIONAL_FIELDS_NEVER
Definition fftools_ffprobe.c:157
show_decoders
int show_decoders(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:794
opt_loglevel
int opt_loglevel(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:1263
opt_cpuflags
int opt_cpuflags(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:1076
show_help
int show_help(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:597
show_filters
int show_filters(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:818
show_sample_fmts
int show_sample_fmts(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:1057
show_muxers
int show_muxers(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:942
show_bsfs
int show_bsfs(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:806
show_dispositions
int show_dispositions(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:1066
show_layouts
int show_layouts(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:1024
show_encoders
int show_encoders(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:800
show_version
int show_version(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:273
opt_cpucount
int opt_cpucount(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:1088
show_license
int show_license(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:101
show_codecs
int show_codecs(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:697
show_buildconf
int show_buildconf(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:281
show_devices
int show_devices(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:952
show_formats
int show_formats(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:937
show_protocols
int show_protocols(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:957
opt_max_alloc
int opt_max_alloc(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:1249
opt_report
int opt_report(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:1244
show_colors
int show_colors(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:972
show_pix_fmts
int show_pix_fmts(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:986
show_demuxers
int show_demuxers(void *optctx, const char *opt, const char *arg)
Definition fftools_opt_common.c:947
fftools_opt_common.h
CompactContext
Definition fftools_ffprobe.c:1195
CompactContext::terminate_line
int terminate_line[SECTION_MAX_NB_LEVELS]
Definition fftools_ffprobe.c:1205
CompactContext::has_nested_elems
int has_nested_elems[SECTION_MAX_NB_LEVELS]
Definition fftools_ffprobe.c:1204
CompactContext::nested_section
int nested_section[SECTION_MAX_NB_LEVELS]
Definition fftools_ffprobe.c:1203
CompactContext::nokey
int nokey
Definition fftools_ffprobe.c:1199
CompactContext::escape_str
const char *(* escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition fftools_ffprobe.c:1202
CompactContext::item_sep
char item_sep
Definition fftools_ffprobe.c:1198
CompactContext::item_sep_str
char * item_sep_str
Definition fftools_ffprobe.c:1197
CompactContext::escape_mode_str
char * escape_mode_str
Definition fftools_ffprobe.c:1201
CompactContext::print_section
int print_section
Definition fftools_ffprobe.c:1200
DefaultContext
Definition fftools_ffprobe.c:1047
DefaultContext::noprint_wrappers
int noprint_wrappers
Definition fftools_ffprobe.c:1050
DefaultContext::nested_section
int nested_section[SECTION_MAX_NB_LEVELS]
Definition fftools_ffprobe.c:1051
DefaultContext::nokey
int nokey
Definition fftools_ffprobe.c:1049
FlatContext
Definition fftools_ffprobe.c:1357
FlatContext::sep_str
const char * sep_str
Definition fftools_ffprobe.c:1359
FlatContext::sep
char sep
Definition fftools_ffprobe.c:1360
FlatContext::hierarchical
int hierarchical
Definition fftools_ffprobe.c:1361
INIContext
Definition fftools_ffprobe.c:1481
INIContext::hierarchical
int hierarchical
Definition fftools_ffprobe.c:1483
InputFile
Definition fftools_ffmpeg.h:499
InputFile::streams
InputStream * streams
Definition fftools_ffprobe.c:118
InputFile::streams
InputStream ** streams
Definition fftools_ffmpeg.h:523
InputFile::fmt_ctx
AVFormatContext * fmt_ctx
Definition fftools_ffprobe.c:116
InputFile::nb_streams
int nb_streams
Definition fftools_ffmpeg.h:524
InputStream
Definition fftools_ffmpeg.h:384
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition fftools_ffmpeg.h:402
InputStream::st
AVStream * st
Definition fftools_ffmpeg.h:386
JSONContext
Definition fftools_ffprobe.c:1585
JSONContext::compact
int compact
Definition fftools_ffprobe.c:1588
JSONContext::item_sep
const char * item_sep
Definition fftools_ffprobe.c:1589
JSONContext::indent_level
int indent_level
Definition fftools_ffprobe.c:1587
JSONContext::item_start_end
const char * item_start_end
Definition fftools_ffprobe.c:1589
LogBuffer
Definition fftools_ffprobe.c:344
LogBuffer::context_name
char * context_name
Definition fftools_ffprobe.c:345
LogBuffer::parent_category
AVClassCategory parent_category
Definition fftools_ffprobe.c:350
LogBuffer::category
AVClassCategory category
Definition fftools_ffprobe.c:348
LogBuffer::log_message
char * log_message
Definition fftools_ffprobe.c:347
LogBuffer::parent_name
char * parent_name
Definition fftools_ffprobe.c:349
LogBuffer::log_level
int log_level
Definition fftools_ffprobe.c:346
OptionDef
Definition fftools_cmdutils.h:194
ReadInterval
Definition fftools_ffprobe.c:165
ReadInterval::end
int64_t end
start, end in second/AV_TIME_BASE units
Definition fftools_ffprobe.c:167
ReadInterval::duration_frames
int duration_frames
Definition fftools_ffprobe.c:170
ReadInterval::has_end
int has_end
Definition fftools_ffprobe.c:168
ReadInterval::start
int64_t start
Definition fftools_ffprobe.c:167
ReadInterval::has_start
int has_start
Definition fftools_ffprobe.c:168
ReadInterval::end_is_offset
int end_is_offset
Definition fftools_ffprobe.c:169
ReadInterval::id
int id
identifier
Definition fftools_ffprobe.c:166
ReadInterval::start_is_offset
int start_is_offset
Definition fftools_ffprobe.c:169
WriterContext
Definition fftools_ffprobe.c:506
WriterContext::nb_section_frame
unsigned int nb_section_frame
number of the frame section in case we are in "packets_and_frames" section
Definition fftools_ffprobe.c:532
WriterContext::nb_item
unsigned int nb_item[SECTION_MAX_NB_LEVELS]
Definition fftools_ffprobe.c:524
WriterContext::section
const struct section * section[SECTION_MAX_NB_LEVELS]
Definition fftools_ffprobe.c:527
WriterContext::writer_put_str
void(* writer_put_str)(WriterContext *wctx, const char *str)
Definition fftools_ffprobe.c:512
WriterContext::string_validation_replacement
char * string_validation_replacement
Definition fftools_ffprobe.c:536
WriterContext::name
char * name
name of this writer instance
Definition fftools_ffprobe.c:515
WriterContext::priv
void * priv
private data for use by the filter
Definition fftools_ffprobe.c:516
WriterContext::section_pbuf
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
Definition fftools_ffprobe.c:528
WriterContext::writer_w8
void(* writer_w8)(WriterContext *wctx, int b)
Definition fftools_ffprobe.c:511
WriterContext::nb_section_packet_frame
unsigned int nb_section_packet_frame
nb_section_packet or nb_section_frame according if is_packets_and_frames
Definition fftools_ffprobe.c:533
WriterContext::level
int level
current level, starting from 0
Definition fftools_ffprobe.c:521
WriterContext::nb_section_packet
unsigned int nb_section_packet
number of the packet section in case we are in "packets_and_frames" section
Definition fftools_ffprobe.c:531
WriterContext::avio
AVIOContext * avio
the I/O context used to write
Definition fftools_ffprobe.c:509
WriterContext::writer_printf
void(* writer_printf)(WriterContext *wctx, const char *fmt,...)
Definition fftools_ffprobe.c:513
WriterContext::nb_sections
int nb_sections
number of sections
Definition fftools_ffprobe.c:519
WriterContext::sections
const struct section * sections
array containing all sections
Definition fftools_ffprobe.c:518
WriterContext::string_validation_utf8_flags
unsigned int string_validation_utf8_flags
Definition fftools_ffprobe.c:537
WriterContext::string_validation
int string_validation
Definition fftools_ffprobe.c:535
WriterContext::writer
const Writer * writer
the Writer of which this is an instance
Definition fftools_ffprobe.c:508
Writer
Definition fftools_ffprobe.c:488
Writer::print_string
void(* print_string)(WriterContext *wctx, const char *, const char *)
Definition fftools_ffprobe.c:500
Writer::flags
int flags
a combination or WRITER_FLAG_*
Definition fftools_ffprobe.c:501
Writer::priv_size
int priv_size
private size for the writer context
Definition fftools_ffprobe.c:490
Writer::priv_class
const AVClass * priv_class
private class of the writer, if any
Definition fftools_ffprobe.c:489
Writer::print_integer
void(* print_integer)(WriterContext *wctx, const char *, long long int)
Definition fftools_ffprobe.c:498
Writer::print_rational
void(* print_rational)(WriterContext *wctx, AVRational *q, char *sep)
Definition fftools_ffprobe.c:499
Writer::name
const char * name
Definition fftools_ffprobe.c:491
Writer::init
int(* init)(WriterContext *wctx)
Definition fftools_ffprobe.c:493
Writer::print_section_header
void(* print_section_header)(WriterContext *wctx)
Definition fftools_ffprobe.c:496
Writer::print_section_footer
void(* print_section_footer)(WriterContext *wctx)
Definition fftools_ffprobe.c:497
Writer::uninit
void(* uninit)(WriterContext *wctx)
Definition fftools_ffprobe.c:494
XMLContext
Definition fftools_ffprobe.c:1752
XMLContext::xsd_strict
int xsd_strict
Definition fftools_ffprobe.c:1757
XMLContext::fully_qualified
int fully_qualified
Definition fftools_ffprobe.c:1756
XMLContext::indent_level
int indent_level
Definition fftools_ffprobe.c:1755
XMLContext::within_tag
int within_tag
Definition fftools_ffprobe.c:1754
section
Definition fftools_ffprobe.c:182
section::show_all_entries
int show_all_entries
Definition fftools_ffprobe.c:195
section::entries_to_show
AVDictionary * entries_to_show
Definition fftools_ffprobe.c:194
section::name
const char * name
Definition fftools_ffprobe.c:184
section::element_name
const char * element_name
name of the contained element, if provided
Definition fftools_ffprobe.c:192
section::id
int id
unique id identifying a section
Definition fftools_ffprobe.c:183
section::flags
int flags
Definition fftools_ffprobe.c:190
section::unique_name
const char * unique_name
unique section name, in case the name is ambiguous
Definition fftools_ffprobe.c:193
section::children_ids
int children_ids[SECTION_MAX_NB_CHILDREN+1]
list of children section IDS, terminated by -1
Definition fftools_ffprobe.c:191
unit_value
Definition fftools_ffprobe.c:416
unit_value::unit
const char * unit
Definition fftools_ffprobe.c:418
unit_value::d
double d
Definition fftools_ffprobe.c:417
unit_value::i
long long int i
Definition fftools_ffprobe.c:417
unit_value::val
union unit_value::@5 val