From dc3ca1ba71e0452d37853279ffe857c593530a95 Mon Sep 17 00:00:00 2001 From: Jerome Wu Date: Sun, 23 Jul 2023 21:01:29 +0800 Subject: [PATCH] Upgrade fftools to n5.1.3 --- src/fftools/Makefile | 54 +++++++++++++++++++++++++++++++++++++--- src/fftools/ffmpeg_opt.c | 39 ++++++++++++++++++++++++++++- src/fftools/ffprobe.c | 6 ++++- 3 files changed, 94 insertions(+), 5 deletions(-) diff --git a/src/fftools/Makefile b/src/fftools/Makefile index 840afa3..81ad6c4 100644 --- a/src/fftools/Makefile +++ b/src/fftools/Makefile @@ -1,4 +1,52 @@ -all: build +AVPROGS-$(CONFIG_FFMPEG) += ffmpeg +AVPROGS-$(CONFIG_FFPLAY) += ffplay +AVPROGS-$(CONFIG_FFPROBE) += ffprobe -build: - cd ../../ && make +AVPROGS := $(AVPROGS-yes:%=%$(PROGSSUF)$(EXESUF)) +PROGS += $(AVPROGS) + +AVBASENAMES = ffmpeg ffplay ffprobe +ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF)) +ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) + +OBJS-ffmpeg += \ + fftools/ffmpeg_filter.o \ + fftools/ffmpeg_hw.o \ + fftools/ffmpeg_mux.o \ + fftools/ffmpeg_opt.o \ + +define DOFFTOOL +OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o $(OBJS-$(1)-yes) +$(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1)) +$$(OBJS-$(1)): | fftools +$$(OBJS-$(1)): CFLAGS += $(CFLAGS-$(1)) +$(1)$(PROGSSUF)_g$(EXESUF): LDFLAGS += $(LDFLAGS-$(1)) +$(1)$(PROGSSUF)_g$(EXESUF): FF_EXTRALIBS += $(EXTRALIBS-$(1)) +-include $$(OBJS-$(1):.o=.d) +endef + +$(foreach P,$(AVPROGS-yes),$(eval $(call DOFFTOOL,$(P)))) + +all: $(AVPROGS) + +fftools/ffprobe.o fftools/cmdutils.o: libavutil/ffversion.h | fftools +OUTDIRS += fftools + +ifdef AVPROGS +install: install-progs install-data +endif + +install-progs-yes: +install-progs-$(CONFIG_SHARED): install-libs + +install-progs: install-progs-yes $(AVPROGS) + $(Q)mkdir -p "$(BINDIR)" + $(INSTALL) -c -m 755 $(AVPROGS) "$(BINDIR)" + +uninstall: uninstall-progs + +uninstall-progs: + $(RM) $(addprefix "$(BINDIR)/", $(ALLAVPROGS)) + +clean:: + $(RM) $(ALLAVPROGS) $(ALLAVPROGS_G) $(CLEANSUFFIXES:%=fftools/%) diff --git a/src/fftools/ffmpeg_opt.c b/src/fftools/ffmpeg_opt.c index ac7fe3b..6e18a4a 100644 --- a/src/fftools/ffmpeg_opt.c +++ b/src/fftools/ffmpeg_opt.c @@ -2372,6 +2372,43 @@ static int init_complex_filters(void) return 0; } +static void set_channel_layout(OutputFilter *f, OutputStream *ost) +{ + int i, err; + + if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { + /* Pass the layout through for all orders but UNSPEC */ + err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout); + if (err < 0) + exit_program(1); + return; + } + + /* Requested layout is of order UNSPEC */ + if (!ost->enc->ch_layouts) { + /* Use the default native layout for the requested amount of channels when the + encoder doesn't have a list of supported layouts */ + av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); + return; + } + /* Encoder has a list of supported layouts. Pick the first layout in it with the + same amount of channels as the requested layout */ + for (i = 0; ost->enc->ch_layouts[i].nb_channels; i++) { + if (ost->enc->ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels) + break; + } + if (ost->enc->ch_layouts[i].nb_channels) { + /* Use it if one is found */ + err = av_channel_layout_copy(&f->ch_layout, &ost->enc->ch_layouts[i]); + if (err < 0) + exit_program(1); + return; + } + /* If no layout for the amount of channels requested was found, use the default + native layout for it. */ + av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); +} + static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; @@ -2774,7 +2811,7 @@ loop_end: f->sample_rates = ost->enc->supported_samplerates; } if (ost->enc_ctx->ch_layout.nb_channels) { - av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); + set_channel_layout(f, ost); } else if (ost->enc->ch_layouts) { f->ch_layouts = ost->enc->ch_layouts; } diff --git a/src/fftools/ffprobe.c b/src/fftools/ffprobe.c index d40e177..1aa403f 100644 --- a/src/fftools/ffprobe.c +++ b/src/fftools/ffprobe.c @@ -4026,7 +4026,7 @@ int ffprobe(int argc, char **argv) WriterContext *wctx; char *buf; char *w_name = NULL, *w_args = NULL; - int ret, i; + int ret, input_ret, i; init_dynload(); @@ -4150,10 +4150,14 @@ int ffprobe(int argc, char **argv) show_error(wctx, ret); } + input_ret = ret; + writer_print_section_footer(wctx); ret = writer_close(&wctx); if (ret < 0) av_log(NULL, AV_LOG_ERROR, "Writing output failed: %s\n", av_err2str(ret)); + + ret = FFMIN(ret, input_ret); } end: