X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=fftools%2Fffprobe.c;h=7b28f6b3ce31126aff9639be89ee810ca7390483;hb=ef6a9e5e311f09fa8032974fa4d0c1e166a959bb;hp=544786ec728aec22c1f04eaeda95f47fbbe97c73;hpb=5c1aafff2d844b177b0b20db4a38d8460992558b;p=ffmpeg diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 544786ec728..7b28f6b3ce3 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -35,7 +35,9 @@ #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" #include "libavutil/pixdesc.h" #include "libavutil/spherical.h" @@ -165,6 +167,8 @@ typedef enum { SECTION_ID_FRAME_TAGS, SECTION_ID_FRAME_SIDE_DATA_LIST, SECTION_ID_FRAME_SIDE_DATA, + SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, + SECTION_ID_FRAME_SIDE_DATA_TIMECODE, SECTION_ID_FRAME_LOG, SECTION_ID_FRAME_LOGS, SECTION_ID_LIBRARY_VERSION, @@ -209,7 +213,9 @@ static struct section sections[] = { [SECTION_ID_FRAME] = { SECTION_ID_FRAME, "frame", 0, { SECTION_ID_FRAME_TAGS, SECTION_ID_FRAME_SIDE_DATA_LIST, SECTION_ID_FRAME_LOGS, -1 } }, [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" }, [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" }, - [SECTION_ID_FRAME_SIDE_DATA] = { SECTION_ID_FRAME_SIDE_DATA, "side_data", 0, { -1 } }, + [SECTION_ID_FRAME_SIDE_DATA] = { SECTION_ID_FRAME_SIDE_DATA, "side_data", 0, { SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST, -1 } }, + [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 } }, + [SECTION_ID_FRAME_SIDE_DATA_TIMECODE] = { SECTION_ID_FRAME_SIDE_DATA_TIMECODE, "timecode", 0, { -1 } }, [SECTION_ID_FRAME_LOGS] = { SECTION_ID_FRAME_LOGS, "logs", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_LOG, -1 } }, [SECTION_ID_FRAME_LOG] = { SECTION_ID_FRAME_LOG, "log", 0, { -1 }, }, [SECTION_ID_LIBRARY_VERSIONS] = { SECTION_ID_LIBRARY_VERSIONS, "library_versions", SECTION_FLAG_IS_ARRAY, { SECTION_ID_LIBRARY_VERSION, -1 } }, @@ -250,7 +256,8 @@ static const OptionDef *options; /* FFprobe context */ static const char *input_filename; -static AVInputFormat *iformat = NULL; +static const char *print_input_filename; +static const AVInputFormat *iformat = NULL; static struct AVHashContext *hash; @@ -1079,12 +1086,12 @@ typedef struct CompactContext { #define OFFSET(x) offsetof(CompactContext, x) static const AVOption compact_options[]= { - {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX }, - {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX }, + {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 }, + {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 }, {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 }, - {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX }, - {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX }, + {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 }, + {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 }, {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, {NULL}, @@ -1195,12 +1202,12 @@ static const Writer compact_writer = { #define OFFSET(x) offsetof(CompactContext, x) static const AVOption csv_options[] = { - {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX }, - {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX }, + {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 }, + {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 }, {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, - {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX }, - {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX }, + {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 }, + {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 }, {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, {NULL}, @@ -1233,8 +1240,8 @@ typedef struct FlatContext { #define OFFSET(x) offsetof(FlatContext, x) static const AVOption flat_options[]= { - {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX }, - {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX }, + {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 }, + {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 }, {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 }, {NULL}, @@ -1531,7 +1538,7 @@ static void json_print_section_header(WriterContext *wctx) if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) { if (!json->compact) JSON_INDENT(); - printf("\"type\": \"%s\"%s", section->name, json->item_sep); + printf("\"type\": \"%s\"", section->name); } } av_bprint_finalize(&buf, NULL); @@ -1575,8 +1582,10 @@ static inline void json_print_item_str(WriterContext *wctx, static void json_print_str(WriterContext *wctx, const char *key, const char *value) { JSONContext *json = wctx->priv; + const struct section *parent_section = wctx->level ? + wctx->section[wctx->level-1] : NULL; - if (wctx->nb_item[wctx->level]) + if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES)) printf("%s", json->item_sep); if (!json->compact) JSON_INDENT(); @@ -1586,9 +1595,11 @@ static void json_print_str(WriterContext *wctx, const char *key, const char *val static void json_print_int(WriterContext *wctx, const char *key, long long int value) { JSONContext *json = wctx->priv; + const struct section *parent_section = wctx->level ? + wctx->section[wctx->level-1] : NULL; AVBPrint buf; - if (wctx->nb_item[wctx->level]) + if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES)) printf("%s", json->item_sep); if (!json->compact) JSON_INDENT(); @@ -1649,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) @@ -1750,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); @@ -1850,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, @@ -1919,6 +2012,16 @@ static void print_pkt_side_data(WriterContext *w, AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data; print_int("max_content", metadata->MaxCLL); print_int("max_average", metadata->MaxFALL); + } else if (sd->type == AV_PKT_DATA_DOVI_CONF) { + AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord *)sd->data; + print_int("dv_version_major", dovi->dv_version_major); + print_int("dv_version_minor", dovi->dv_version_minor); + print_int("dv_profile", dovi->dv_profile); + print_int("dv_level", dovi->dv_level); + print_int("rpu_present_flag", dovi->rpu_present_flag); + print_int("el_present_flag", dovi->el_present_flag); + print_int("bl_present_flag", dovi->bl_present_flag); + print_int("dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id); } writer_print_section_footer(w); } @@ -2048,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"); @@ -2057,7 +2158,7 @@ static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int p pkt->flags & AV_PKT_FLAG_DISCARD ? 'D' : '_'); if (pkt->side_data_elems) { - int size; + size_t size; const uint8_t *side_metadata; side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size); @@ -2199,6 +2300,18 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, char tcbuf[AV_TIMECODE_STR_SIZE]; av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data)); print_str("timecode", tcbuf); + } else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) { + uint32_t *tc = (uint32_t*)sd->data; + int m = FFMIN(tc[0],3); + 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_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); + } + writer_print_section_footer(w); } else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) { AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data; @@ -2218,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); @@ -2330,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); @@ -2370,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; @@ -2403,28 +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_init_packet(&pkt); - pkt.data = NULL; - pkt.size = 0; + 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); @@ -2500,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)); @@ -2513,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) { @@ -2556,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; @@ -2603,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); @@ -2622,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); @@ -2646,20 +2750,25 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id } while (0) if (do_show_stream_disposition) { - writer_print_section_header(w, in_program ? SECTION_ID_PROGRAM_STREAM_DISPOSITION : SECTION_ID_STREAM_DISPOSITION); - PRINT_DISPOSITION(DEFAULT, "default"); - PRINT_DISPOSITION(DUB, "dub"); - PRINT_DISPOSITION(ORIGINAL, "original"); - PRINT_DISPOSITION(COMMENT, "comment"); - PRINT_DISPOSITION(LYRICS, "lyrics"); - PRINT_DISPOSITION(KARAOKE, "karaoke"); - PRINT_DISPOSITION(FORCED, "forced"); - PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired"); - PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired"); - PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects"); - PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic"); - PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails"); - writer_print_section_footer(w); + writer_print_section_header(w, in_program ? SECTION_ID_PROGRAM_STREAM_DISPOSITION : SECTION_ID_STREAM_DISPOSITION); + PRINT_DISPOSITION(DEFAULT, "default"); + PRINT_DISPOSITION(DUB, "dub"); + PRINT_DISPOSITION(ORIGINAL, "original"); + PRINT_DISPOSITION(COMMENT, "comment"); + PRINT_DISPOSITION(LYRICS, "lyrics"); + PRINT_DISPOSITION(KARAOKE, "karaoke"); + PRINT_DISPOSITION(FORCED, "forced"); + PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired"); + PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired"); + 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); } if (do_show_stream_tags) @@ -2818,11 +2927,12 @@ static void show_error(WriterContext *w, int err) writer_print_section_footer(w); } -static int open_input_file(InputFile *ifile, const char *filename) +static int open_input_file(InputFile *ifile, const char *filename, + const char *print_filename) { int err, i; AVFormatContext *fmt_ctx = NULL; - AVDictionaryEntry *t; + AVDictionaryEntry *t = NULL; int scan_all_pmts_set = 0; fmt_ctx = avformat_alloc_context(); @@ -2840,13 +2950,15 @@ static int open_input_file(InputFile *ifile, const char *filename) print_error(filename, err); return err; } + if (print_filename) { + av_freep(&fmt_ctx->url); + fmt_ctx->url = av_strdup(print_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); @@ -2876,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; @@ -2914,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", @@ -2953,7 +3060,8 @@ static void close_input_file(InputFile *ifile) avformat_close_input(&ifile->fmt_ctx); } -static int probe_file(WriterContext *wctx, const char *filename) +static int probe_file(WriterContext *wctx, const char *filename, + const char *print_filename) { InputFile ifile = { 0 }; int ret, i; @@ -2962,7 +3070,7 @@ static int probe_file(WriterContext *wctx, const char *filename) do_read_frames = do_show_frames || do_count_frames; do_read_packets = do_show_packets || do_count_packets; - ret = open_input_file(&ifile, filename); + ret = open_input_file(&ifile, filename, print_filename); if (ret < 0) goto end; @@ -3118,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); } @@ -3268,6 +3373,12 @@ static int opt_input_file_i(void *optctx, const char *opt, const char *arg) return 0; } +static int opt_print_filename(void *optctx, const char *opt, const char *arg) +{ + print_input_filename = arg; + return 0; +} + void show_help_default(const char *opt, const char *arg) { av_log_set_callback(log_callback_help); @@ -3457,7 +3568,7 @@ static int opt_sections(void *optctx, const char *opt, const char *arg) return 0; } -static int opt_show_versions(const char *opt, const char *arg) +static int opt_show_versions(void *optctx, const char *opt, const char *arg) { mark_section_show_entries(SECTION_ID_PROGRAM_VERSION, 1, NULL); mark_section_show_entries(SECTION_ID_LIBRARY_VERSION, 1, NULL); @@ -3465,7 +3576,7 @@ static int opt_show_versions(const char *opt, const char *arg) } #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \ - static int opt_show_##section(const char *opt, const char *arg) \ + static int opt_show_##section(void *optctx, const char *opt, const char *arg) \ { \ mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \ return 0; \ @@ -3493,39 +3604,40 @@ static const OptionDef real_options[] = { "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" }, { "pretty", 0, {.func_arg = opt_pretty}, "prettify the format of displayed values, make it more human readable" }, - { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format}, + { "print_format", OPT_STRING | HAS_ARG, { &print_format }, "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" }, - { "of", OPT_STRING | HAS_ARG, {(void*)&print_format}, "alias for -print_format", "format" }, - { "select_streams", OPT_STRING | HAS_ARG, {(void*)&stream_specifier}, "select the specified streams", "stream_specifier" }, + { "of", OPT_STRING | HAS_ARG, { &print_format }, "alias for -print_format", "format" }, + { "select_streams", OPT_STRING | HAS_ARG, { &stream_specifier }, "select the specified streams", "stream_specifier" }, { "sections", OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" }, - { "show_data", OPT_BOOL, {(void*)&do_show_data}, "show packets data" }, - { "show_data_hash", OPT_STRING | HAS_ARG, {(void*)&show_data_hash}, "show packets data hash" }, - { "show_error", 0, {(void*)&opt_show_error}, "show probing error" }, - { "show_format", 0, {(void*)&opt_show_format}, "show format/container info" }, - { "show_frames", 0, {(void*)&opt_show_frames}, "show frames info" }, + { "show_data", OPT_BOOL, { &do_show_data }, "show packets data" }, + { "show_data_hash", OPT_STRING | HAS_ARG, { &show_data_hash }, "show packets data hash" }, + { "show_error", 0, { .func_arg = &opt_show_error }, "show probing error" }, + { "show_format", 0, { .func_arg = &opt_show_format }, "show format/container info" }, + { "show_frames", 0, { .func_arg = &opt_show_frames }, "show frames info" }, { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry}, "show a particular entry from the format/container info", "entry" }, { "show_entries", HAS_ARG, {.func_arg = opt_show_entries}, "show a set of specified entries", "entry_list" }, #if HAVE_THREADS - { "show_log", OPT_INT|HAS_ARG, {(void*)&do_show_log}, "show log" }, + { "show_log", OPT_INT|HAS_ARG, { &do_show_log }, "show log" }, #endif - { "show_packets", 0, {(void*)&opt_show_packets}, "show packets info" }, - { "show_programs", 0, {(void*)&opt_show_programs}, "show programs info" }, - { "show_streams", 0, {(void*)&opt_show_streams}, "show streams info" }, - { "show_chapters", 0, {(void*)&opt_show_chapters}, "show chapters info" }, - { "count_frames", OPT_BOOL, {(void*)&do_count_frames}, "count the number of frames per stream" }, - { "count_packets", OPT_BOOL, {(void*)&do_count_packets}, "count the number of packets per stream" }, - { "show_program_version", 0, {(void*)&opt_show_program_version}, "show ffprobe version" }, - { "show_library_versions", 0, {(void*)&opt_show_library_versions}, "show library versions" }, - { "show_versions", 0, {(void*)&opt_show_versions}, "show program and library versions" }, - { "show_pixel_formats", 0, {(void*)&opt_show_pixel_formats}, "show pixel format descriptions" }, - { "show_private_data", OPT_BOOL, {(void*)&show_private_data}, "show private data" }, - { "private", OPT_BOOL, {(void*)&show_private_data}, "same as show_private_data" }, + { "show_packets", 0, { .func_arg = &opt_show_packets }, "show packets info" }, + { "show_programs", 0, { .func_arg = &opt_show_programs }, "show programs info" }, + { "show_streams", 0, { .func_arg = &opt_show_streams }, "show streams info" }, + { "show_chapters", 0, { .func_arg = &opt_show_chapters }, "show chapters info" }, + { "count_frames", OPT_BOOL, { &do_count_frames }, "count the number of frames per stream" }, + { "count_packets", OPT_BOOL, { &do_count_packets }, "count the number of packets per stream" }, + { "show_program_version", 0, { .func_arg = &opt_show_program_version }, "show ffprobe version" }, + { "show_library_versions", 0, { .func_arg = &opt_show_library_versions }, "show library versions" }, + { "show_versions", 0, { .func_arg = &opt_show_versions }, "show program and library versions" }, + { "show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats }, "show pixel format descriptions" }, + { "show_private_data", OPT_BOOL, { &show_private_data }, "show private data" }, + { "private", OPT_BOOL, { &show_private_data }, "same as show_private_data" }, { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" }, { "read_intervals", HAS_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" }, { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default}, "generic catch all option", "" }, { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"}, + { "print_filename", HAS_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"}, { "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT, { &find_stream_info }, "read and decode the streams to fill missing information with heuristics" }, { NULL, }, @@ -3674,7 +3786,7 @@ int main(int argc, char **argv) av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name); ret = AVERROR(EINVAL); } else if (input_filename) { - ret = probe_file(wctx, input_filename); + ret = probe_file(wctx, input_filename, print_input_filename); if (ret < 0 && do_show_error) show_error(wctx, ret); }