X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=fftools%2Fffprobe.c;h=13ed16431dd81c2a38f2051020ed3b37ee300f38;hb=e8876bdcf3b4a8e5320884ffb9d39ce30e23f0e6;hp=840fcb71e24e748f8c4bbc7e4a14cb24196d2834;hpb=e689a759c6b634ff26d53e870dcfe725cfce86a5;p=ffmpeg diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 840fcb71e24..13ed16431dd 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -35,6 +35,7 @@ #include "libavutil/bprint.h" #include "libavutil/display.h" #include "libavutil/hash.h" +#include "libavutil/hdr_dynamic_metadata.h" #include "libavutil/mastering_display_metadata.h" #include "libavutil/dovi_meta.h" #include "libavutil/opt.h" @@ -256,7 +257,7 @@ static const OptionDef *options; /* FFprobe context */ static const char *input_filename; static const char *print_input_filename; -static AVInputFormat *iformat = NULL; +static const AVInputFormat *iformat = NULL; static struct AVHashContext *hash; @@ -1659,36 +1660,11 @@ static av_cold int xml_init(WriterContext *wctx) CHECK_COMPLIANCE(show_private_data, "private"); CHECK_COMPLIANCE(show_value_unit, "unit"); CHECK_COMPLIANCE(use_value_prefix, "prefix"); - - if (do_show_frames && do_show_packets) { - av_log(wctx, AV_LOG_ERROR, - "Interleaved frames and packets are not allowed in XSD. " - "Select only one between the -show_frames and the -show_packets options.\n"); - return AVERROR(EINVAL); - } } return 0; } -static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx) -{ - const char *p; - - for (p = src; *p; p++) { - switch (*p) { - case '&' : av_bprintf(dst, "%s", "&"); break; - case '<' : av_bprintf(dst, "%s", "<"); break; - case '>' : av_bprintf(dst, "%s", ">"); break; - case '"' : av_bprintf(dst, "%s", """); break; - case '\'': av_bprintf(dst, "%s", "'"); break; - default: av_bprint_chars(dst, *p, 1); - } - } - - return dst->str; -} - #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ') static void xml_print_section_header(WriterContext *wctx) @@ -1760,14 +1736,22 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) { XML_INDENT(); + av_bprint_escape(&buf, key, NULL, + AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); printf("<%s key=\"%s\"", - section->element_name, xml_escape_str(&buf, key, wctx)); + section->element_name, buf.str); av_bprint_clear(&buf); - printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx)); + + av_bprint_escape(&buf, value, NULL, + AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); + printf(" value=\"%s\"/>\n", buf.str); } else { if (wctx->nb_item[wctx->level]) printf(" "); - printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx)); + + av_bprint_escape(&buf, value, NULL, + AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES); + printf("%s=\"%s\"", key, buf.str); } av_bprint_finalize(&buf, NULL); @@ -1860,6 +1844,105 @@ static inline int show_tags(WriterContext *w, AVDictionary *tags, int section_id return ret; } +static void print_dynamic_hdr10_plus(WriterContext *w, const AVDynamicHDRPlus *metadata) +{ + if (!metadata) + return; + print_int("application version", metadata->application_version); + print_int("num_windows", metadata->num_windows); + for (int n = 1; n < metadata->num_windows; n++) { + const AVHDRPlusColorTransformParams *params = &metadata->params[n]; + print_q("window_upper_left_corner_x", + params->window_upper_left_corner_x,'/'); + print_q("window_upper_left_corner_y", + params->window_upper_left_corner_y,'/'); + print_q("window_lower_right_corner_x", + params->window_lower_right_corner_x,'/'); + print_q("window_lower_right_corner_y", + params->window_lower_right_corner_y,'/'); + print_q("window_upper_left_corner_x", + params->window_upper_left_corner_x,'/'); + print_q("window_upper_left_corner_y", + params->window_upper_left_corner_y,'/'); + print_int("center_of_ellipse_x", + params->center_of_ellipse_x ) ; + print_int("center_of_ellipse_y", + params->center_of_ellipse_y ); + print_int("rotation_angle", + params->rotation_angle); + print_int("semimajor_axis_internal_ellipse", + params->semimajor_axis_internal_ellipse); + print_int("semimajor_axis_external_ellipse", + params->semimajor_axis_external_ellipse); + print_int("semiminor_axis_external_ellipse", + params->semiminor_axis_external_ellipse); + print_int("overlap_process_option", + params->overlap_process_option); + } + print_q("targeted_system_display_maximum_luminance", + metadata->targeted_system_display_maximum_luminance,'/'); + if (metadata->targeted_system_display_actual_peak_luminance_flag) { + print_int("num_rows_targeted_system_display_actual_peak_luminance", + metadata->num_rows_targeted_system_display_actual_peak_luminance); + print_int("num_cols_targeted_system_display_actual_peak_luminance", + metadata->num_cols_targeted_system_display_actual_peak_luminance); + for (int i = 0; i < metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) { + for (int j = 0; j < metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) { + print_q("targeted_system_display_actual_peak_luminance", + metadata->targeted_system_display_actual_peak_luminance[i][j],'/'); + } + } + } + for (int n = 0; n < metadata->num_windows; n++) { + const AVHDRPlusColorTransformParams *params = &metadata->params[n]; + for (int i = 0; i < 3; i++) { + print_q("maxscl",params->maxscl[i],'/'); + } + print_q("average_maxrgb", + params->average_maxrgb,'/'); + print_int("num_distribution_maxrgb_percentiles", + params->num_distribution_maxrgb_percentiles); + for (int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) { + print_int("distribution_maxrgb_percentage", + params->distribution_maxrgb[i].percentage); + print_q("distribution_maxrgb_percentile", + params->distribution_maxrgb[i].percentile,'/'); + } + print_q("fraction_bright_pixels", + params->fraction_bright_pixels,'/'); + } + if (metadata->mastering_display_actual_peak_luminance_flag) { + print_int("num_rows_mastering_display_actual_peak_luminance", + metadata->num_rows_mastering_display_actual_peak_luminance); + print_int("num_cols_mastering_display_actual_peak_luminance", + metadata->num_cols_mastering_display_actual_peak_luminance); + for (int i = 0; i < metadata->num_rows_mastering_display_actual_peak_luminance; i++) { + for (int j = 0; j < metadata->num_cols_mastering_display_actual_peak_luminance; j++) { + print_q("mastering_display_actual_peak_luminance", + metadata->mastering_display_actual_peak_luminance[i][j],'/'); + } + } + } + + for (int n = 0; n < metadata->num_windows; n++) { + const AVHDRPlusColorTransformParams *params = &metadata->params[n]; + if (params->tone_mapping_flag) { + print_q("knee_point_x", params->knee_point_x,'/'); + print_q("knee_point_y", params->knee_point_y,'/'); + print_int("num_bezier_curve_anchors", + params->num_bezier_curve_anchors ); + for (int i = 0; i < params->num_bezier_curve_anchors; i++) { + print_q("bezier_curve_anchors", + params->bezier_curve_anchors[i],'/'); + } + } + if (params->color_saturation_mapping_flag) { + print_q("color_saturation_weight", + params->color_saturation_weight,'/'); + } + } +} + static void print_pkt_side_data(WriterContext *w, AVCodecParameters *par, const AVPacketSideData *side_data, @@ -2068,8 +2151,6 @@ static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int p print_time("dts_time", pkt->dts, &st->time_base); print_duration_ts("duration", pkt->duration); print_duration_time("duration_time", pkt->duration, &st->time_base); - print_duration_ts("convergence_duration", pkt->convergence_duration); - print_duration_time("convergence_duration_time", pkt->convergence_duration, &st->time_base); print_val("size", pkt->size, unit_byte_str); if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos); else print_str_opt("pos", "N/A"); @@ -2225,7 +2306,7 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST); for (int j = 1; j <= m ; j++) { char tcbuf[AV_TIMECODE_STR_SIZE]; - av_timecode_make_smpte_tc_string(tcbuf, tc[j], 0); + av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0); writer_print_section_header(w, SECTION_ID_FRAME_SIDE_DATA_TIMECODE); print_str("value", tcbuf); writer_print_section_footer(w); @@ -2250,6 +2331,9 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, print_q("min_luminance", metadata->min_luminance, '/'); print_q("max_luminance", metadata->max_luminance, '/'); } + } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) { + AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data; + print_dynamic_hdr10_plus(w, metadata); } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) { AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data; print_int("max_content", metadata->MaxCLL); @@ -2362,14 +2446,12 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile, const ReadInterval *interval, int64_t *cur_ts) { AVFormatContext *fmt_ctx = ifile->fmt_ctx; - AVPacket pkt; + AVPacket *pkt = NULL; AVFrame *frame = NULL; int ret = 0, i = 0, frame_count = 0; int64_t start = -INT64_MAX, end = interval->end; int has_start = 0, has_end = interval->has_end && !interval->end_is_offset; - av_init_packet(&pkt); - av_log(NULL, AV_LOG_VERBOSE, "Processing read interval "); log_read_interval(interval, NULL, AV_LOG_VERBOSE); @@ -2402,18 +2484,23 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile, ret = AVERROR(ENOMEM); goto end; } - while (!av_read_frame(fmt_ctx, &pkt)) { + pkt = av_packet_alloc(); + if (!pkt) { + ret = AVERROR(ENOMEM); + goto end; + } + while (!av_read_frame(fmt_ctx, pkt)) { if (fmt_ctx->nb_streams > nb_streams) { REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams); REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams); REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams); nb_streams = fmt_ctx->nb_streams; } - if (selected_streams[pkt.stream_index]) { - AVRational tb = ifile->streams[pkt.stream_index].st->time_base; + if (selected_streams[pkt->stream_index]) { + AVRational tb = ifile->streams[pkt->stream_index].st->time_base; - if (pkt.pts != AV_NOPTS_VALUE) - *cur_ts = av_rescale_q(pkt.pts, tb, AV_TIME_BASE_Q); + if (pkt->pts != AV_NOPTS_VALUE) + *cur_ts = av_rescale_q(pkt->pts, tb, AV_TIME_BASE_Q); if (!has_start && *cur_ts != AV_NOPTS_VALUE) { start = *cur_ts; @@ -2435,26 +2522,27 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile, frame_count++; if (do_read_packets) { if (do_show_packets) - show_packet(w, ifile, &pkt, i++); - nb_streams_packets[pkt.stream_index]++; + show_packet(w, ifile, pkt, i++); + nb_streams_packets[pkt->stream_index]++; } if (do_read_frames) { int packet_new = 1; - while (process_frame(w, ifile, frame, &pkt, &packet_new) > 0); + while (process_frame(w, ifile, frame, pkt, &packet_new) > 0); } } - av_packet_unref(&pkt); + av_packet_unref(pkt); } - av_packet_unref(&pkt); + av_packet_unref(pkt); //Flush remaining frames that are cached in the decoder for (i = 0; i < fmt_ctx->nb_streams; i++) { - pkt.stream_index = i; + pkt->stream_index = i; if (do_read_frames) - while (process_frame(w, ifile, frame, &pkt, &(int){1}) > 0); + while (process_frame(w, ifile, frame, pkt, &(int){1}) > 0); } end: av_frame_free(&frame); + av_packet_free(&pkt); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval "); log_read_interval(interval, NULL, AV_LOG_ERROR); @@ -2530,10 +2618,6 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id s = av_get_media_type_string(par->codec_type); if (s) print_str ("codec_type", s); else print_str_opt("codec_type", "unknown"); -#if FF_API_LAVF_AVCTX - if (dec_ctx) - print_q("codec_time_base", dec_ctx->time_base, '/'); -#endif /* print AVI/FourCC tag */ print_str("codec_tag_string", av_fourcc2str(par->codec_tag)); @@ -2543,12 +2627,11 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id case AVMEDIA_TYPE_VIDEO: print_int("width", par->width); print_int("height", par->height); -#if FF_API_LAVF_AVCTX if (dec_ctx) { print_int("coded_width", dec_ctx->coded_width); print_int("coded_height", dec_ctx->coded_height); + print_int("closed_captions", !!(dec_ctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS)); } -#endif print_int("has_b_frames", par->video_delay); sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL); if (sar.num) { @@ -2586,15 +2669,6 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id else print_str_opt("field_order", "unknown"); -#if FF_API_PRIVATE_OPT - if (dec_ctx && dec_ctx->timecode_frame_start >= 0) { - char tcbuf[AV_TIMECODE_STR_SIZE]; - av_timecode_make_mpeg_tc_string(tcbuf, dec_ctx->timecode_frame_start); - print_str("timecode", tcbuf); - } else { - print_str_opt("timecode", "N/A"); - } -#endif if (dec_ctx) print_int("refs", dec_ctx->refs); break; @@ -2633,7 +2707,7 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id const AVOption *opt = NULL; while (opt = av_opt_next(dec_ctx->priv_data,opt)) { uint8_t *str; - if (opt->flags) continue; + if (!(opt->flags & AV_OPT_FLAG_EXPORT)) continue; if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) { print_str(opt->name, str); av_free(str); @@ -2652,10 +2726,10 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id print_time("duration", stream->duration, &stream->time_base); if (par->bit_rate > 0) print_val ("bit_rate", par->bit_rate, unit_bit_per_second_str); else print_str_opt("bit_rate", "N/A"); -#if FF_API_LAVF_AVCTX - if (stream->codec->rc_max_rate > 0) print_val ("max_bit_rate", stream->codec->rc_max_rate, unit_bit_per_second_str); - else print_str_opt("max_bit_rate", "N/A"); -#endif + if (dec_ctx && dec_ctx->rc_max_rate > 0) + print_val ("max_bit_rate", dec_ctx->rc_max_rate, unit_bit_per_second_str); + else + print_str_opt("max_bit_rate", "N/A"); if (dec_ctx && dec_ctx->bits_per_raw_sample > 0) print_fmt("bits_per_raw_sample", "%d", dec_ctx->bits_per_raw_sample); else print_str_opt("bits_per_raw_sample", "N/A"); if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames); @@ -2689,6 +2763,11 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects"); PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic"); PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails"); + PRINT_DISPOSITION(CAPTIONS, "captions"); + PRINT_DISPOSITION(DESCRIPTIONS, "descriptions"); + PRINT_DISPOSITION(METADATA, "metadata"); + PRINT_DISPOSITION(DEPENDENT, "dependent"); + PRINT_DISPOSITION(STILL_IMAGE, "still_image"); writer_print_section_footer(w); } @@ -2853,7 +2932,7 @@ static int open_input_file(InputFile *ifile, const char *filename, { int err, i; AVFormatContext *fmt_ctx = NULL; - AVDictionaryEntry *t; + AVDictionaryEntry *t = NULL; int scan_all_pmts_set = 0; fmt_ctx = avformat_alloc_context(); @@ -2878,10 +2957,8 @@ static int open_input_file(InputFile *ifile, const char *filename, ifile->fmt_ctx = fmt_ctx; if (scan_all_pmts_set) av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE); - if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) { - av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key); - return AVERROR_OPTION_NOT_FOUND; - } + while ((t = av_dict_get(format_opts, "", t, AV_DICT_IGNORE_SUFFIX))) + av_log(NULL, AV_LOG_WARNING, "Option %s skipped - not known to demuxer.\n", t->key); if (find_stream_info) { AVDictionary **opts = setup_find_stream_info_opts(fmt_ctx, codec_opts); @@ -2911,7 +2988,7 @@ static int open_input_file(InputFile *ifile, const char *filename, for (i = 0; i < fmt_ctx->nb_streams; i++) { InputStream *ist = &ifile->streams[i]; AVStream *stream = fmt_ctx->streams[i]; - AVCodec *codec; + const AVCodec *codec; ist->st = stream; @@ -2949,11 +3026,6 @@ static int open_input_file(InputFile *ifile, const char *filename, } ist->dec_ctx->pkt_timebase = stream->time_base; - ist->dec_ctx->framerate = stream->avg_frame_rate; -#if FF_API_LAVF_AVCTX - ist->dec_ctx->coded_width = stream->codec->coded_width; - ist->dec_ctx->coded_height = stream->codec->coded_height; -#endif if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) { av_log(NULL, AV_LOG_WARNING, "Could not open codec for input stream %d\n", @@ -3154,9 +3226,6 @@ static void ffprobe_show_pixel_formats(WriterContext *w) PRINT_PIX_FMT_FLAG(HWACCEL, "hwaccel"); PRINT_PIX_FMT_FLAG(PLANAR, "planar"); PRINT_PIX_FMT_FLAG(RGB, "rgb"); -#if FF_API_PSEUDOPAL - PRINT_PIX_FMT_FLAG(PSEUDOPAL, "pseudopal"); -#endif PRINT_PIX_FMT_FLAG(ALPHA, "alpha"); writer_print_section_footer(w); }