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
104104 const char program_name[] = "ffprobe";
105105 const int program_birth_year = 2007;
106106
107+static int do_analyze_frames = 0;
107108 static int do_bitexact = 0;
108109 static int do_count_frames = 0;
109110 static int do_count_packets = 0;
@@ -385,6 +386,8 @@ static int nb_streams; · 275 unmodified lines
385386 static uint64_t *nb_streams_packets;
386387 static uint64_t *nb_streams_frames;
387388 static int *selected_streams;
389+static int *streams_with_closed_captions;
390+static int *streams_with_film_grain;
388391
389392 #if HAVE_THREADS
390393 pthread_mutex_t log_mutex;
@@ -3072,6 +3075,16 @@ static av_always_inline int process_frame(WriterContext *w, · 2681 unmodified lines
30723075 show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
30733076 else
30743077 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+
30753088 if (is_sub)
30763089 avsubtitle_free(&sub);
30773090 }
@@ -3154,6 +3167,8 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile, · 76 unmodified lines
31543167 REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams);
31553168 REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);
31563169 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);
31573172 nb_streams = fmt_ctx->nb_streams;
31583173 }
31593174 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
33373352 if (dec_ctx) {
33383353 print_int("coded_width", dec_ctx->coded_width);
33393354 print_int("coded_height", dec_ctx->coded_height);
3340− print_int("closed_captions", !!(dec_ctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS));
3341− print_int("film_grain", !!(dec_ctx->properties & FF_CODEC_PROPERTY_FILM_GRAIN));
3355+
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+ }
33423360 }
33433361 print_int("has_b_frames", par->video_delay);
33443362 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
40054023 int ret, i;
40064024 int section_id;
40074025
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;
40094028 do_read_packets = do_show_packets || do_count_packets;
40104029
40114030 ret = open_input_file(&ifile, filename, print_filename);
@@ -4018,6 +4037,8 @@ static int probe_file(WriterContext *wctx, const char *filename, · 6 unmodified lines
40184037 REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);
40194038 REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);
40204039 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);
40214042
40224043 for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
40234044 if (stream_specifier) {
@@ -4080,6 +4101,8 @@ end: · 56 unmodified lines
40804101 av_freep(&nb_streams_frames);
40814102 av_freep(&nb_streams_packets);
40824103 av_freep(&selected_streams);
4104+ av_freep(&streams_with_closed_captions);
4105+ av_freep(&streams_with_film_grain);
40834106
40844107 return ret;
40854108 }
@@ -4602,6 +4625,7 @@ static const OptionDef real_options[] = { · 516 unmodified lines
46024625 { "show_optional_fields", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" },
46034626 { "show_private_data", OPT_TYPE_BOOL, 0, { &show_private_data }, "show private data" },
46044627 { "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" },
46054629 { "bitexact", OPT_TYPE_BOOL, 0, {&do_bitexact}, "force bitexact output" },
46064630 { "read_intervals", OPT_TYPE_FUNC, OPT_FUNC_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
46074631 { "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