History

fftools/ffprobe: add analyze_frames option for CC and grain detection

Currently, ffprobe has two stream-level fields that do not work, closed_captions and film_grain). Their value is always 0 because ffprobe cannot access the internal codec properties when it is setting up its stream contexts. In this commit, add the new option -analyze_frames to ffprobe, allowing the user to read frames up to the interval they have defined and fill these fields based on what is exposed in AVPacketSideData. Additionally, in the same commit, don't write these fields to the output unless analyze_frames is enabled. Finally, fix the FATE test refs accordingly and update the docs.

Marth64 committed 1 year ago

Commit 90af8e01 parent 8291aed27 files · +58 −51Browse files

Showing the changes to fftools (1 of 27 files). Show all

Unified · Split

fftools/ffprobe.c+27−3
@@ -104,6 +104,7 @@ typedef struct InputFile { · 103 unmodified lines
104const char program_name[] = "ffprobe";104const char program_name[] = "ffprobe";
105const int program_birth_year = 2007;105const int program_birth_year = 2007;
106 106
107static int do_analyze_frames = 0;
107static int do_bitexact = 0;108static int do_bitexact = 0;
108static int do_count_frames = 0;109static int do_count_frames = 0;
109static int do_count_packets = 0;110static int do_count_packets = 0;
@@ -385,6 +386,8 @@ static int nb_streams; · 275 unmodified lines
385static uint64_t *nb_streams_packets;386static uint64_t *nb_streams_packets;
386static uint64_t *nb_streams_frames;387static uint64_t *nb_streams_frames;
387static int *selected_streams;388static int *selected_streams;
389static int *streams_with_closed_captions;
390static int *streams_with_film_grain;
388 391
389#if HAVE_THREADS392#if HAVE_THREADS
390pthread_mutex_t log_mutex;393pthread_mutex_t log_mutex;
@@ -3072,6 +3075,16 @@ static av_always_inline int process_frame(WriterContext *w, · 2681 unmodified lines
3072 show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);3075 show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
3073 else3076 else
3074 show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);3077 show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);
3078
3079 if (!is_sub && do_analyze_frames) {
3080 for (int i = 0; i < frame->nb_side_data; i++) {
3081 if (frame->side_data[i]->type == AV_FRAME_DATA_A53_CC)
3082 streams_with_closed_captions[pkt->stream_index] = 1;
3083 else if (frame->side_data[i]->type == AV_FRAME_DATA_FILM_GRAIN_PARAMS)
3084 streams_with_film_grain[pkt->stream_index] = 1;
3085 }
3086 }
3087
3075 if (is_sub)3088 if (is_sub)
3076 avsubtitle_free(&sub);3089 avsubtitle_free(&sub);
3077 }3090 }
@@ -3154,6 +3167,8 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile, · 76 unmodified lines
3154 REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams);3167 REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams);
3155 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);3168 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);
3156 REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams);3169 REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams);
3170 REALLOCZ_ARRAY_STREAM(streams_with_closed_captions, nb_streams, fmt_ctx->nb_streams);
3171 REALLOCZ_ARRAY_STREAM(streams_with_film_grain, nb_streams, fmt_ctx->nb_streams);
3157 nb_streams = fmt_ctx->nb_streams;3172 nb_streams = fmt_ctx->nb_streams;
3158 }3173 }
3159 if (selected_streams[pkt->stream_index]) {3174 if (selected_streams[pkt->stream_index]) {
@@ -3337,8 +3352,11 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id · 177 unmodified lines
3337 if (dec_ctx) {3352 if (dec_ctx) {
3338 print_int("coded_width", dec_ctx->coded_width);3353 print_int("coded_width", dec_ctx->coded_width);
3339 print_int("coded_height", dec_ctx->coded_height);3354 print_int("coded_height", dec_ctx->coded_height);
3340 print_int("closed_captions", !!(dec_ctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS));3355
3341 print_int("film_grain", !!(dec_ctx->properties & FF_CODEC_PROPERTY_FILM_GRAIN));3356 if (do_analyze_frames) {
3357 print_int("closed_captions", streams_with_closed_captions[stream->index]);
3358 print_int("film_grain", streams_with_film_grain[stream->index]);
3359 }
3342 }3360 }
3343 print_int("has_b_frames", par->video_delay);3361 print_int("has_b_frames", par->video_delay);
3344 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);3362 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
@@ -4005,7 +4023,8 @@ static int probe_file(WriterContext *wctx, const char *filename, · 660 unmodified lines
4005 int ret, i;4023 int ret, i;
4006 int section_id;4024 int section_id;
4007 4025
4008 do_read_frames = do_show_frames || do_count_frames;4026 do_analyze_frames = do_analyze_frames && do_show_streams;
4027 do_read_frames = do_show_frames || do_count_frames || do_analyze_frames;
4009 do_read_packets = do_show_packets || do_count_packets;4028 do_read_packets = do_show_packets || do_count_packets;
4010 4029
4011 ret = open_input_file(&ifile, filename, print_filename);4030 ret = open_input_file(&ifile, filename, print_filename);
@@ -4018,6 +4037,8 @@ static int probe_file(WriterContext *wctx, const char *filename, · 6 unmodified lines
4018 REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);4037 REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);
4019 REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);4038 REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);
4020 REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams);4039 REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams);
4040 REALLOCZ_ARRAY_STREAM(streams_with_closed_captions,0,ifile.fmt_ctx->nb_streams);
4041 REALLOCZ_ARRAY_STREAM(streams_with_film_grain,0,ifile.fmt_ctx->nb_streams);
4021 4042
4022 for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {4043 for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
4023 if (stream_specifier) {4044 if (stream_specifier) {
@@ -4080,6 +4101,8 @@ end: · 56 unmodified lines
4080 av_freep(&nb_streams_frames);4101 av_freep(&nb_streams_frames);
4081 av_freep(&nb_streams_packets);4102 av_freep(&nb_streams_packets);
4082 av_freep(&selected_streams);4103 av_freep(&selected_streams);
4104 av_freep(&streams_with_closed_captions);
4105 av_freep(&streams_with_film_grain);
4083 4106
4084 return ret;4107 return ret;
4085}4108}
@@ -4602,6 +4625,7 @@ static const OptionDef real_options[] = { · 516 unmodified lines
4602 { "show_optional_fields", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" },4625 { "show_optional_fields", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" },
4603 { "show_private_data", OPT_TYPE_BOOL, 0, { &show_private_data }, "show private data" },4626 { "show_private_data", OPT_TYPE_BOOL, 0, { &show_private_data }, "show private data" },
4604 { "private", OPT_TYPE_BOOL, 0, { &show_private_data }, "same as show_private_data" },4627 { "private", OPT_TYPE_BOOL, 0, { &show_private_data }, "same as show_private_data" },
4628 { "analyze_frames", OPT_TYPE_BOOL, 0, { &do_analyze_frames }, "analyze frames to provide additional stream-level information" },
4605 { "bitexact", OPT_TYPE_BOOL, 0, {&do_bitexact}, "force bitexact output" },4629 { "bitexact", OPT_TYPE_BOOL, 0, {&do_bitexact}, "force bitexact output" },
4606 { "read_intervals", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },4630 { "read_intervals", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
4607 { "i", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},4631 { "i", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t