* [FFmpeg-devel] [PATCH 02/47] fftools/ffmpeg_filter: move "smart" pixfmt selection to ffmpeg_mux_init
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 03/47] fftools/ffmpeg_mux_init: deprecate "smart" pixel format selection Anton Khirnov
` (45 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
This code works on encoder information and has no interaction with
filtering, so it does not belong in ffmpeg_filter.
---
fftools/ffmpeg_filter.c | 36 +-----------------------------------
fftools/ffmpeg_mux_init.c | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 35 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index de75c9970e..71595513f3 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -285,38 +285,6 @@ static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *c
}
}
-static enum AVPixelFormat
-choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target,
- int strict_std_compliance)
-{
- if (codec && codec->pix_fmts) {
- const enum AVPixelFormat *p = codec->pix_fmts;
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
- //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
- int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
- enum AVPixelFormat best= AV_PIX_FMT_NONE;
-
- if (strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
- p = get_compliance_normal_pix_fmts(codec, p);
- }
- for (; *p != AV_PIX_FMT_NONE; p++) {
- best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
- if (*p == target)
- break;
- }
- if (*p == AV_PIX_FMT_NONE) {
- if (target != AV_PIX_FMT_NONE)
- av_log(NULL, AV_LOG_WARNING,
- "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
- av_get_pix_fmt_name(target),
- codec->name,
- av_get_pix_fmt_name(best));
- return best;
- }
- }
- return target;
-}
-
/* May return NULL (no pixel format found), a static string or a string
* backed by the bprint. Nothing has been written to the AVBPrint in case
* NULL is returned. The AVBPrint provided should be clean. */
@@ -326,7 +294,6 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
AVCodecContext *enc = ost->enc_ctx;
const AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
if (strict_dict)
- // used by choose_pixel_fmt() and below
av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
if (ost->keep_pix_fmt) {
@@ -335,8 +302,7 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt);
}
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
- return av_get_pix_fmt_name(choose_pixel_fmt(enc->codec, enc->pix_fmt,
- ost->enc_ctx->strict_std_compliance));
+ return av_get_pix_fmt_name(enc->pix_fmt);
} else if (enc->codec->pix_fmts) {
const enum AVPixelFormat *p;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 2d45fa7c7c..3fe157c2e4 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -503,6 +503,32 @@ static int fmt_in_list(const int *formats, int format)
return 0;
}
+static enum AVPixelFormat
+choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
+{
+ const enum AVPixelFormat *p = codec->pix_fmts;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
+ //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
+ int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
+ enum AVPixelFormat best= AV_PIX_FMT_NONE;
+
+ for (; *p != AV_PIX_FMT_NONE; p++) {
+ best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
+ if (*p == target)
+ break;
+ }
+ if (*p == AV_PIX_FMT_NONE) {
+ if (target != AV_PIX_FMT_NONE)
+ av_log(NULL, AV_LOG_WARNING,
+ "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
+ av_get_pix_fmt_name(target),
+ codec->name,
+ av_get_pix_fmt_name(best));
+ return best;
+ }
+ return target;
+}
+
static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
{
const enum AVPixelFormat *fmts = ost->enc_ctx->codec->pix_fmts;
@@ -540,6 +566,9 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
}
}
+ if (fmts && !fmt_in_list(fmts, fmt))
+ fmt = choose_pixel_fmt(ost->enc_ctx->codec, fmt);
+
return fmt;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 03/47] fftools/ffmpeg_mux_init: deprecate "smart" pixel format selection
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 02/47] fftools/ffmpeg_filter: move "smart" pixfmt selection to ffmpeg_mux_init Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 04/47] tests/fate: fix mismatches between requested and actually used pixel formats Anton Khirnov
` (44 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
It may override a format explicitly requested with -pix_fmt and instead
select something completely unrelated, which is a user-hostile behaviour
and is inconsistent with how other options generally work.
Print a warning and delay for a second to make the users aware of the
deprecation.
---
doc/ffmpeg.texi | 3 +--
fftools/ffmpeg.h | 1 +
fftools/ffmpeg_mux_init.c | 15 +++++++++++++--
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 2273c39214..a6ef5590c7 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1014,8 +1014,7 @@ Disable autoscale at your own risk.
@item -pix_fmt[:@var{stream_specifier}] @var{format} (@emph{input/output,per-stream})
Set pixel format. Use @code{-pix_fmts} to show all the supported
pixel formats.
-If the selected pixel format can not be selected, ffmpeg will print a
-warning and select the best pixel format supported by the encoder.
+
If @var{pix_fmt} is prefixed by a @code{+}, ffmpeg will exit with an error
if the requested pixel format can not be selected, and automatic conversions
inside filtergraphs are disabled.
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index f45ddf33b2..7c4f4365c6 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -57,6 +57,7 @@
#define FFMPEG_OPT_QPHIST 1
#define FFMPEG_OPT_ADRIFT_THRESHOLD 1
#define FFMPEG_OPT_ENC_TIME_BASE_NUM 1
+#define FFMPEG_OPT_SMART_PIXFMT 1
enum VideoSyncMethod {
VSYNC_AUTO = -1,
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 3fe157c2e4..03d60f2a19 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -45,6 +45,7 @@
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
+#include "libavutil/time.h"
#define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
@@ -503,6 +504,7 @@ static int fmt_in_list(const int *formats, int format)
return 0;
}
+#if FFMPEG_OPT_SMART_PIXFMT
static enum AVPixelFormat
choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
{
@@ -518,16 +520,23 @@ choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
break;
}
if (*p == AV_PIX_FMT_NONE) {
- if (target != AV_PIX_FMT_NONE)
+ if (target != AV_PIX_FMT_NONE) {
av_log(NULL, AV_LOG_WARNING,
- "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
+ "Requested pixel format '%s' is nut supported by encoder '%s', "
+ "auto-selecting format '%s'\n",
av_get_pix_fmt_name(target),
codec->name,
av_get_pix_fmt_name(best));
+ av_log(NULL, AV_LOG_WARNING, "This behaviour is deprecated and will "
+ "be removed. Use -h encoder=%s to check supported pixel "
+ "formats and select one of them.\n", codec->name);
+ av_usleep(1000000);
+ }
return best;
}
return target;
}
+#endif
static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
{
@@ -566,8 +575,10 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
}
}
+#if FFMPEG_OPT_SMART_PIXFMT
if (fmts && !fmt_in_list(fmts, fmt))
fmt = choose_pixel_fmt(ost->enc_ctx->codec, fmt);
+#endif
return fmt;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 04/47] tests/fate: fix mismatches between requested and actually used pixel formats
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 02/47] fftools/ffmpeg_filter: move "smart" pixfmt selection to ffmpeg_mux_init Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 03/47] fftools/ffmpeg_mux_init: deprecate "smart" pixel format selection Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 05/47] fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection Anton Khirnov
` (43 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
tests/fate/fits.mak | 6 +++---
tests/fate/lavf-video.mak | 2 +-
tests/fate/vcodec.mak | 4 ++--
tests/ref/fate/{fitsdec-gbrap16le => fitsdec-gbrap16be} | 4 ++--
tests/ref/fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} | 4 ++--
tests/ref/lavf/gif | 2 +-
6 files changed, 11 insertions(+), 11 deletions(-)
rename tests/ref/fate/{fitsdec-gbrap16le => fitsdec-gbrap16be} (79%)
rename tests/ref/fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} (79%)
diff --git a/tests/fate/fits.mak b/tests/fate/fits.mak
index b9e99d97ee..d85946bc1a 100644
--- a/tests/fate/fits.mak
+++ b/tests/fate/fits.mak
@@ -8,8 +8,8 @@ tests/data/fits-multi.fits: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
# TODO: Use an actual 64bit input file and fix the gbrp16 test on big-endian
fits-png-map-gray := gray8
fits-png-map-gbrp := rgb24
-fits-png-map-gbrp16 := rgb48
-fits-png-map-gbrap16le := rgba64
+fits-png-map-gbrp16be := rgb48
+fits-png-map-gbrap16be := rgba64
FATE_FITS_DEC-$(call FRAMECRC, FITS, FITS, SCALE_FILTER) += fate-fitsdec-ext_data_min_max
fate-fitsdec-ext_data_min_max: CMD = framecrc -i $(TARGET_SAMPLES)/fits/x0cj010ct_d0h.fit -pix_fmt gray16le -vf scale
@@ -30,7 +30,7 @@ fate-fitsdec-multi: CMD = framecrc -i $(TARGET_PATH)/tests/data/fits-multi.fits
fate-fitsdec%: PIXFMT = $(word 3, $(subst -, ,$(@)))
fate-fitsdec%: CMD = transcode image2 $(TARGET_SAMPLES)/png1/lena-$(fits-png-map-$(PIXFMT)).png fits "-vf scale -pix_fmt $(PIXFMT)"
-FATE_FITS_DEC_PIXFMT = gray gbrp gbrp16 gbrap16le
+FATE_FITS_DEC_PIXFMT = gray gbrp gbrp16be gbrap16be
FATE_FITS_DEC-$(call TRANSCODE, FITS, FITS, IMAGE2_DEMUXER PNG_DECODER SCALE_FILTER) += $(FATE_FITS_DEC_PIXFMT:%=fate-fitsdec-%)
FATE_FITS += $(FATE_FITS_DEC-yes)
diff --git a/tests/fate/lavf-video.mak b/tests/fate/lavf-video.mak
index e73f8f203b..da3b114bc8 100644
--- a/tests/fate/lavf-video.mak
+++ b/tests/fate/lavf-video.mak
@@ -27,7 +27,7 @@ fate-lavf-gbrp.fits: CMD = lavf_video "-pix_fmt gbrp"
fate-lavf-gbrap.fits: CMD = lavf_video "-pix_fmt gbrap"
fate-lavf-gbrp16be.fits: CMD = lavf_video "-pix_fmt gbrp16be"
fate-lavf-gbrap16be.fits: CMD = lavf_video "-pix_fmt gbrap16be"
-fate-lavf-gif: CMD = lavf_video "-pix_fmt rgb24"
+fate-lavf-gif: CMD = lavf_video "-pix_fmt rgb8"
FATE_AVCONV += $(FATE_LAVF_VIDEO)
fate-lavf-video fate-lavf: $(FATE_LAVF_VIDEO)
diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak
index 2839e54de8..e32d28c556 100644
--- a/tests/fate/vcodec.mak
+++ b/tests/fate/vcodec.mak
@@ -210,9 +210,9 @@ fate-vsynth%-h263p: ENCOPTS = -qscale 2 -flags +aic -umv 1 -aiv 1 -
FATE_VCODEC_SCALE-$(call ENCDEC, HUFFYUV, AVI) += huffyuv huffyuvbgr24 huffyuvbgra
fate-vsynth%-huffyuv: ENCOPTS = -c:v huffyuv -pix_fmt yuv422p -sws_flags neighbor
fate-vsynth%-huffyuv: DECOPTS = -sws_flags neighbor
-fate-vsynth%-huffyuvbgr24: ENCOPTS = -c:v huffyuv -pix_fmt bgr24 -sws_flags neighbor
+fate-vsynth%-huffyuvbgr24: ENCOPTS = -c:v huffyuv -pix_fmt rgb24 -sws_flags neighbor
fate-vsynth%-huffyuvbgr24: DECOPTS = -sws_flags neighbor
-fate-vsynth%-huffyuvbgra: ENCOPTS = -c:v huffyuv -pix_fmt bgr32 -sws_flags neighbor
+fate-vsynth%-huffyuvbgra: ENCOPTS = -c:v huffyuv -pix_fmt rgb32 -sws_flags neighbor
fate-vsynth%-huffyuvbgra: DECOPTS = -sws_flags neighbor
FATE_VCODEC_SCALE-$(call ENCDEC, JPEGLS, AVI) += jpegls
diff --git a/tests/ref/fate/fitsdec-gbrap16le b/tests/ref/fate/fitsdec-gbrap16be
similarity index 79%
rename from tests/ref/fate/fitsdec-gbrap16le
rename to tests/ref/fate/fitsdec-gbrap16be
index 53ef980b13..1174a0f1d8 100644
--- a/tests/ref/fate/fitsdec-gbrap16le
+++ b/tests/ref/fate/fitsdec-gbrap16be
@@ -1,5 +1,5 @@
-64526d8da12d1fa07ceea5725647076f *tests/data/fate/fitsdec-gbrap16le.fits
-135360 tests/data/fate/fitsdec-gbrap16le.fits
+64526d8da12d1fa07ceea5725647076f *tests/data/fate/fitsdec-gbrap16be.fits
+135360 tests/data/fate/fitsdec-gbrap16be.fits
#tb 0: 1/1
#media_type 0: video
#codec_id 0: rawvideo
diff --git a/tests/ref/fate/fitsdec-gbrp16 b/tests/ref/fate/fitsdec-gbrp16be
similarity index 79%
rename from tests/ref/fate/fitsdec-gbrp16
rename to tests/ref/fate/fitsdec-gbrp16be
index 9250690e9b..ff4ca9e65c 100644
--- a/tests/ref/fate/fitsdec-gbrp16
+++ b/tests/ref/fate/fitsdec-gbrp16be
@@ -1,5 +1,5 @@
-2078208c93ba417d3fe150ba42bf5a30 *tests/data/fate/fitsdec-gbrp16.fits
-103680 tests/data/fate/fitsdec-gbrp16.fits
+2078208c93ba417d3fe150ba42bf5a30 *tests/data/fate/fitsdec-gbrp16be.fits
+103680 tests/data/fate/fitsdec-gbrp16be.fits
#tb 0: 1/1
#media_type 0: video
#codec_id 0: rawvideo
diff --git a/tests/ref/lavf/gif b/tests/ref/lavf/gif
index fc94b9df3d..7f353df286 100644
--- a/tests/ref/lavf/gif
+++ b/tests/ref/lavf/gif
@@ -1,3 +1,3 @@
e35f5ea283bbcb249818e0078ec72664 *tests/data/lavf/lavf.gif
2011766 tests/data/lavf/lavf.gif
-tests/data/lavf/lavf.gif CRC=0x2429faff
+tests/data/lavf/lavf.gif CRC=0x37f4d323
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 05/47] fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (2 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 04/47] tests/fate: fix mismatches between requested and actually used pixel formats Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 06/47] fftools/ffmpeg_filter: restrict reap_filters() to a single filtergraph Anton Khirnov
` (42 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
ffmpeg CLI pixel format selection for filtering currently special-cases
MJPEG encoding, where it will restrict the supported list of pixel
formats depending on the value of the -strict option. In order to get
that value it will apply it from the options dict into the encoder
context, which is a highly invasive action even now, and would become a
race once encoding is moved to its own thread.
The ugliness of this code can be much reduced by moving the special
handling of MJPEG into ofilter_bind_ost(), which is called from encoder
init and is thus synchronized with it. There is also no need to write
anything to the encoder context, we can evaluate the option into our
stack variable.
There is also no need to access AVCodec at all during pixel format
selection, as the pixel formats array is already stored in
OutputFilterPriv.
---
fftools/ffmpeg_filter.c | 64 ++++++++++++++++++++---------------------
1 file changed, 32 insertions(+), 32 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 71595513f3..e14b8f0f3c 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -270,46 +270,22 @@ static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts,
ifp->sub2video.initialize = 0;
}
-// FIXME: YUV420P etc. are actually supported with full color range,
-// yet the latter information isn't available here.
-static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[])
-{
- static const enum AVPixelFormat mjpeg_formats[] =
- { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
- AV_PIX_FMT_NONE };
-
- if (!strcmp(codec->name, "mjpeg")) {
- return mjpeg_formats;
- } else {
- return default_formats;
- }
-}
-
/* May return NULL (no pixel format found), a static string or a string
* backed by the bprint. Nothing has been written to the AVBPrint in case
* NULL is returned. The AVBPrint provided should be clean. */
static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
{
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
OutputStream *ost = ofilter->ost;
- AVCodecContext *enc = ost->enc_ctx;
- const AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
- if (strict_dict)
- av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0);
- if (ost->keep_pix_fmt) {
- if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE)
- return NULL;
- return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt);
+ if (ost->keep_pix_fmt) {
+ return ofp->format == AV_PIX_FMT_NONE ? NULL :
+ av_get_pix_fmt_name(ofp->format);
}
- if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
- return av_get_pix_fmt_name(enc->pix_fmt);
- } else if (enc->codec->pix_fmts) {
- const enum AVPixelFormat *p;
-
- p = enc->codec->pix_fmts;
- if (ost->enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) {
- p = get_compliance_normal_pix_fmts(enc->codec, p);
- }
+ if (ofp->format != AV_PIX_FMT_NONE) {
+ return av_get_pix_fmt_name(ofp->format);
+ } else if (ofp->formats) {
+ const enum AVPixelFormat *p = ofp->formats;
for (; *p != AV_PIX_FMT_NONE; p++) {
const char *name = av_get_pix_fmt_name(*p);
@@ -668,6 +644,30 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
ofp->format = ost->enc_ctx->pix_fmt;
} else {
ofp->formats = c->pix_fmts;
+
+ // MJPEG encoder exports a full list of supported pixel formats,
+ // but the full-range ones are experimental-only.
+ // Restrict the auto-conversion list unless -strict experimental
+ // has been specified.
+ if (!strcmp(c->name, "mjpeg")) {
+ // FIXME: YUV420P etc. are actually supported with full color range,
+ // yet the latter information isn't available here.
+ static const enum AVPixelFormat mjpeg_formats[] =
+ { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
+ AV_PIX_FMT_NONE };
+
+ const AVDictionaryEntry *strict = av_dict_get(ost->encoder_opts, "strict", NULL, 0);
+ int strict_val = ost->enc_ctx->strict_std_compliance;
+
+ if (strict) {
+ const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, NULL, 0, 0);
+ av_assert0(o);
+ av_opt_eval_int(ost->enc_ctx, o, strict->value, &strict_val);
+ }
+
+ if (strict_val > FF_COMPLIANCE_UNOFFICIAL)
+ ofp->formats = mjpeg_formats;
+ }
}
fgp->disable_conversions |= ost->keep_pix_fmt;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 06/47] fftools/ffmpeg_filter: restrict reap_filters() to a single filtergraph
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (3 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 05/47] fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 07/47] fftools/ffmpeg_mux_init: avoid invalid memory access in set_dispositions() Anton Khirnov
` (41 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
This is more natural, as all except one of its callers require
processing only one filtergraph.
---
fftools/ffmpeg.c | 10 +++++++++-
fftools/ffmpeg.h | 4 ++--
fftools/ffmpeg_filter.c | 33 ++++++++++++++++-----------------
3 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index cbeddab125..27c4e7ef26 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1171,7 +1171,15 @@ static int transcode_step(OutputStream *ost)
if (ret < 0)
return ret == AVERROR_EOF ? 0 : ret;
- return reap_filters(0);
+ // process_input() above might have caused output to become available
+ // in multiple filtergraphs, so we process all of them
+ for (int i = 0; i < nb_filtergraphs; i++) {
+ ret = reap_filters(filtergraphs[i], 0);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
}
/*
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7c4f4365c6..0189bee0f3 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -766,12 +766,12 @@ void fg_free(FilterGraph **pfg);
int fg_transcode_step(FilterGraph *graph, InputStream **best_ist);
/**
- * Get and encode new output from any of the filtergraphs, without causing
+ * Get and encode new output from specified filtergraph, without causing
* activity.
*
* @return 0 for success, <0 for severe errors
*/
-int reap_filters(int flush);
+int reap_filters(FilterGraph *fg, int flush);
int ffmpeg_parse_options(int argc, char **argv);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index e14b8f0f3c..49e0800e6e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1695,24 +1695,23 @@ int filtergraph_is_simple(const FilterGraph *fg)
return fgp->is_simple;
}
-int reap_filters(int flush)
+int reap_filters(FilterGraph *fg, int flush)
{
+ FilterGraphPriv *fgp = fgp_from_fg(fg);
+ AVFrame *filtered_frame = fgp->frame;
+
+ if (!fg->graph)
+ return 0;
+
/* Reap all buffers present in the buffer sinks */
- for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
- OutputFilterPriv *ofp;
- FilterGraphPriv *fgp;
- AVFrame *filtered_frame;
- AVFilterContext *filter;
+ for (int i = 0; i < fg->nb_outputs; i++) {
+ OutputFilter *ofilter = fg->outputs[i];
+ OutputStream *ost = ofilter->ost;
+ OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
+ AVFilterContext *filter = ofp->filter;
+
int ret = 0;
- if (!ost->filter || !ost->filter->graph->graph)
- continue;
- fgp = fgp_from_fg(ost->filter->graph);
- ofp = ofp_from_ofilter(ost->filter);
- filter = ofp->filter;
-
- filtered_frame = fgp->frame;
-
while (1) {
FrameData *fd;
@@ -1931,7 +1930,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference)
return ret;
}
- ret = reap_filters(0);
+ ret = reap_filters(fg, 0);
if (ret < 0 && ret != AVERROR_EOF) {
av_log(fg, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
return ret;
@@ -2000,10 +1999,10 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist)
*best_ist = NULL;
ret = avfilter_graph_request_oldest(graph->graph);
if (ret >= 0)
- return reap_filters(0);
+ return reap_filters(graph, 0);
if (ret == AVERROR_EOF) {
- reap_filters(1);
+ reap_filters(graph, 1);
for (int i = 0; i < graph->nb_outputs; i++) {
OutputFilter *ofilter = graph->outputs[i];
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 07/47] fftools/ffmpeg_mux_init: avoid invalid memory access in set_dispositions()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (4 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 06/47] fftools/ffmpeg_filter: restrict reap_filters() to a single filtergraph Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 08/47] fftools/ffmpeg_enc: return errors from enc_frame() instead of aborting Anton Khirnov
` (40 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
This function assumes AVMEDIA_* are always positive, while in fact it
can also handle AVMEDIA_TYPE_UNKNOWN, which is -1.
---
fftools/ffmpeg_mux_init.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 03d60f2a19..cc5ec68040 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -2296,8 +2296,9 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o)
OutputFile *of = &mux->of;
AVFormatContext *ctx = mux->fc;
- int nb_streams[AVMEDIA_TYPE_NB] = { 0 };
- int have_default[AVMEDIA_TYPE_NB] = { 0 };
+ // indexed by type+1, because AVMEDIA_TYPE_UNKNOWN=-1
+ int nb_streams[AVMEDIA_TYPE_NB + 1] = { 0 };
+ int have_default[AVMEDIA_TYPE_NB + 1] = { 0 };
int have_manual = 0;
int ret = 0;
@@ -2311,7 +2312,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o)
for (int i = 0; i < ctx->nb_streams; i++) {
OutputStream *ost = of->streams[i];
- nb_streams[ost->type]++;
+ nb_streams[ost->type + 1]++;
MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st);
@@ -2321,7 +2322,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o)
ost->st->disposition = ost->ist->st->disposition;
if (ost->st->disposition & AV_DISPOSITION_DEFAULT)
- have_default[ost->type] = 1;
+ have_default[ost->type + 1] = 1;
}
}
@@ -2346,12 +2347,12 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o)
OutputStream *ost = of->streams[i];
enum AVMediaType type = ost->type;
- if (nb_streams[type] < 2 || have_default[type] ||
+ if (nb_streams[type + 1] < 2 || have_default[type + 1] ||
ost->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
continue;
ost->st->disposition |= AV_DISPOSITION_DEFAULT;
- have_default[type] = 1;
+ have_default[type + 1] = 1;
}
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 08/47] fftools/ffmpeg_enc: return errors from enc_frame() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (5 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 07/47] fftools/ffmpeg_mux_init: avoid invalid memory access in set_dispositions() Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 09/47] fftools/ffmpeg_enc: return errors from enc_open() " Anton Khirnov
` (39 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_enc.c | 6 ++++--
fftools/ffmpeg_filter.c | 12 +++++++++---
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 0189bee0f3..38f2b1ef66 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -815,7 +815,7 @@ void enc_free(Encoder **penc);
int enc_open(OutputStream *ost, AVFrame *frame);
int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub);
-void enc_frame(OutputStream *ost, AVFrame *frame);
+int enc_frame(OutputStream *ost, AVFrame *frame);
void enc_flush(void);
/*
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1489b2f179..6130e3e221 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1133,17 +1133,19 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_frame_move_ref(e->last_frame, frame);
}
-void enc_frame(OutputStream *ost, AVFrame *frame)
+int enc_frame(OutputStream *ost, AVFrame *frame)
{
OutputFile *of = output_files[ost->file_index];
int ret;
ret = enc_open(ost, frame);
if (ret < 0)
- exit_program(1);
+ return ret;
if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) do_video_out(of, ost, frame);
else do_audio_out(of, ost, frame);
+
+ return 0;
}
void enc_flush(void)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 49e0800e6e..d373d8c002 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1722,8 +1722,11 @@ int reap_filters(FilterGraph *fg, int flush)
av_log(fgp, AV_LOG_WARNING,
"Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret));
} else if (flush && ret == AVERROR_EOF && ofp->got_frame &&
- av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
- enc_frame(ost, NULL);
+ av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO) {
+ ret = enc_frame(ost, NULL);
+ if (ret < 0)
+ return ret;
+ }
break;
}
@@ -1759,8 +1762,11 @@ int reap_filters(FilterGraph *fg, int flush)
if (ost->type == AVMEDIA_TYPE_VIDEO)
fd->frame_rate_filter = av_buffersink_get_frame_rate(filter);
- enc_frame(ost, filtered_frame);
+ ret = enc_frame(ost, filtered_frame);
av_frame_unref(filtered_frame);
+ if (ret < 0)
+ return ret;
+
ofp->got_frame = 1;
}
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 09/47] fftools/ffmpeg_enc: return errors from enc_open() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (6 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 08/47] fftools/ffmpeg_enc: return errors from enc_frame() instead of aborting Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 10/47] fftools/ffmpeg_enc: return errors from do_*_out() " Anton Khirnov
` (38 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_enc.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 6130e3e221..f84641b1c4 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -165,19 +165,19 @@ static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref
return 0;
}
-static void set_encoder_id(OutputFile *of, OutputStream *ost)
+static int set_encoder_id(OutputFile *of, OutputStream *ost)
{
const char *cname = ost->enc_ctx->codec->name;
uint8_t *encoder_string;
int encoder_string_len;
if (av_dict_get(ost->st->metadata, "encoder", NULL, 0))
- return;
+ return 0;
encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(cname) + 2;
encoder_string = av_mallocz(encoder_string_len);
if (!encoder_string)
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
if (!of->bitexact && !ost->bitexact)
av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len);
@@ -186,6 +186,8 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost)
av_strlcat(encoder_string, cname, encoder_string_len);
av_dict_set(&ost->st->metadata, "encoder", encoder_string,
AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE);
+
+ return 0;
}
int enc_open(OutputStream *ost, AVFrame *frame)
@@ -211,7 +213,9 @@ int enc_open(OutputStream *ost, AVFrame *frame)
return AVERROR(ENOMEM);
}
- set_encoder_id(output_files[ost->file_index], ost);
+ ret = set_encoder_id(output_files[ost->file_index], ost);
+ if (ret < 0)
+ return ret;
if (ist) {
dec_ctx = ist->dec_ctx;
@@ -417,7 +421,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
if (ret < 0) {
av_log(ost, AV_LOG_FATAL,
"Error initializing the output stream codec context.\n");
- exit_program(1);
+ return ret;
}
if (ost->enc_ctx->nb_coded_side_data) {
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 10/47] fftools/ffmpeg_enc: return errors from do_*_out() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (7 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 09/47] fftools/ffmpeg_enc: return errors from enc_open() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 11/47] fftools/ffmpeg_enc: return errors from enc_flush() " Anton Khirnov
` (37 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_enc.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f84641b1c4..72ba56a03d 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -839,8 +839,8 @@ static int submit_encode_frame(OutputFile *of, OutputStream *ost,
}
}
-static void do_audio_out(OutputFile *of, OutputStream *ost,
- AVFrame *frame)
+static int do_audio_out(OutputFile *of, OutputStream *ost,
+ AVFrame *frame)
{
Encoder *e = ost->enc;
AVCodecContext *enc = ost->enc_ctx;
@@ -850,7 +850,7 @@ static void do_audio_out(OutputFile *of, OutputStream *ost,
enc->ch_layout.nb_channels != frame->ch_layout.nb_channels) {
av_log(ost, AV_LOG_ERROR,
"Audio channel count changed and encoder does not support parameter changes\n");
- return;
+ return 0;
}
if (frame->pts == AV_NOPTS_VALUE)
@@ -866,13 +866,12 @@ static void do_audio_out(OutputFile *of, OutputStream *ost,
enc->time_base);
if (!check_recording_time(ost, frame->pts, frame->time_base))
- return;
+ return 0;
e->next_pts = frame->pts + frame->nb_samples;
ret = submit_encode_frame(of, ost, frame);
- if (ret < 0 && ret != AVERROR_EOF)
- exit_program(1);
+ return (ret < 0 && ret != AVERROR_EOF) ? ret : 0;
}
static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
@@ -1059,7 +1058,7 @@ force_keyframe:
}
/* May modify/reset frame */
-static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
+static int do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
{
int ret;
Encoder *e = ost->enc;
@@ -1090,7 +1089,7 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
if (nb_frames > dts_error_threshold * 30) {
av_log(ost, AV_LOG_ERROR, "%"PRId64" frame duplication too large, skipping\n", nb_frames - 1);
ost->nb_frames_drop++;
- return;
+ return 0;
}
ost->nb_frames_dup += nb_frames - (nb_frames_prev && ost->last_dropped) - (nb_frames > nb_frames_prev);
av_log(ost, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", nb_frames - 1);
@@ -1112,12 +1111,12 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
in_picture = frame;
if (!in_picture)
- return;
+ return 0;
in_picture->pts = e->next_pts;
if (!check_recording_time(ost, in_picture->pts, ost->enc_ctx->time_base))
- return;
+ return 0;
in_picture->quality = enc->global_quality;
in_picture->pict_type = forced_kf_apply(ost, &ost->kf, enc->time_base, in_picture, i);
@@ -1126,7 +1125,7 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
if (ret == AVERROR_EOF)
break;
else if (ret < 0)
- exit_program(1);
+ return ret;
e->next_pts++;
e->vsync_frame_number++;
@@ -1135,6 +1134,8 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_frame_unref(e->last_frame);
if (frame)
av_frame_move_ref(e->last_frame, frame);
+
+ return 0;
}
int enc_frame(OutputStream *ost, AVFrame *frame)
@@ -1146,10 +1147,8 @@ int enc_frame(OutputStream *ost, AVFrame *frame)
if (ret < 0)
return ret;
- if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) do_video_out(of, ost, frame);
- else do_audio_out(of, ost, frame);
-
- return 0;
+ return ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO ?
+ do_video_out(of, ost, frame) : do_audio_out(of, ost, frame);
}
void enc_flush(void)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 11/47] fftools/ffmpeg_enc: return errors from enc_flush() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (8 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 10/47] fftools/ffmpeg_enc: return errors from do_*_out() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 12/47] fftools/ffmpeg_enc: return errors from encode_frame() " Anton Khirnov
` (36 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 2 +-
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_enc.c | 6 ++++--
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 27c4e7ef26..926fdea23a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1250,7 +1250,7 @@ static int transcode(int *err_rate_exceeded)
} else if (err_rate)
av_log(ist, AV_LOG_VERBOSE, "Decode error rate %g\n", err_rate);
}
- enc_flush();
+ ret = err_merge(ret, enc_flush());
term_exit();
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 38f2b1ef66..7329df6607 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -816,7 +816,7 @@ void enc_free(Encoder **penc);
int enc_open(OutputStream *ost, AVFrame *frame);
int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub);
int enc_frame(OutputStream *ost, AVFrame *frame);
-void enc_flush(void);
+int enc_flush(void);
/*
* Initialize muxing state for the given stream, should be called
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 72ba56a03d..728c09dcad 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -1151,7 +1151,7 @@ int enc_frame(OutputStream *ost, AVFrame *frame)
do_video_out(of, ost, frame) : do_audio_out(of, ost, frame);
}
-void enc_flush(void)
+int enc_flush(void)
{
int ret;
@@ -1172,6 +1172,8 @@ void enc_flush(void)
ret = submit_encode_frame(of, ost, NULL);
if (ret != AVERROR_EOF)
- exit_program(1);
+ return ret;
}
+
+ return 0;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 12/47] fftools/ffmpeg_enc: return errors from encode_frame() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (9 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 11/47] fftools/ffmpeg_enc: return errors from enc_flush() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 13/47] fftools/ffmpeg_mux: return errors from of_output_packet() " Anton Khirnov
` (35 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_enc.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 728c09dcad..9ca3940b93 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -641,7 +641,7 @@ static inline double psnr(double d)
return -10.0 * log10(d);
}
-static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats)
+static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats)
{
Encoder *e = ost->enc;
const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,
@@ -663,14 +663,14 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write
}
if (!write_vstats)
- return;
+ return 0;
/* this is executed just the first time update_video_stats is called */
if (!vstats_file) {
vstats_file = fopen(vstats_filename, "w");
if (!vstats_file) {
perror("fopen");
- exit_program(1);
+ return AVERROR(errno);
}
}
@@ -697,6 +697,8 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write
fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
(double)e->data_size / 1024, ti1, bitrate, avg_bitrate);
fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(pict_type));
+
+ return 0;
}
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
@@ -738,6 +740,8 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
}
while (1) {
+ av_packet_unref(pkt);
+
ret = avcodec_receive_packet(enc, pkt);
update_benchmark("%s_%s %d.%d", action, type_desc,
ost->file_index, ost->index);
@@ -759,8 +763,12 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
return ret;
}
- if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
- update_video_stats(ost, pkt, !!vstats_filename);
+ if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+ ret = update_video_stats(ost, pkt, !!vstats_filename);
+ if (ret < 0)
+ return ret;
+ }
+
if (ost->enc_stats_post.io)
enc_stats_write(ost, &ost->enc_stats_post, NULL, pkt,
e->packets_encoded);
@@ -779,7 +787,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_log(NULL, AV_LOG_ERROR,
"Subtitle heartbeat logic failed in %s! (%s)\n",
__func__, av_err2str(ret));
- exit_program(1);
+ return ret;
}
e->data_size += pkt->size;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 13/47] fftools/ffmpeg_mux: return errors from of_output_packet() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (10 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 12/47] fftools/ffmpeg_enc: return errors from encode_frame() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 14/47] fftools/ffmpeg_dec: return error codes from dec_packet() " Anton Khirnov
` (34 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 4 +++-
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_enc.c | 12 ++++++++----
fftools/ffmpeg_mux.c | 20 +++++++++-----------
4 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 926fdea23a..ddb011741a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1120,7 +1120,9 @@ static int process_input(int file_index)
OutputStream *ost = ist->outputs[oidx];
OutputFile *of = output_files[ost->file_index];
close_output_stream(ost);
- of_output_packet(of, ost, NULL);
+ ret = of_output_packet(of, ost, NULL);
+ if (ret < 0)
+ return ret;
}
}
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7329df6607..62b56a8cd8 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -831,7 +831,7 @@ void of_close(OutputFile **pof);
void of_enc_stats_close(void);
-void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt);
+int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt);
/**
* @param dts predicted packet dts in AV_TIME_BASE_Q
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 9ca3940b93..01e1b0656c 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -563,7 +563,9 @@ int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub)
}
pkt->dts = pkt->pts;
- of_output_packet(of, ost, pkt);
+ ret = of_output_packet(of, ost, pkt);
+ if (ret < 0)
+ return ret;
}
return 0;
@@ -756,8 +758,8 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_assert0(frame); // should never happen during flushing
return 0;
} else if (ret == AVERROR_EOF) {
- of_output_packet(of, ost, NULL);
- return ret;
+ ret = of_output_packet(of, ost, NULL);
+ return ret < 0 ? ret : AVERROR_EOF;
} else if (ret < 0) {
av_log(ost, AV_LOG_ERROR, "%s encoding failed\n", type_desc);
return ret;
@@ -794,7 +796,9 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
e->packets_encoded++;
- of_output_packet(of, ost, pkt);
+ ret = of_output_packet(of, ost, pkt);
+ if (ret < 0)
+ return ret;
}
av_assert0(0);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index a6cc824496..24cdf00469 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -330,7 +330,7 @@ static int submit_packet(Muxer *mux, AVPacket *pkt, OutputStream *ost)
return 0;
}
-void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
+int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
{
Muxer *mux = mux_from_of(of);
MuxStream *ms = ms_from_ost(ost);
@@ -359,7 +359,7 @@ void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
while (!bsf_eof) {
ret = av_bsf_receive_packet(ms->bsf_ctx, ms->bsf_pkt);
if (ret == AVERROR(EAGAIN))
- return;
+ return 0;
else if (ret == AVERROR_EOF)
bsf_eof = 1;
else if (ret < 0) {
@@ -377,16 +377,14 @@ void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
goto mux_fail;
}
- return;
+ return 0;
mux_fail:
err_msg = "submitting a packet to the muxer";
fail:
av_log(ost, AV_LOG_ERROR, "Error %s\n", err_msg);
- if (exit_on_error)
- exit_program(1);
-
+ return exit_on_error ? ret : 0;
}
int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
@@ -405,10 +403,8 @@ int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
pkt = NULL;
// EOF: flush output bitstream filters.
- if (!pkt) {
- of_output_packet(of, ost, NULL);
- return 0;
- }
+ if (!pkt)
+ return of_output_packet(of, ost, NULL);
if (!ms->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) &&
!ms->copy_initial_nonkeyframes)
@@ -461,7 +457,9 @@ int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
}
}
- of_output_packet(of, ost, opkt);
+ ret = of_output_packet(of, ost, opkt);
+ if (ret < 0)
+ return ret;
ms->streamcopy_started = 1;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 14/47] fftools/ffmpeg_dec: return error codes from dec_packet() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (11 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 13/47] fftools/ffmpeg_mux: return errors from of_output_packet() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 15/47] fftools/ffmpeg_dec: drop redundant handling of AVERROR_EXPERIMENTAL Anton Khirnov
` (33 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 5 ++++-
fftools/ffmpeg_dec.c | 4 ++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ddb011741a..b4ea52ac1d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -814,8 +814,11 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
int eof_reached = 0;
int duration_exceeded;
- if (ist->decoding_needed)
+ if (ist->decoding_needed) {
ret = dec_packet(ist, pkt, no_eof);
+ if (ret < 0 && ret != AVERROR_EOF)
+ return ret;
+ }
if (ret == AVERROR_EOF || (!pkt && !ist->decoding_needed))
eof_reached = 1;
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 5c1b8888e9..f5f764b6fa 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -816,7 +816,7 @@ finish:
}
// non-EOF errors here are all fatal
if (ret < 0 && ret != AVERROR_EOF)
- report_and_exit(ret);
+ return ret;
// signal EOF to our downstreams
if (ist->dec->type == AVMEDIA_TYPE_SUBTITLE)
@@ -825,7 +825,7 @@ finish:
ret = send_filter_eof(ist);
if (ret < 0) {
av_log(NULL, AV_LOG_FATAL, "Error marking filters as finished\n");
- exit_program(1);
+ return ret;
}
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 15/47] fftools/ffmpeg_dec: drop redundant handling of AVERROR_EXPERIMENTAL
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (12 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 14/47] fftools/ffmpeg_dec: return error codes from dec_packet() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 16/47] fftools/ffmpeg_filter: return error codes from ofilter_bind_ost() instead of aborting Anton Khirnov
` (32 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
Normal error handling does the job just as well.
---
fftools/ffmpeg_dec.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index f5f764b6fa..62c1baf287 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -1115,9 +1115,6 @@ int dec_open(InputStream *ist)
}
if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) {
- if (ret == AVERROR_EXPERIMENTAL)
- exit_program(1);
-
av_log(ist, AV_LOG_ERROR, "Error while opening decoder: %s\n",
av_err2str(ret));
return ret;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 16/47] fftools/ffmpeg_filter: return error codes from ofilter_bind_ost() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (13 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 15/47] fftools/ffmpeg_dec: drop redundant handling of AVERROR_EXPERIMENTAL Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 17/47] fftools/ffmpeg_filter: return error codes from init_input_filter() " Anton Khirnov
` (31 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_filter.c | 12 ++++++++----
fftools/ffmpeg_mux_init.c | 4 +++-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 62b56a8cd8..d7e16d034f 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -744,7 +744,7 @@ void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational t
*/
int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec);
-void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost);
+int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost);
/**
* Create a new filtergraph in the global filtergraph list.
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index d373d8c002..cdf5610620 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -624,7 +624,7 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
}
-void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
+int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
{
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
FilterGraph *fg = ofilter->graph;
@@ -699,15 +699,17 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
for (int i = 0; i < fg->nb_outputs; i++)
if (!fg->outputs[i]->ost)
- return;
+ return 0;
ret = configure_filtergraph(fg);
if (ret < 0) {
av_log(fg, AV_LOG_ERROR, "Error configuring filter graph: %s\n",
av_err2str(ret));
- exit_program(1);
+ return ret;
}
}
+
+ return 0;
}
static InputFilter *ifilter_alloc(FilterGraph *fg)
@@ -899,7 +901,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
if (ret < 0)
return ret;
- ofilter_bind_ost(fg->outputs[0], ost);
+ ret = ofilter_bind_ost(fg->outputs[0], ost);
+ if (ret < 0)
+ return ret;
return 0;
}
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index cc5ec68040..359a5149d4 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1393,7 +1393,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
(type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
if (ofilter) {
ost->filter = ofilter;
- ofilter_bind_ost(ofilter, ost);
+ ret = ofilter_bind_ost(ofilter, ost);
+ if (ret < 0)
+ return ret;
} else {
ret = init_simple_filtergraph(ost->ist, ost, filters);
if (ret < 0) {
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 17/47] fftools/ffmpeg_filter: return error codes from init_input_filter() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (14 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 16/47] fftools/ffmpeg_filter: return error codes from ofilter_bind_ost() instead of aborting Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 18/47] fftools/ffmpeg_filter: replace remaining exit_program() with error codes Anton Khirnov
` (30 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_filter.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index cdf5610620..79e034d248 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -908,7 +908,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
return 0;
}
-static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
+static int init_input_filter(FilterGraph *fg, InputFilter *ifilter)
{
FilterGraphPriv *fgp = fgp_from_fg(fg);
InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
@@ -920,7 +920,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {
av_log(fg, AV_LOG_FATAL, "Only video and audio filters supported "
"currently.\n");
- exit_program(1);
+ return AVERROR(ENOSYS);
}
if (ifp->linklabel) {
@@ -932,7 +932,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
if (file_idx < 0 || file_idx >= nb_input_files) {
av_log(fg, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n",
file_idx, fgp->graph_desc);
- exit_program(1);
+ return AVERROR(EINVAL);
}
s = input_files[file_idx]->ctx;
@@ -950,7 +950,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
if (!st) {
av_log(fg, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "
"matches no streams.\n", p, fgp->graph_desc);
- exit_program(1);
+ return AVERROR(EINVAL);
}
ist = input_files[file_idx]->streams[st->index];
} else {
@@ -958,7 +958,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
if (!ist) {
av_log(fg, AV_LOG_FATAL, "Cannot find a matching stream for "
"unlabeled input pad %s\n", ifilter->name);
- exit_program(1);
+ return AVERROR(EINVAL);
}
}
av_assert0(ist);
@@ -968,15 +968,20 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter)
av_log(fg, AV_LOG_ERROR,
"Error binding an input stream to complex filtergraph input %s.\n",
ifilter->name);
- exit_program(1);
+ return ret;
}
+
+ return 0;
}
int init_complex_filtergraph(FilterGraph *fg)
{
// bind filtergraph inputs to input streams
- for (int i = 0; i < fg->nb_inputs; i++)
- init_input_filter(fg, fg->inputs[i]);
+ for (int i = 0; i < fg->nb_inputs; i++) {
+ int ret = init_input_filter(fg, fg->inputs[i]);
+ if (ret < 0)
+ return ret;
+ }
return 0;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 18/47] fftools/ffmpeg_filter: replace remaining exit_program() with error codes
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (15 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 17/47] fftools/ffmpeg_filter: return error codes from init_input_filter() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 19/47] fftools/ffmpeg_filter: return error codes from choose_pix_fmts() instead of aborting Anton Khirnov
` (29 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_filter.c | 15 ++++++++++-----
fftools/ffmpeg_opt.c | 4 +++-
3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index d7e16d034f..043eb5e6ec 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -717,7 +717,7 @@ const AVCodec *find_codec_or_die(void *logctx, const char *name,
enum AVMediaType type, int encoder);
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
-void check_filter_outputs(void);
+int check_filter_outputs(void);
int filtergraph_is_simple(const FilterGraph *fg);
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
char *graph_desc);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 79e034d248..ed0df9f320 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1246,7 +1246,7 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter,
{
if (!ofilter->ost) {
av_log(fg, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name);
- exit_program(1);
+ return AVERROR(EINVAL);
}
switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) {
@@ -1256,7 +1256,7 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter,
}
}
-void check_filter_outputs(void)
+int check_filter_outputs(void)
{
int i;
for (i = 0; i < nb_filtergraphs; i++) {
@@ -1266,10 +1266,12 @@ void check_filter_outputs(void)
if (!output->ost) {
av_log(filtergraphs[i], AV_LOG_FATAL,
"Filter %s has an unconnected output\n", output->name);
- exit_program(1);
+ return AVERROR(EINVAL);
}
}
}
+
+ return 0;
}
static void sub2video_prepare(InputFilterPriv *ifp)
@@ -1570,8 +1572,11 @@ static int configure_filtergraph(FilterGraph *fg)
}
avfilter_inout_free(&inputs);
- for (cur = outputs, i = 0; cur; cur = cur->next, i++)
- configure_output_filter(fg, fg->outputs[i], cur);
+ for (cur = outputs, i = 0; cur; cur = cur->next, i++) {
+ ret = configure_output_filter(fg, fg->outputs[i], cur);
+ if (ret < 0)
+ return ret;
+ }
avfilter_inout_free(&outputs);
if (fgp->disable_conversions)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 300f042660..44bf263621 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1301,7 +1301,9 @@ int ffmpeg_parse_options(int argc, char **argv)
apply_sync_offsets();
- check_filter_outputs();
+ ret = check_filter_outputs();
+ if (ret < 0)
+ goto fail;
fail:
uninit_parse_context(&octx);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 19/47] fftools/ffmpeg_filter: return error codes from choose_pix_fmts() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (16 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 18/47] fftools/ffmpeg_filter: replace remaining exit_program() with error codes Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 20/47] fftools/ffmpeg_filter: return error codes from fg_create() " Anton Khirnov
` (28 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_filter.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ed0df9f320..2a3204121a 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -270,20 +270,20 @@ static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts,
ifp->sub2video.initialize = 0;
}
-/* May return NULL (no pixel format found), a static string or a string
- * backed by the bprint. Nothing has been written to the AVBPrint in case
+/* *dst may return be set to NULL (no pixel format found), a static string or a
+ * string backed by the bprint. Nothing has been written to the AVBPrint in case
* NULL is returned. The AVBPrint provided should be clean. */
-static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
+static int choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint,
+ const char **dst)
{
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
OutputStream *ost = ofilter->ost;
- if (ost->keep_pix_fmt) {
- return ofp->format == AV_PIX_FMT_NONE ? NULL :
+ *dst = NULL;
+
+ if (ost->keep_pix_fmt || ofp->format != AV_PIX_FMT_NONE) {
+ *dst = ofp->format == AV_PIX_FMT_NONE ? NULL :
av_get_pix_fmt_name(ofp->format);
- }
- if (ofp->format != AV_PIX_FMT_NONE) {
- return av_get_pix_fmt_name(ofp->format);
} else if (ofp->formats) {
const enum AVPixelFormat *p = ofp->formats;
@@ -292,10 +292,12 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
av_bprintf(bprint, "%s%c", name, p[1] == AV_PIX_FMT_NONE ? '\0' : '|');
}
if (!av_bprint_is_complete(bprint))
- report_and_exit(AVERROR(ENOMEM));
- return bprint->str;
- } else
- return NULL;
+ return AVERROR(ENOMEM);
+
+ *dst = bprint->str;
+ }
+
+ return 0;
}
/* Define a function for appending a list of allowed formats
@@ -1103,7 +1105,11 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
}
av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
- if ((pix_fmts = choose_pix_fmts(ofilter, &bprint))) {
+ ret = choose_pix_fmts(ofilter, &bprint, &pix_fmts);
+ if (ret < 0)
+ return ret;
+
+ if (pix_fmts) {
AVFilterContext *filter;
ret = avfilter_graph_create_filter(&filter,
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 20/47] fftools/ffmpeg_filter: return error codes from fg_create() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (17 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 19/47] fftools/ffmpeg_filter: return error codes from choose_pix_fmts() instead of aborting Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 21/47] fftools/ffmpeg_filter: return error codes from set_channel_layout() " Anton Khirnov
` (27 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_filter.c | 38 ++++++++++++++++++++++----------------
fftools/ffmpeg_opt.c | 8 ++------
3 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 043eb5e6ec..ba73dcffdc 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -752,7 +752,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost);
* @param graph_desc Graph description; an av_malloc()ed string, filtergraph
* takes ownership of it.
*/
-FilterGraph *fg_create(char *graph_desc);
+int fg_create(FilterGraph **pfg, char *graph_desc);
void fg_free(FilterGraph **pfg);
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 2a3204121a..485154a448 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -538,16 +538,11 @@ static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
AVFilterContext *ctx = inout->filter_ctx;
AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads;
int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs;
- char *res;
if (nb_pads > 1)
- res = av_strdup(ctx->filter->name);
- else
- res = av_asprintf("%s:%s", ctx->filter->name,
- avfilter_pad_get_name(pads, inout->pad_idx));
- if (!res)
- report_and_exit(AVERROR(ENOMEM));
- return res;
+ return av_strdup(ctx->filter->name);
+ return av_asprintf("%s:%s", ctx->filter->name,
+ avfilter_pad_get_name(pads, inout->pad_idx));
}
static OutputFilter *ofilter_alloc(FilterGraph *fg)
@@ -799,7 +794,7 @@ static const AVClass fg_class = {
.category = AV_CLASS_CATEGORY_FILTER,
};
-FilterGraph *fg_create(char *graph_desc)
+int fg_create(FilterGraph **pfg, char *graph_desc)
{
FilterGraphPriv *fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs);
FilterGraph *fg = &fgp->fg;
@@ -808,6 +803,9 @@ FilterGraph *fg_create(char *graph_desc)
AVFilterGraph *graph;
int ret = 0;
+ if (pfg)
+ *pfg = fg;
+
fg->class = &fg_class;
fg->index = nb_filtergraphs - 1;
fgp->graph_desc = graph_desc;
@@ -817,13 +815,13 @@ FilterGraph *fg_create(char *graph_desc)
fgp->frame = av_frame_alloc();
if (!fgp->frame)
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
/* this graph is only used for determining the kinds of inputs
* and outputs we have, and is discarded on exit from this function */
graph = avfilter_graph_alloc();
if (!graph)
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);;
graph->nb_threads = 1;
ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, NULL);
@@ -840,6 +838,10 @@ FilterGraph *fg_create(char *graph_desc)
ifp->type = avfilter_pad_get_type(cur->filter_ctx->input_pads,
cur->pad_idx);
ifilter->name = describe_filter_link(fg, cur, 1);
+ if (!ifilter->name) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
}
for (AVFilterInOut *cur = outputs; cur; cur = cur->next) {
@@ -851,6 +853,10 @@ FilterGraph *fg_create(char *graph_desc)
ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads,
cur->pad_idx);
ofilter->name = describe_filter_link(fg, cur, 0);
+ if (!ofilter->name) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
}
if (!fg->nb_outputs) {
@@ -865,9 +871,9 @@ fail:
avfilter_graph_free(&graph);
if (ret < 0)
- report_and_exit(ret);
+ return ret;
- return fg;
+ return 0;
}
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
@@ -877,9 +883,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
FilterGraphPriv *fgp;
int ret;
- fg = fg_create(graph_desc);
- if (!fg)
- report_and_exit(AVERROR(ENOMEM));
+ ret = fg_create(&fg, graph_desc);
+ if (ret < 0)
+ return ret;
fgp = fgp_from_fg(fg);
fgp->is_simple = 1;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 44bf263621..25a1083366 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1112,9 +1112,7 @@ static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
if (!graph_desc)
return AVERROR(ENOMEM);
- fg_create(graph_desc);
-
- return 0;
+ return fg_create(NULL, graph_desc);
}
static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
@@ -1123,9 +1121,7 @@ static int opt_filter_complex_script(void *optctx, const char *opt, const char *
if (!graph_desc)
return AVERROR(EINVAL);
- fg_create(graph_desc);
-
- return 0;
+ return fg_create(NULL, graph_desc);
}
void show_help_default(const char *opt, const char *arg)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 21/47] fftools/ffmpeg_filter: return error codes from set_channel_layout() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (18 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 20/47] fftools/ffmpeg_filter: return error codes from fg_create() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 22/47] fftools/ffmpeg_filter: replace remaining report_and_exit() with error codes Anton Khirnov
` (26 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_filter.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 485154a448..470d7b1f02 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -583,7 +583,7 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist)
return 0;
}
-static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
+static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
{
const AVCodec *c = ost->enc_ctx->codec;
int i, err;
@@ -592,8 +592,8 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
/* 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)
- report_and_exit(AVERROR(ENOMEM));
- return;
+ return err;
+ return 0;
}
/* Requested layout is of order UNSPEC */
@@ -601,7 +601,7 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
/* 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;
+ return 0;
}
/* Encoder has a list of supported layouts. Pick the first layout in it with the
same amount of channels as the requested layout */
@@ -613,12 +613,14 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
/* Use it if one is found */
err = av_channel_layout_copy(&f->ch_layout, &c->ch_layouts[i]);
if (err < 0)
- report_and_exit(AVERROR(ENOMEM));
- return;
+ return err;
+ return 0;
}
/* 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);
+
+ return 0;
}
int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
@@ -682,7 +684,9 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
ofp->sample_rates = c->supported_samplerates;
}
if (ost->enc_ctx->ch_layout.nb_channels) {
- set_channel_layout(ofp, ost);
+ int ret = set_channel_layout(ofp, ost);
+ if (ret < 0)
+ return ret;
} else if (c->ch_layouts) {
ofp->ch_layouts = c->ch_layouts;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 22/47] fftools/ffmpeg_filter: replace remaining report_and_exit() with error codes
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (19 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 21/47] fftools/ffmpeg_filter: return error codes from set_channel_layout() " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 23/47] fftools/cmdutils: return error codes from setup_find_stream_info_opts() instead of aborting Anton Khirnov
` (25 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_filter.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 470d7b1f02..26aff9c328 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -723,14 +723,14 @@ static InputFilter *ifilter_alloc(FilterGraph *fg)
ifp->frame = av_frame_alloc();
if (!ifp->frame)
- report_and_exit(AVERROR(ENOMEM));
+ return NULL;
ifp->format = -1;
ifp->fallback.format = -1;
ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
if (!ifp->frame_queue)
- report_and_exit(AVERROR(ENOMEM));
+ return NULL;
return ifilter;
}
@@ -1781,7 +1781,7 @@ int reap_filters(FilterGraph *fg, int flush)
fd = frame_data(filtered_frame);
if (!fd) {
av_frame_unref(filtered_frame);
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
}
// only use bits_per_raw_sample passed through from the decoder
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 23/47] fftools/cmdutils: return error codes from setup_find_stream_info_opts() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (20 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 22/47] fftools/ffmpeg_filter: replace remaining report_and_exit() with error codes Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 24/47] fftools/ffmpeg_opt: reimplement -streamid using a dictionary Anton Khirnov
` (24 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.c | 30 +++++++++++++++++++++---------
fftools/cmdutils.h | 8 +++-----
fftools/ffmpeg_demux.c | 6 +++++-
fftools/ffplay.c | 6 +++++-
fftools/ffprobe.c | 6 +++++-
5 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 9ec00add30..e2fa08c116 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -645,8 +645,8 @@ static void add_opt(OptionParseContext *octx, const OptionDef *opt,
g->opts[g->nb_opts - 1].val = val;
}
-static void init_parse_context(OptionParseContext *octx,
- const OptionGroupDef *groups, int nb_groups)
+static int init_parse_context(OptionParseContext *octx,
+ const OptionGroupDef *groups, int nb_groups)
{
static const OptionGroupDef global_group = { "global" };
int i;
@@ -656,13 +656,15 @@ static void init_parse_context(OptionParseContext *octx,
octx->nb_groups = nb_groups;
octx->groups = av_calloc(octx->nb_groups, sizeof(*octx->groups));
if (!octx->groups)
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
for (i = 0; i < octx->nb_groups; i++)
octx->groups[i].group_def = &groups[i];
octx->global_opts.group_def = &global_group;
octx->global_opts.arg = "";
+
+ return 0;
}
void uninit_parse_context(OptionParseContext *octx)
@@ -694,13 +696,17 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[],
const OptionDef *options,
const OptionGroupDef *groups, int nb_groups)
{
+ int ret;
int optindex = 1;
int dashdash = -2;
/* perform system-dependent conversions for arguments list */
prepare_app_arguments(&argc, &argv);
- init_parse_context(octx, groups, nb_groups);
+ ret = init_parse_context(octx, groups, nb_groups);
+ if (ret < 0)
+ return ret;
+
av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
while (optindex < argc) {
@@ -950,21 +956,27 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
return ret;
}
-AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
- AVDictionary *codec_opts)
+int setup_find_stream_info_opts(AVFormatContext *s,
+ AVDictionary *codec_opts,
+ AVDictionary ***dst)
{
int i;
AVDictionary **opts;
+ *dst = NULL;
+
if (!s->nb_streams)
- return NULL;
+ return 0;
+
opts = av_calloc(s->nb_streams, sizeof(*opts));
if (!opts)
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
+
for (i = 0; i < s->nb_streams; i++)
opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
s, s->streams[i], NULL);
- return opts;
+ *dst = opts;
+ return 0;
}
void *grow_array(void *array, int elem_size, int *size, int new_size)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 0115940225..f54f3322ef 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -364,12 +364,10 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
* contained in s.
* Each dictionary will contain the options from codec_opts which can
* be applied to the corresponding stream codec context.
- *
- * @return pointer to the created array of dictionaries.
- * Calls exit() on failure.
*/
-AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
- AVDictionary *codec_opts);
+int setup_find_stream_info_opts(AVFormatContext *s,
+ AVDictionary *codec_opts,
+ AVDictionary ***dst);
/**
* Print an error message to stderr, indicating filename and a human
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 9e7f13a2b4..a43c39b843 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1482,9 +1482,13 @@ int ifile_open(const OptionsContext *o, const char *filename)
choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE);
if (o->find_stream_info) {
- AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts);
+ AVDictionary **opts;
int orig_nb_streams = ic->nb_streams;
+ ret = setup_find_stream_info_opts(ic, o->g->codec_opts, &opts);
+ if (ret < 0)
+ return ret;
+
/* If not enough info to get the stream parameters, we decode the
first frames to get it. (used in mpeg case for example) */
ret = avformat_find_stream_info(ic, opts);
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 51cde0d208..99700dc6f2 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -2773,9 +2773,13 @@ static int read_thread(void *arg)
av_format_inject_global_side_data(ic);
if (find_stream_info) {
- AVDictionary **opts = setup_find_stream_info_opts(ic, codec_opts);
+ AVDictionary **opts;
int orig_nb_streams = ic->nb_streams;
+ err = setup_find_stream_info_opts(ic, codec_opts, &opts);
+ if (err < 0)
+ report_and_exit(err);
+
err = avformat_find_stream_info(ic, opts);
for (i = 0; i < orig_nb_streams; i++)
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 1ff76ce809..91a3be660b 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3372,9 +3372,13 @@ static int open_input_file(InputFile *ifile, const char *filename,
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);
+ AVDictionary **opts;
int orig_nb_streams = fmt_ctx->nb_streams;
+ err = setup_find_stream_info_opts(fmt_ctx, codec_opts, &opts);
+ if (err < 0)
+ report_and_exit(err);
+
err = avformat_find_stream_info(fmt_ctx, opts);
for (i = 0; i < orig_nb_streams; i++)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 24/47] fftools/ffmpeg_opt: reimplement -streamid using a dictionary
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (21 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 23/47] fftools/cmdutils: return error codes from setup_find_stream_info_opts() instead of aborting Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 25/47] fftools/cmdutils: drop unused ALLOC_ARRAY_ELEM() Anton Khirnov
` (23 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
This does not require an arbitrary limit on the number of streams.
Also, return error codes from opt_streamid() instead of aborting.
---
fftools/ffmpeg.h | 7 ++-----
fftools/ffmpeg_mux_init.c | 18 +++++++++++++++---
fftools/ffmpeg_opt.c | 12 +++++-------
3 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ba73dcffdc..8a94cd7861 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -73,8 +73,6 @@ enum EncTimeBase {
ENC_TIME_BASE_FILTER = -2,
};
-#define MAX_STREAMS 1024 /* arbitrary sanity check value */
-
enum HWAccelID {
HWACCEL_NONE = 0,
HWACCEL_AUTO,
@@ -184,9 +182,8 @@ typedef struct OptionsContext {
int subtitle_disable;
int data_disable;
- /* indexed by output file stream index */
- int *streamid_map;
- int nb_streamid_map;
+ // keys are stream indices
+ AVDictionary *streamid;
SpecifierOpt *metadata;
int nb_metadata;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 359a5149d4..ac4ef328a6 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1111,12 +1111,24 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
if (!st)
return AVERROR(ENOMEM);
- if (oc->nb_streams - 1 < o->nb_streamid_map)
- st->id = o->streamid_map[oc->nb_streams - 1];
-
ms = mux_stream_alloc(mux, type);
ost = &ms->ost;
+ if (o->streamid) {
+ AVDictionaryEntry *e;
+ char idx[16], *p;
+ snprintf(idx, sizeof(idx), "%d", ost->index);
+
+ e = av_dict_get(o->streamid, idx, NULL, 0);
+ if (e) {
+ st->id = strtol(e->value, &p, 0);
+ if (!e->value[0] || *p) {
+ av_log(ost, AV_LOG_FATAL, "Invalid stream id: %s\n", e->value);
+ return AVERROR(EINVAL);
+ }
+ }
+ }
+
ost->par_in = avcodec_parameters_alloc();
if (!ost->par_in)
return AVERROR(ENOMEM);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 25a1083366..7002986369 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -128,8 +128,9 @@ static void uninit_options(OptionsContext *o)
#if FFMPEG_OPT_MAP_CHANNEL
av_freep(&o->audio_channel_maps);
#endif
- av_freep(&o->streamid_map);
av_freep(&o->attachments);
+
+ av_dict_free(&o->streamid);
}
static void init_options(OptionsContext *o)
@@ -727,7 +728,6 @@ char *file_read(const char *filename)
static int opt_streamid(void *optctx, const char *opt, const char *arg)
{
OptionsContext *o = optctx;
- int idx;
char *p;
char idx_str[16];
@@ -737,13 +737,11 @@ static int opt_streamid(void *optctx, const char *opt, const char *arg)
av_log(NULL, AV_LOG_FATAL,
"Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
arg, opt);
- exit_program(1);
+ return AVERROR(EINVAL);
}
*p++ = '\0';
- idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
- o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
- o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
- return 0;
+
+ return av_dict_set(&o->streamid, idx_str, p, 0);
}
static int init_complex_filters(void)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 25/47] fftools/cmdutils: drop unused ALLOC_ARRAY_ELEM()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (22 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 24/47] fftools/ffmpeg_opt: reimplement -streamid using a dictionary Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 26/47] fftools/cmdutils: add error handling to allocate_array_elem() Anton Khirnov
` (22 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.h | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index f54f3322ef..decd23040f 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -443,9 +443,6 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
#define GROW_ARRAY(array, nb_elems)\
array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
-#define ALLOC_ARRAY_ELEM(array, nb_elems)\
- allocate_array_elem(&array, sizeof(*array[0]), &nb_elems)
-
#define GET_PIX_FMT_NAME(pix_fmt)\
const char *name = av_get_pix_fmt_name(pix_fmt);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 26/47] fftools/cmdutils: add error handling to allocate_array_elem()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (23 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 25/47] fftools/cmdutils: drop unused ALLOC_ARRAY_ELEM() Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 27/47] fftools/cmdutils: add error handling to grow_array() Anton Khirnov
` (21 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.c | 2 +-
fftools/cmdutils.h | 3 +--
fftools/ffmpeg_demux.c | 16 ++++++++++++++--
fftools/ffmpeg_filter.c | 28 +++++++++++++++++++++-------
fftools/ffmpeg_mux_init.c | 16 ++++++++++++++--
5 files changed, 51 insertions(+), 14 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index e2fa08c116..6c627ee815 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1002,7 +1002,7 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
if (!(new_elem = av_mallocz(elem_size)) ||
av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
- report_and_exit(AVERROR(ENOMEM));
+ return NULL;
return new_elem;
}
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index decd23040f..6b9d7f80ae 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -430,13 +430,12 @@ void *grow_array(void *array, int elem_size, int *size, int new_size);
* Atomically add a new element to an array of pointers, i.e. allocate
* a new entry, reallocate the array of pointers and make the new last
* member of this array point to the newly allocated buffer.
- * Calls exit() on failure.
*
* @param array array of pointers to reallocate
* @param elem_size size of the new element to allocate
* @param nb_elems pointer to the number of elements of the array array;
* *nb_elems will be incremented by one by this function.
- * @return pointer to the newly allocated entry
+ * @return pointer to the newly allocated entry or NULL on failure
*/
void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index a43c39b843..72b94ea44f 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1018,8 +1018,11 @@ static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st)
{
const char *type_str = av_get_media_type_string(st->codecpar->codec_type);
InputFile *f = &d->f;
- DemuxStream *ds = allocate_array_elem(&f->streams, sizeof(*ds),
- &f->nb_streams);
+ DemuxStream *ds;
+
+ ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams);
+ if (!ds)
+ return NULL;
ds->ist.st = st;
ds->ist.file_index = f->index;
@@ -1051,6 +1054,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
int ret;
ds = demux_stream_alloc(d, st);
+ if (!ds)
+ return AVERROR(ENOMEM);
+
ist = &ds->ist;
ist->discard = 1;
@@ -1328,6 +1334,9 @@ static Demuxer *demux_alloc(void)
{
Demuxer *d = allocate_array_elem(&input_files, sizeof(*d), &nb_input_files);
+ if (!d)
+ return NULL;
+
d->f.class = &input_file_class;
d->f.index = nb_input_files - 1;
@@ -1358,6 +1367,9 @@ int ifile_open(const OptionsContext *o, const char *filename)
int64_t recording_time = o->recording_time;
d = demux_alloc();
+ if (!d)
+ return AVERROR(ENOMEM);
+
f = &d->f;
if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 26aff9c328..880d883064 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -550,8 +550,10 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg)
OutputFilterPriv *ofp;
OutputFilter *ofilter;
- ofp = allocate_array_elem(&fg->outputs, sizeof(*ofp),
- &fg->nb_outputs);
+ ofp = allocate_array_elem(&fg->outputs, sizeof(*ofp), &fg->nb_outputs);
+ if (!ofp)
+ return NULL;
+
ofilter = &ofp->ofilter;
ofilter->graph = fg;
ofp->format = -1;
@@ -715,10 +717,14 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost)
static InputFilter *ifilter_alloc(FilterGraph *fg)
{
- InputFilterPriv *ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp),
- &fg->nb_inputs);
- InputFilter *ifilter = &ifp->ifilter;
+ InputFilterPriv *ifp;
+ InputFilter *ifilter;
+ ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp), &fg->nb_inputs);
+ if (!ifp)
+ return NULL;
+
+ ifilter = &ifp->ifilter;
ifilter->graph = fg;
ifp->frame = av_frame_alloc();
@@ -800,13 +806,18 @@ static const AVClass fg_class = {
int fg_create(FilterGraph **pfg, char *graph_desc)
{
- FilterGraphPriv *fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs);
- FilterGraph *fg = &fgp->fg;
+ FilterGraphPriv *fgp;
+ FilterGraph *fg;
AVFilterInOut *inputs, *outputs;
AVFilterGraph *graph;
int ret = 0;
+ fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs);
+ if (!fgp)
+ return AVERROR(ENOMEM);
+ fg = &fgp->fg;
+
if (pfg)
*pfg = fg;
@@ -851,6 +862,9 @@ int fg_create(FilterGraph **pfg, char *graph_desc)
for (AVFilterInOut *cur = outputs; cur; cur = cur->next) {
OutputFilter *const ofilter = ofilter_alloc(fg);
+ if (!ofilter)
+ goto fail;
+
ofilter->linklabel = cur->name;
cur->name = NULL;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index ac4ef328a6..e714d6cc70 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -414,8 +414,11 @@ static const AVClass output_stream_class = {
static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type)
{
const char *type_str = av_get_media_type_string(type);
- MuxStream *ms = allocate_array_elem(&mux->of.streams, sizeof(*ms),
- &mux->of.nb_streams);
+ MuxStream *ms;
+
+ ms = allocate_array_elem(&mux->of.streams, sizeof(*ms), &mux->of.nb_streams);
+ if (!ms)
+ return NULL;
ms->ost.file_index = mux->of.index;
ms->ost.index = mux->of.nb_streams - 1;
@@ -1112,6 +1115,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
return AVERROR(ENOMEM);
ms = mux_stream_alloc(mux, type);
+ if (!ms)
+ return AVERROR(ENOMEM);
+
ost = &ms->ost;
if (o->streamid) {
@@ -2568,6 +2574,9 @@ static Muxer *mux_alloc(void)
{
Muxer *mux = allocate_array_elem(&output_files, sizeof(*mux), &nb_output_files);
+ if (!mux)
+ return NULL;
+
mux->of.class = &output_file_class;
mux->of.index = nb_output_files - 1;
@@ -2587,6 +2596,9 @@ int of_open(const OptionsContext *o, const char *filename)
int64_t stop_time = o->stop_time;
mux = mux_alloc();
+ if (!mux)
+ return AVERROR(ENOMEM);
+
of = &mux->of;
if (stop_time != INT64_MAX && recording_time != INT64_MAX) {
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 27/47] fftools/cmdutils: add error handling to grow_array()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (24 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 26/47] fftools/cmdutils: add error handling to allocate_array_elem() Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 28/47] fftools/cmdutils: add error handling to GROW_ARRAY() Anton Khirnov
` (20 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.c | 19 ++++++++++++-------
fftools/cmdutils.h | 14 +++++++++-----
2 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 6c627ee815..63b29c7a3a 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -262,6 +262,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
(uint8_t *)optctx + po->u.off : po->u.dst_ptr;
int *dstcount;
+ int ret;
if (po->flags & OPT_SPEC) {
SpecifierOpt **so = dst;
@@ -269,7 +270,10 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
char *str;
dstcount = (int *)(so + 1);
- *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
+ ret = grow_array((void**)so, sizeof(**so), dstcount, *dstcount + 1);
+ if (ret < 0)
+ return ret;
+
str = av_strdup(p ? p + 1 : "");
if (!str)
return AVERROR(ENOMEM);
@@ -979,21 +983,22 @@ int setup_find_stream_info_opts(AVFormatContext *s,
return 0;
}
-void *grow_array(void *array, int elem_size, int *size, int new_size)
+int grow_array(void **array, int elem_size, int *size, int new_size)
{
if (new_size >= INT_MAX / elem_size) {
av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
- exit_program(1);
+ return AVERROR(ERANGE);
}
if (*size < new_size) {
- uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
+ uint8_t *tmp = av_realloc_array(*array, new_size, elem_size);
if (!tmp)
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
*size = new_size;
- return tmp;
+ *array = tmp;
+ return 0;
}
- return array;
+ return 0;
}
void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 6b9d7f80ae..0dfe8b313c 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -416,15 +416,15 @@ FILE *get_preset_file(char *filename, size_t filename_size,
/**
* Realloc array to hold new_size elements of elem_size.
- * Calls exit() on failure.
*
- * @param array array to reallocate
+ * @param array pointer to the array to reallocate, will be updated
+ * with a new pointer on success
* @param elem_size size in bytes of each element
* @param size new element count will be written here
* @param new_size number of elements to place in reallocated array
- * @return reallocated array
+ * @return a non-negative number on success, a negative error code on failure
*/
-void *grow_array(void *array, int elem_size, int *size, int new_size);
+int grow_array(void **array, int elem_size, int *size, int new_size);
/**
* Atomically add a new element to an array of pointers, i.e. allocate
@@ -440,7 +440,11 @@ void *grow_array(void *array, int elem_size, int *size, int new_size);
void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
#define GROW_ARRAY(array, nb_elems)\
- array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
+do { \
+ int _ret = grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1); \
+ if (_ret < 0) \
+ report_and_exit(_ret); \
+} while (0)
#define GET_PIX_FMT_NAME(pix_fmt)\
const char *name = av_get_pix_fmt_name(pix_fmt);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 28/47] fftools/cmdutils: add error handling to GROW_ARRAY()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (25 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 27/47] fftools/cmdutils: add error handling to grow_array() Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 29/47] fftools/ffmpeg: return errors from find_codec_or_die() instead of aborting Anton Khirnov
` (19 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.c | 44 ++++++++++++++++++++++++++++++---------
fftools/cmdutils.h | 6 +-----
fftools/ffmpeg_demux.c | 10 +++++++--
fftools/ffmpeg_mux_init.c | 15 ++++++++++---
fftools/ffmpeg_opt.c | 24 ++++++++++++++++-----
fftools/ffplay.c | 5 ++++-
6 files changed, 78 insertions(+), 26 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 63b29c7a3a..fb35245f0a 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -609,13 +609,17 @@ static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
* @param group_idx which group definition should this group belong to
* @param arg argument of the group delimiting option
*/
-static void finish_group(OptionParseContext *octx, int group_idx,
- const char *arg)
+static int finish_group(OptionParseContext *octx, int group_idx,
+ const char *arg)
{
OptionGroupList *l = &octx->groups[group_idx];
OptionGroup *g;
+ int ret;
+
+ ret = GROW_ARRAY(l->groups, l->nb_groups);
+ if (ret < 0)
+ return ret;
- GROW_ARRAY(l->groups, l->nb_groups);
g = &l->groups[l->nb_groups - 1];
*g = octx->cur_group;
@@ -632,21 +636,29 @@ static void finish_group(OptionParseContext *octx, int group_idx,
swr_opts = NULL;
memset(&octx->cur_group, 0, sizeof(octx->cur_group));
+
+ return ret;
}
/*
* Add an option instance to currently parsed group.
*/
-static void add_opt(OptionParseContext *octx, const OptionDef *opt,
- const char *key, const char *val)
+static int add_opt(OptionParseContext *octx, const OptionDef *opt,
+ const char *key, const char *val)
{
int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
+ int ret;
+
+ ret = GROW_ARRAY(g->opts, g->nb_opts);
+ if (ret < 0)
+ return ret;
- GROW_ARRAY(g->opts, g->nb_opts);
g->opts[g->nb_opts - 1].opt = opt;
g->opts[g->nb_opts - 1].key = key;
g->opts[g->nb_opts - 1].val = val;
+
+ return 0;
}
static int init_parse_context(OptionParseContext *octx,
@@ -726,7 +738,10 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[],
}
/* unnamed group separators, e.g. output filename */
if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
- finish_group(octx, 0, opt);
+ ret = finish_group(octx, 0, opt);
+ if (ret < 0)
+ return ret;
+
av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
continue;
}
@@ -744,7 +759,10 @@ do { \
/* named group separators, e.g. -i */
if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
GET_ARG(arg);
- finish_group(octx, ret, arg);
+ ret = finish_group(octx, ret, arg);
+ if (ret < 0)
+ return ret;
+
av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
groups[ret].name, arg);
continue;
@@ -762,7 +780,10 @@ do { \
arg = "1";
}
- add_opt(octx, po, opt, arg);
+ ret = add_opt(octx, po, opt, arg);
+ if (ret < 0)
+ return ret;
+
av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
"argument '%s'.\n", po->name, po->help, arg);
continue;
@@ -787,7 +808,10 @@ do { \
if (opt[0] == 'n' && opt[1] == 'o' &&
(po = find_option(options, opt + 2)) &&
po->name && po->flags & OPT_BOOL) {
- add_opt(octx, po, opt, "0");
+ ret = add_opt(octx, po, opt, "0");
+ if (ret < 0)
+ return ret;
+
av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
"argument 0.\n", po->name, po->help);
continue;
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 0dfe8b313c..69c2123804 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -440,11 +440,7 @@ int grow_array(void **array, int elem_size, int *size, int new_size);
void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
#define GROW_ARRAY(array, nb_elems)\
-do { \
- int _ret = grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1); \
- if (_ret < 0) \
- report_and_exit(_ret); \
-} while (0)
+ grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1)
#define GET_PIX_FMT_NAME(pix_fmt)\
const char *name = av_get_pix_fmt_name(pix_fmt);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 72b94ea44f..5a41db9b21 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -880,7 +880,10 @@ int ist_output_add(InputStream *ist, OutputStream *ost)
if (ret < 0)
return ret;
- GROW_ARRAY(ist->outputs, ist->nb_outputs);
+ ret = GROW_ARRAY(ist->outputs, ist->nb_outputs);
+ if (ret < 0)
+ return ret;
+
ist->outputs[ist->nb_outputs - 1] = ost;
return 0;
@@ -894,7 +897,10 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
if (ret < 0)
return ret;
- GROW_ARRAY(ist->filters, ist->nb_filters);
+ ret = GROW_ARRAY(ist->filters, ist->nb_filters);
+ if (ret < 0)
+ return ret;
+
ist->filters[ist->nb_filters - 1] = ifilter;
// initialize fallback parameters for filtering
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index e714d6cc70..cb943ac408 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -209,7 +209,9 @@ static int enc_stats_get_file(AVIOContext **io, const char *path)
return 0;
}
- GROW_ARRAY(enc_stats_files, nb_enc_stats_files);
+ ret = GROW_ARRAY(enc_stats_files, nb_enc_stats_files);
+ if (ret < 0)
+ return ret;
esf = &enc_stats_files[nb_enc_stats_files - 1];
@@ -321,7 +323,11 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
return ret;
if (val) {
- GROW_ARRAY(es->components, es->nb_components);
+ ret = GROW_ARRAY(es->components, es->nb_components);
+ if (ret < 0) {
+ av_freep(&val);
+ return ret;
+ }
c = &es->components[es->nb_components - 1];
c->type = ENC_STATS_LITERAL;
@@ -352,7 +358,10 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
}
next++;
- GROW_ARRAY(es->components, es->nb_components);
+ ret = GROW_ARRAY(es->components, es->nb_components);
+ if (ret < 0)
+ return ret;
+
c = &es->components[es->nb_components - 1];
for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) {
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 7002986369..eef6d5e749 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -361,6 +361,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
OptionsContext *o = optctx;
StreamMap *m = NULL;
int i, negative = 0, file_idx, disabled = 0;
+ int ret;
#if FFMPEG_OPT_MAP_SYNC
char *sync;
#endif
@@ -387,7 +388,11 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
if (map[0] == '[') {
/* this mapping refers to lavfi output */
const char *c = map + 1;
- GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
+
+ ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
+ if (ret < 0)
+ return ret;
+
m = &o->stream_maps[o->nb_stream_maps - 1];
m->linklabel = av_get_token(&c, "]");
if (!m->linklabel) {
@@ -421,7 +426,10 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
disabled = 1;
continue;
}
- GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
+ ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
+ if (ret < 0)
+ return ret;
+
m = &o->stream_maps[o->nb_stream_maps - 1];
m->file_index = file_idx;
@@ -450,7 +458,10 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
static int opt_attach(void *optctx, const char *opt, const char *arg)
{
OptionsContext *o = optctx;
- GROW_ARRAY(o->attachments, o->nb_attachments);
+ int ret = GROW_ARRAY(o->attachments, o->nb_attachments);
+ if (ret < 0)
+ return ret;
+
o->attachments[o->nb_attachments - 1] = arg;
return 0;
}
@@ -459,7 +470,7 @@ static int opt_attach(void *optctx, const char *opt, const char *arg)
static int opt_map_channel(void *optctx, const char *opt, const char *arg)
{
OptionsContext *o = optctx;
- int n;
+ int n, ret;
AVStream *st;
AudioChannelMap *m;
char *allow_unused;
@@ -474,7 +485,10 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg)
if (!mapchan)
return AVERROR(ENOMEM);
- GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
+ ret = GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
+ if (ret < 0)
+ return ret;
+
m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1];
/* muted channel syntax */
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 99700dc6f2..1f9757d607 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -388,7 +388,10 @@ static const struct TextureFormatEntry {
static int opt_add_vfilter(void *optctx, const char *opt, const char *arg)
{
- GROW_ARRAY(vfilters_list, nb_vfilters);
+ int ret = GROW_ARRAY(vfilters_list, nb_vfilters);
+ if (ret < 0)
+ return ret;
+
vfilters_list[nb_vfilters - 1] = arg;
return 0;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 29/47] fftools/ffmpeg: return errors from find_codec_or_die() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (26 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 28/47] fftools/cmdutils: add error handling to GROW_ARRAY() Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 30/47] fftools/ffmpeg_opt: replace exit_program() with returning error codes Anton Khirnov
` (18 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
Rename the function to just find_codec().
---
fftools/ffmpeg.h | 4 +--
fftools/ffmpeg_demux.c | 54 +++++++++++++++++++++++++++------------
fftools/ffmpeg_mux_init.c | 4 ++-
fftools/ffmpeg_opt.c | 13 ++++++----
4 files changed, 50 insertions(+), 25 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8a94cd7861..60dff87436 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -710,8 +710,8 @@ void assert_avoptions(AVDictionary *m);
int assert_file_overwrite(const char *filename);
char *file_read(const char *filename);
AVDictionary *strip_specifiers(const AVDictionary *dict);
-const AVCodec *find_codec_or_die(void *logctx, const char *name,
- enum AVMediaType type, int encoder);
+int find_codec(void *logctx, const char *name,
+ enum AVMediaType type, int encoder, const AVCodec **codec);
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
int check_filter_outputs(void);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 5a41db9b21..a41b59ceb8 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -911,19 +911,22 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
return 0;
}
-static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
- enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
+static int choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
+ enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
+ const AVCodec **pcodec)
{
char *codec_name = NULL;
MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
if (codec_name) {
- const AVCodec *codec = find_codec_or_die(NULL, codec_name, st->codecpar->codec_type, 0);
- st->codecpar->codec_id = codec->id;
- if (recast_media && st->codecpar->codec_type != codec->type)
- st->codecpar->codec_type = codec->type;
- return codec;
+ int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
+ if (ret < 0)
+ return ret;
+ st->codecpar->codec_id = (*pcodec)->id;
+ if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
+ st->codecpar->codec_type = (*pcodec)->type;
+ return 0;
} else {
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
hwaccel_id == HWACCEL_GENERIC &&
@@ -942,13 +945,15 @@ static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s
if (config->device_type == hwaccel_device_type) {
av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
c->name, av_hwdevice_get_type_name(hwaccel_device_type));
- return c;
+ *pcodec = c;
+ return 0;
}
}
}
}
- return avcodec_find_decoder(st->codecpar->codec_id);
+ *pcodec = avcodec_find_decoder(st->codecpar->codec_id);
+ return 0;
}
}
@@ -1166,7 +1171,11 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
}
}
- ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type);
+ ret = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type,
+ &ist->dec);
+ if (ret < 0)
+ return ret;
+
ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
ist->reinit_filters = -1;
@@ -1357,7 +1366,7 @@ int ifile_open(const OptionsContext *o, const char *filename)
InputFile *f;
AVFormatContext *ic;
const AVInputFormat *file_iformat = NULL;
- int err, i, ret;
+ int err, i, ret = 0;
int64_t timestamp;
AVDictionary *unused_opts = NULL;
const AVDictionaryEntry *e = NULL;
@@ -1455,13 +1464,19 @@ int ifile_open(const OptionsContext *o, const char *filename)
MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
if (video_codec_name)
- ic->video_codec = find_codec_or_die(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
+ ret = err_merge(ret, find_codec(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0,
+ &ic->video_codec));
if (audio_codec_name)
- ic->audio_codec = find_codec_or_die(NULL, audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
+ ret = err_merge(ret, find_codec(NULL, audio_codec_name , AVMEDIA_TYPE_AUDIO , 0,
+ &ic->audio_codec));
if (subtitle_codec_name)
- ic->subtitle_codec = find_codec_or_die(NULL, subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
+ ret = err_merge(ret, find_codec(NULL, subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0,
+ &ic->subtitle_codec));
if (data_codec_name)
- ic->data_codec = find_codec_or_die(NULL, data_codec_name , AVMEDIA_TYPE_DATA , 0);
+ ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
+ &ic->data_codec));
+ if (ret < 0)
+ return ret;
ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
@@ -1496,8 +1511,13 @@ int ifile_open(const OptionsContext *o, const char *filename)
assert_avoptions(o->g->format_opts);
/* apply forced codec ids */
- for (i = 0; i < ic->nb_streams; i++)
- choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE);
+ for (i = 0; i < ic->nb_streams; i++) {
+ const AVCodec *dummy;
+ ret = choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE,
+ &dummy);
+ if (ret < 0)
+ return ret;
+ }
if (o->find_stream_info) {
AVDictionary **opts;
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index cb943ac408..aebec0c573 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -140,7 +140,9 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
return AVERROR_ENCODER_NOT_FOUND;
}
} else if (strcmp(codec_name, "copy")) {
- *enc = find_codec_or_die(ost, codec_name, ost->type, 1);
+ int ret = find_codec(ost, codec_name, ost->type, 1, enc);
+ if (ret < 0)
+ return ret;
ost->par_in->codec_id = (*enc)->id;
}
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index eef6d5e749..5a5a26d0a5 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -637,8 +637,8 @@ static int opt_recording_timestamp(void *optctx, const char *opt, const char *ar
return 0;
}
-const AVCodec *find_codec_or_die(void *logctx, const char *name,
- enum AVMediaType type, int encoder)
+int find_codec(void *logctx, const char *name,
+ enum AVMediaType type, int encoder, const AVCodec **pcodec)
{
const AVCodecDescriptor *desc;
const char *codec_string = encoder ? "encoder" : "decoder";
@@ -658,13 +658,16 @@ const AVCodec *find_codec_or_die(void *logctx, const char *name,
if (!codec) {
av_log(logctx, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
- exit_program(1);
+ return encoder ? AVERROR_ENCODER_NOT_FOUND :
+ AVERROR_DECODER_NOT_FOUND;
}
if (codec->type != type && !recast_media) {
av_log(logctx, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
- exit_program(1);
+ return AVERROR(EINVAL);
}
- return codec;
+
+ *pcodec = codec;
+ return 0;;
}
int assert_file_overwrite(const char *filename)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 30/47] fftools/ffmpeg_opt: replace exit_program() with returning error codes
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (27 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 29/47] fftools/ffmpeg: return errors from find_codec_or_die() instead of aborting Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 31/47] fftools/opt_common: " Anton Khirnov
` (17 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_opt.c | 49 ++++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 20 deletions(-)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 5a5a26d0a5..293397a8b7 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -190,7 +190,7 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id
else if (!is_global && !av_strcasecmp(arg, "auto")) *vsync_var = VSYNC_AUTO;
else if (!is_global) {
av_log(NULL, AV_LOG_FATAL, "Invalid value %s specified for fps_mode of #%d:%d.\n", arg, file_idx, st_idx);
- exit_program(1);
+ return AVERROR(EINVAL);
}
if (is_global && *vsync_var == VSYNC_AUTO) {
@@ -250,12 +250,12 @@ static int apply_sync_offsets(void)
if (self->input_sync_ref == -1 || self->input_sync_ref == i) continue;
if (self->input_sync_ref >= nb_input_files || self->input_sync_ref < -1) {
av_log(NULL, AV_LOG_FATAL, "-isync for input %d references non-existent input %d.\n", i, self->input_sync_ref);
- exit_program(1);
+ return AVERROR(EINVAL);
}
if (copy_ts && !start_at_zero) {
av_log(NULL, AV_LOG_FATAL, "Use of -isync requires that start_at_zero be set if copyts is set.\n");
- exit_program(1);
+ return AVERROR(EINVAL);
}
ref = input_files[self->input_sync_ref];
@@ -397,7 +397,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
m->linklabel = av_get_token(&c, "]");
if (!m->linklabel) {
av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
- exit_program(1);
+ return AVERROR(EINVAL);
}
} else {
if (allow_unused = strchr(map, '?'))
@@ -405,7 +405,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
file_idx = strtol(map, &p, 0);
if (file_idx >= nb_input_files || file_idx < 0) {
av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
- exit_program(1);
+ return AVERROR(EINVAL);
}
if (negative)
/* disable some already defined maps */
@@ -443,11 +443,11 @@ static int opt_map(void *optctx, const char *opt, const char *arg)
} else if (disabled) {
av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
"To ignore this, add a trailing '?' to the map.\n", arg);
- exit_program(1);
+ return AVERROR(EINVAL);
} else {
av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
"To ignore this, add a trailing '?' to the map.\n", arg);
- exit_program(1);
+ return AVERROR(EINVAL);
}
}
@@ -509,7 +509,7 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg)
if (n != 3 && n != 5) {
av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
"[file.stream.channel|-1][:syncfile:syncstream]\n");
- exit_program(1);
+ goto fail;
}
if (n != 5) // only file.stream.channel specified
@@ -519,19 +519,19 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg)
if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
m->file_idx);
- exit_program(1);
+ goto fail;
}
if (m->stream_idx < 0 ||
m->stream_idx >= input_files[m->file_idx]->nb_streams) {
av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
m->file_idx, m->stream_idx);
- exit_program(1);
+ goto fail;
}
st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
m->file_idx, m->stream_idx);
- exit_program(1);
+ goto fail;
}
/* allow trailing ? to map_channel */
if (allow_unused = strchr(mapchan, '?'))
@@ -545,12 +545,15 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg)
av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
"To ignore this, add a trailing '?' to the map_channel.\n",
m->file_idx, m->stream_idx, m->channel_idx);
- exit_program(1);
+ goto fail;
}
}
av_free(mapchan);
return 0;
+fail:
+ av_free(mapchan);
+ return AVERROR(EINVAL);
}
#endif
@@ -602,7 +605,7 @@ static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
AV_HWDEVICE_TYPE_NONE)
printf("%s\n", av_hwdevice_get_type_name(type));
printf("\n");
- exit_program(0);
+ return AVERROR_EXIT;
} else {
return hw_device_init_from_string(arg, NULL);
}
@@ -819,7 +822,7 @@ static int opt_target(void *optctx, const char *opt, const char *arg)
av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
- exit_program(1);
+ return AVERROR(EINVAL);
}
if (!strcmp(arg, "vcd")) {
@@ -931,7 +934,7 @@ static int opt_vstats(void *optctx, const char *opt, const char *arg)
if (!today) { // maybe tomorrow
av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
- exit_program(1);
+ return AVERROR(errno);
}
snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
@@ -983,6 +986,7 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
FILE *f=NULL;
char filename[1000], line[1000], tmp_line[1000];
const char *codec_name = NULL;
+ int ret = 0;
tmp_line[0] = *opt;
tmp_line[1] = 0;
@@ -993,7 +997,7 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
}else
av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
- exit_program(1);
+ return AVERROR(ENOENT);
}
while (fgets(line, sizeof(line), f)) {
@@ -1005,7 +1009,8 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
if (!av_strtok(key, "=", &value) ||
!av_strtok(value, "\r\n", &endptr)) {
av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
- exit_program(1);
+ ret = AVERROR(EINVAL);
+ goto fail;
}
av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
@@ -1016,13 +1021,15 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
else if (opt_default_new(o, key, value) < 0) {
av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
filename, line, key, value);
- exit_program(1);
+ ret = AVERROR(EINVAL);
+ goto fail;
}
}
+fail:
fclose(f);
- return 0;
+ return ret;
}
static int opt_old2new(void *optctx, const char *opt, const char *arg)
@@ -1310,7 +1317,9 @@ int ffmpeg_parse_options(int argc, char **argv)
correct_input_start_times();
- apply_sync_offsets();
+ ret = apply_sync_offsets();
+ if (ret < 0)
+ goto fail;
ret = check_filter_outputs();
if (ret < 0)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 31/47] fftools/opt_common: replace exit_program() with returning error codes
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (28 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 30/47] fftools/ffmpeg_opt: replace exit_program() with returning error codes Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 32/47] fftools: return errors from parse_number_or_die() instead of aborting Anton Khirnov
` (16 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/opt_common.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index f6fe9815e1..39258bb46c 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -1159,7 +1159,9 @@ int init_report(const char *env, FILE **file)
report_file_level = strtol(val, &tail, 10);
if (*tail) {
av_log(NULL, AV_LOG_FATAL, "Invalid report file level\n");
- exit_program(1);
+ av_free(key);
+ av_free(val);
+ return AVERROR(EINVAL);
}
envlevel = 1;
} else {
@@ -1219,7 +1221,7 @@ int opt_max_alloc(void *optctx, const char *opt, const char *arg)
max = strtol(arg, &tail, 10);
if (*tail) {
av_log(NULL, AV_LOG_FATAL, "Invalid max_alloc \"%s\".\n", arg);
- exit_program(1);
+ return AVERROR(EINVAL);
}
av_max_alloc(max);
return 0;
@@ -1293,7 +1295,7 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg)
"Possible levels are numbers or:\n", arg);
for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
- exit_program(1);
+ return AVERROR(EINVAL);
}
end:
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 32/47] fftools: return errors from parse_number_or_die() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (29 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 31/47] fftools/opt_common: " Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 33/47] fftools: remove parse_time_or_die() Anton Khirnov
` (15 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
Rename the function to just parse_number().
---
fftools/cmdutils.c | 39 +++++++++++++++++++++++++++++----------
fftools/cmdutils.h | 6 ++----
fftools/ffmpeg_mux_init.c | 7 +++++--
fftools/ffmpeg_opt.c | 23 ++++++++++++++++++-----
fftools/ffplay.c | 25 +++++++++++++++++++++----
fftools/ffprobe.c | 10 ++++++++--
6 files changed, 83 insertions(+), 27 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index fb35245f0a..48a81ca201 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -104,8 +104,8 @@ void exit_program(int ret)
exit(ret);
}
-double parse_number_or_die(const char *context, const char *numstr, int type,
- double min, double max)
+int parse_number(const char *context, const char *numstr, int type,
+ double min, double max, double *dst)
{
char *tail;
const char *error;
@@ -118,11 +118,13 @@ double parse_number_or_die(const char *context, const char *numstr, int type,
error = "Expected int64 for %s but found %s\n";
else if (type == OPT_INT && (int)d != d)
error = "Expected int for %s but found %s\n";
- else
- return d;
+ else {
+ *dst = d;
+ return 0;
+ }
+
av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
- exit_program(1);
- return 0;
+ return AVERROR(EINVAL);
}
int64_t parse_time_or_die(const char *context, const char *timestr,
@@ -262,6 +264,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
(uint8_t *)optctx + po->u.off : po->u.dst_ptr;
int *dstcount;
+ double num;
int ret;
if (po->flags & OPT_SPEC) {
@@ -289,15 +292,31 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
return AVERROR(ENOMEM);
*(char **)dst = str;
} else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
- *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
+ ret = parse_number(opt, arg, OPT_INT64, INT_MIN, INT_MAX, &num);
+ if (ret < 0)
+ return ret;
+
+ *(int *)dst = num;
} else if (po->flags & OPT_INT64) {
- *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
+ ret = parse_number(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX, &num);
+ if (ret < 0)
+ return ret;
+
+ *(int64_t *)dst = num;
} else if (po->flags & OPT_TIME) {
*(int64_t *)dst = parse_time_or_die(opt, arg, 1);
} else if (po->flags & OPT_FLOAT) {
- *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
+ ret = parse_number(opt, arg, OPT_FLOAT, -INFINITY, INFINITY, &num);
+ if (ret < 0)
+ return ret;
+
+ *(float *)dst = num;
} else if (po->flags & OPT_DOUBLE) {
- *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
+ ret = parse_number(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY, &num);
+ if (ret < 0)
+ return ret;
+
+ *(double *)dst = num;
} else if (po->u.func_arg) {
int ret = po->u.func_arg(optctx, opt, arg);
if (ret < 0) {
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 69c2123804..68de0bcb7f 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -100,8 +100,6 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg);
/**
* Parse a string and return its corresponding value as a double.
- * Exit from the application if the string cannot be correctly
- * parsed or the corresponding value is invalid.
*
* @param context the context of the value to be set (e.g. the
* corresponding command line option name)
@@ -111,8 +109,8 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg);
* @param min the minimum valid accepted value
* @param max the maximum valid accepted value
*/
-double parse_number_or_die(const char *context, const char *numstr, int type,
- double min, double max);
+int parse_number(const char *context, const char *numstr, int type,
+ double min, double max, double *dst);
/**
* Parse a string specifying a time and return its corresponding
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index aebec0c573..02d71588ad 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -795,8 +795,11 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o,
ost->vsync_method = video_sync_method;
MATCH_PER_STREAM_OPT(fps_mode, str, fps_mode, oc, st);
- if (fps_mode)
- parse_and_set_vsync(fps_mode, &ost->vsync_method, ost->file_index, ost->index, 0);
+ if (fps_mode) {
+ ret = parse_and_set_vsync(fps_mode, &ost->vsync_method, ost->file_index, ost->index, 0);
+ if (ret < 0)
+ return ret;
+ }
if ((ost->frame_rate.num || ost->max_frame_rate.num) &&
!(ost->vsync_method == VSYNC_AUTO ||
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 293397a8b7..e1696cdd59 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -194,7 +194,14 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id
}
if (is_global && *vsync_var == VSYNC_AUTO) {
- video_sync_method = parse_number_or_die("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR);
+ int ret;
+ double num;
+
+ ret = parse_number("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR, &num);
+ if (ret < 0)
+ return ret;
+
+ video_sync_method = num;
av_log(NULL, AV_LOG_WARNING, "Passing a number to -vsync is deprecated,"
" use a string argument as described in the manual.\n");
}
@@ -1104,8 +1111,7 @@ static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
static int opt_vsync(void *optctx, const char *opt, const char *arg)
{
av_log(NULL, AV_LOG_WARNING, "-vsync is deprecated. Use -fps_mode\n");
- parse_and_set_vsync(arg, &video_sync_method, -1, -1, 1);
- return 0;
+ return parse_and_set_vsync(arg, &video_sync_method, -1, -1, 1);
}
static int opt_timecode(void *optctx, const char *opt, const char *arg)
@@ -1353,8 +1359,15 @@ static int opt_progress(void *optctx, const char *opt, const char *arg)
int opt_timelimit(void *optctx, const char *opt, const char *arg)
{
#if HAVE_SETRLIMIT
- int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
- struct rlimit rl = { lim, lim + 1 };
+ int ret;
+ double lim;
+ struct rlimit rl;
+
+ ret = parse_number(opt, arg, OPT_INT64, 0, INT_MAX, &lim);
+ if (ret < 0)
+ return ret;
+
+ rl = (struct rlimit){ lim, lim + 1 };
if (setrlimit(RLIMIT_CPU, &rl))
perror("setrlimit");
#else
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 1f9757d607..6ca1ad98bf 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3440,13 +3440,23 @@ static void event_loop(VideoState *cur_stream)
static int opt_width(void *optctx, const char *opt, const char *arg)
{
- screen_width = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX);
+ double num;
+ int ret = parse_number(opt, arg, OPT_INT64, 1, INT_MAX, &num);
+ if (ret < 0)
+ return ret;
+
+ screen_width = num;
return 0;
}
static int opt_height(void *optctx, const char *opt, const char *arg)
{
- screen_height = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX);
+ double num;
+ int ret = parse_number(opt, arg, OPT_INT64, 1, INT_MAX, &num);
+ if (ret < 0)
+ return ret;
+
+ screen_height = num;
return 0;
}
@@ -3491,8 +3501,15 @@ static int opt_show_mode(void *optctx, const char *opt, const char *arg)
{
show_mode = !strcmp(arg, "video") ? SHOW_MODE_VIDEO :
!strcmp(arg, "waves") ? SHOW_MODE_WAVES :
- !strcmp(arg, "rdft" ) ? SHOW_MODE_RDFT :
- parse_number_or_die(opt, arg, OPT_INT, 0, SHOW_MODE_NB-1);
+ !strcmp(arg, "rdft" ) ? SHOW_MODE_RDFT : SHOW_MODE_NONE;
+
+ if (show_mode == SHOW_MODE_NONE) {
+ double num;
+ int ret = parse_number(opt, arg, OPT_INT, 0, SHOW_MODE_NB-1, &num);
+ if (ret < 0)
+ return ret;
+ show_mode = num;
+ }
return 0;
}
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 91a3be660b..e6fd33492d 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3665,8 +3665,14 @@ static int opt_show_optional_fields(void *optctx, const char *opt, const char *a
else if (!av_strcasecmp(arg, "never")) show_optional_fields = SHOW_OPTIONAL_FIELDS_NEVER;
else if (!av_strcasecmp(arg, "auto")) show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO;
- if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto"))
- show_optional_fields = parse_number_or_die("show_optional_fields", arg, OPT_INT, SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS);
+ if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto")) {
+ double num;
+ int ret = parse_number("show_optional_fields", arg, OPT_INT,
+ SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS, &num);
+ if (ret < 0)
+ return ret;
+ show_optional_fields = num;
+ }
return 0;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 33/47] fftools: remove parse_time_or_die()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (30 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 32/47] fftools: return errors from parse_number_or_die() instead of aborting Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 34/47] fftools: handle errors in parse_options() Anton Khirnov
` (14 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
Replace it with calling av_parse_time() directly, which provides
graceful error handling and more accurate error messages.
---
fftools/cmdutils.c | 19 ++++++-------------
fftools/cmdutils.h | 17 -----------------
fftools/ffmpeg_mux_init.c | 30 ++++++++++++++++++++++++------
fftools/ffmpeg_opt.c | 17 ++++++++++++++---
fftools/ffplay.c | 16 ++--------------
5 files changed, 46 insertions(+), 53 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 48a81ca201..b401b8fb89 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -127,18 +127,6 @@ int parse_number(const char *context, const char *numstr, int type,
return AVERROR(EINVAL);
}
-int64_t parse_time_or_die(const char *context, const char *timestr,
- int is_duration)
-{
- int64_t us;
- if (av_parse_time(&us, timestr, is_duration) < 0) {
- av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
- is_duration ? "duration" : "date", context, timestr);
- exit_program(1);
- }
- return us;
-}
-
void show_help_options(const OptionDef *options, const char *msg, int req_flags,
int rej_flags, int alt_flags)
{
@@ -304,7 +292,12 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
*(int64_t *)dst = num;
} else if (po->flags & OPT_TIME) {
- *(int64_t *)dst = parse_time_or_die(opt, arg, 1);
+ ret = av_parse_time(dst, arg, 1);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Invalid duration for option %s: %s\n",
+ opt, arg);
+ return ret;
+ }
} else if (po->flags & OPT_FLOAT) {
ret = parse_number(opt, arg, OPT_FLOAT, -INFINITY, INFINITY, &num);
if (ret < 0)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 68de0bcb7f..dc041d9fa2 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -112,23 +112,6 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg);
int parse_number(const char *context, const char *numstr, int type,
double min, double max, double *dst);
-/**
- * Parse a string specifying a time and return its corresponding
- * value as a number of microseconds. Exit from the application if
- * the string cannot be correctly parsed.
- *
- * @param context the context of the value to be set (e.g. the
- * corresponding command line option name)
- * @param timestr the string to be parsed
- * @param is_duration a flag which tells how to interpret timestr, if
- * not zero timestr is interpreted as a duration, otherwise as a
- * date
- *
- * @see av_parse_time()
- */
-int64_t parse_time_or_die(const char *context, const char *timestr,
- int is_duration);
-
typedef struct SpecifierOpt {
char *specifier; /**< stream/chapter/program/... specifier */
union {
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 02d71588ad..92d62c7b89 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -2410,11 +2410,11 @@ static int compare_int64(const void *a, const void *b)
return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b);
}
-static int parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux,
- const char *spec)
+static int parse_forced_key_frames(void *log, KeyframeForceCtx *kf,
+ const Muxer *mux, const char *spec)
{
const char *p;
- int n = 1, i, size, index = 0;
+ int n = 1, i, ret, size, index = 0;
int64_t t, *pts;
for (p = spec; *p; p++)
@@ -2441,7 +2441,16 @@ static int parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux,
!(pts = av_realloc_f(pts, size += nb_ch - 1,
sizeof(*pts))))
return AVERROR(ENOMEM);
- t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0;
+
+ if (p[8]) {
+ ret = av_parse_time(&t, p + 8, 1);
+ if (ret < 0) {
+ av_log(log, AV_LOG_ERROR,
+ "Invalid chapter time offset: %s\n", p + 8);
+ goto fail;
+ }
+ } else
+ t = 0;
for (j = 0; j < nb_ch; j++) {
const AVChapter *c = ch[j];
@@ -2452,7 +2461,13 @@ static int parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux,
} else {
av_assert1(index < size);
- pts[index++] = parse_time_or_die("force_key_frames", p, 1);
+ ret = av_parse_time(&t, p, 1);
+ if (ret < 0) {
+ av_log(log, AV_LOG_ERROR, "Invalid keyframe time: %s\n", p);
+ goto fail;
+ }
+
+ pts[index++] = t;
}
p = next;
@@ -2464,6 +2479,9 @@ static int parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux,
kf->pts = pts;
return 0;
+fail:
+ av_freep(&pts);
+ return ret;
}
static int process_forced_keyframes(Muxer *mux, const OptionsContext *o)
@@ -2498,7 +2516,7 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o)
} else if (!strcmp(forced_keyframes, "source_no_drop")) {
ost->kf.type = KF_FORCE_SOURCE_NO_DROP;
} else {
- int ret = parse_forced_key_frames(&ost->kf, mux, forced_keyframes);
+ int ret = parse_forced_key_frames(ost, &ost->kf, mux, forced_keyframes);
if (ret < 0)
return ret;
}
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index e1696cdd59..44a6b49ed7 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -326,7 +326,10 @@ static int opt_abort_on(void *optctx, const char *opt, const char *arg)
static int opt_stats_period(void *optctx, const char *opt, const char *arg)
{
- int64_t user_stats_period = parse_time_or_die(opt, arg, 1);
+ int64_t user_stats_period;
+ int ret = av_parse_time(&user_stats_period, arg, 1);
+ if (ret < 0)
+ return ret;
if (user_stats_period <= 0) {
av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg);
@@ -636,8 +639,16 @@ static int opt_recording_timestamp(void *optctx, const char *opt, const char *ar
{
OptionsContext *o = optctx;
char buf[128];
- int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
- struct tm time = *gmtime((time_t*)&recording_timestamp);
+ int64_t recording_timestamp;
+ int ret;
+ struct tm time;
+
+ ret = av_parse_time(&recording_timestamp, arg, 0);
+ if (ret < 0)
+ return ret;
+
+ recording_timestamp /= 1e6;
+ time = *gmtime((time_t*)&recording_timestamp);
if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
return -1;
parse_option(o, "metadata", buf, options);
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 6ca1ad98bf..89cea4d876 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3485,18 +3485,6 @@ static int opt_sync(void *optctx, const char *opt, const char *arg)
return 0;
}
-static int opt_seek(void *optctx, const char *opt, const char *arg)
-{
- start_time = parse_time_or_die(opt, arg, 1);
- return 0;
-}
-
-static int opt_duration(void *optctx, const char *opt, const char *arg)
-{
- duration = parse_time_or_die(opt, arg, 1);
- return 0;
-}
-
static int opt_show_mode(void *optctx, const char *opt, const char *arg)
{
show_mode = !strcmp(arg, "video") ? SHOW_MODE_VIDEO :
@@ -3561,8 +3549,8 @@ static const OptionDef options[] = {
{ "ast", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_AUDIO] }, "select desired audio stream", "stream_specifier" },
{ "vst", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_VIDEO] }, "select desired video stream", "stream_specifier" },
{ "sst", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_SUBTITLE] }, "select desired subtitle stream", "stream_specifier" },
- { "ss", HAS_ARG, { .func_arg = opt_seek }, "seek to a given position in seconds", "pos" },
- { "t", HAS_ARG, { .func_arg = opt_duration }, "play \"duration\" seconds of audio/video", "duration" },
+ { "ss", HAS_ARG | OPT_TIME, { &start_time }, "seek to a given position in seconds", "pos" },
+ { "t", HAS_ARG | OPT_TIME, { &duration }, "play \"duration\" seconds of audio/video", "duration" },
{ "bytes", OPT_INT | HAS_ARG, { &seek_by_bytes }, "seek by bytes 0=off 1=on -1=auto", "val" },
{ "seek_interval", OPT_FLOAT | HAS_ARG, { &seek_interval }, "set seek interval for left/right keys, in seconds", "seconds" },
{ "nodisp", OPT_BOOL, { &display_disable }, "disable graphical display" },
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 34/47] fftools: handle errors in parse_options()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (31 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 33/47] fftools: remove parse_time_or_die() Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 35/47] fftools/cmdutils: constify the first parameter of filter_codec_opts() Anton Khirnov
` (13 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.c | 15 ++++++++++-----
fftools/cmdutils.h | 4 ++--
fftools/ffplay.c | 12 ++++++++----
fftools/ffprobe.c | 10 +++++++---
4 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index b401b8fb89..330b9c2aba 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -364,8 +364,8 @@ int parse_option(void *optctx, const char *opt, const char *arg,
return !!(po->flags & HAS_ARG);
}
-void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
- void (*parse_arg_function)(void *, const char*))
+int parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
+ int (*parse_arg_function)(void *, const char*))
{
const char *opt;
int optindex, handleoptions = 1, ret;
@@ -386,13 +386,18 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
opt++;
if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
- exit_program(1);
+ return ret;
optindex += ret;
} else {
- if (parse_arg_function)
- parse_arg_function(optctx, opt);
+ if (parse_arg_function) {
+ ret = parse_arg_function(optctx, opt);
+ if (ret < 0)
+ return ret;
+ }
}
}
+
+ return 0;
}
int parse_optgroup(void *optctx, OptionGroup *g)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index dc041d9fa2..210d52e998 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -194,8 +194,8 @@ void show_help_default(const char *opt, const char *arg);
* argument without a leading option name flag. NULL if such arguments do
* not have to be processed.
*/
-void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
- void (* parse_arg_function)(void *optctx, const char*));
+int parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
+ int (* parse_arg_function)(void *optctx, const char*));
/**
* Parse one given option.
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 89cea4d876..4e26b3309d 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3501,17 +3501,19 @@ static int opt_show_mode(void *optctx, const char *opt, const char *arg)
return 0;
}
-static void opt_input_file(void *optctx, const char *filename)
+static int opt_input_file(void *optctx, const char *filename)
{
if (input_filename) {
av_log(NULL, AV_LOG_FATAL,
"Argument '%s' provided as input filename, but '%s' was already specified.\n",
filename, input_filename);
- exit(1);
+ return AVERROR(EINVAL);
}
if (!strcmp(filename, "-"))
filename = "fd:";
input_filename = filename;
+
+ return 0;
}
static int opt_codec(void *optctx, const char *opt, const char *arg)
@@ -3630,7 +3632,7 @@ void show_help_default(const char *opt, const char *arg)
/* Called from the main */
int main(int argc, char **argv)
{
- int flags;
+ int flags, ret;
VideoState *is;
init_dynload();
@@ -3649,7 +3651,9 @@ int main(int argc, char **argv)
show_banner(argc, argv, options);
- parse_options(NULL, argc, argv, options, opt_input_file);
+ ret = parse_options(NULL, argc, argv, options, opt_input_file);
+ if (ret < 0)
+ exit(1);
if (!input_filename) {
show_usage();
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index e6fd33492d..ba55437760 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3770,17 +3770,19 @@ static int opt_show_entries(void *optctx, const char *opt, const char *arg)
return ret;
}
-static void opt_input_file(void *optctx, const char *arg)
+static int opt_input_file(void *optctx, const char *arg)
{
if (input_filename) {
av_log(NULL, AV_LOG_ERROR,
"Argument '%s' provided as input filename, but '%s' was already specified.\n",
arg, input_filename);
- exit_program(1);
+ return AVERROR(EINVAL);
}
if (!strcmp(arg, "-"))
arg = "fd:";
input_filename = arg;
+
+ return 0;
}
static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
@@ -4121,7 +4123,9 @@ int main(int argc, char **argv)
#endif
show_banner(argc, argv, options);
- parse_options(NULL, argc, argv, options, opt_input_file);
+ ret = parse_options(NULL, argc, argv, options, opt_input_file);
+ if (ret < 0)
+ exit_program(1);
if (do_show_log)
av_log_set_callback(log_callback);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 35/47] fftools/cmdutils: constify the first parameter of filter_codec_opts()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (32 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 34/47] fftools: handle errors in parse_options() Anton Khirnov
@ 2023-07-15 10:45 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 36/47] fftools/cmdutils: add error handling to filter_codec_opts() Anton Khirnov
` (12 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:45 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.c | 2 +-
fftools/cmdutils.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 330b9c2aba..137e69f2c3 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -943,7 +943,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
return ret;
}
-AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
+AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
AVFormatContext *s, AVStream *st, const AVCodec *codec)
{
AVDictionary *ret = NULL;
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 210d52e998..7e7fb700b7 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -335,7 +335,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
* If null, the default one is looked up according to the codec id.
* @return a pointer to the created dictionary
*/
-AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
+AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
AVFormatContext *s, AVStream *st, const AVCodec *codec);
/**
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 36/47] fftools/cmdutils: add error handling to filter_codec_opts()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (33 preceding siblings ...)
2023-07-15 10:45 ` [FFmpeg-devel] [PATCH 35/47] fftools/cmdutils: constify the first parameter of filter_codec_opts() Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 37/47] fftools/ffmpeg_opt: consolidate printing errors in ffmpeg_parse_options() Anton Khirnov
` (11 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.c | 41 ++++++++++++++++++++++++++-------------
fftools/cmdutils.h | 8 +++++---
fftools/ffmpeg_demux.c | 5 ++++-
fftools/ffmpeg_mux_init.c | 11 ++++++++---
fftools/ffplay.c | 6 +++++-
fftools/ffprobe.c | 8 ++++++--
6 files changed, 56 insertions(+), 23 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 137e69f2c3..9d9d8d44a6 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -943,8 +943,9 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
return ret;
}
-AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
- AVFormatContext *s, AVStream *st, const AVCodec *codec)
+int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
+ AVFormatContext *s, AVStream *st, const AVCodec *codec,
+ AVDictionary **dst)
{
AVDictionary *ret = NULL;
const AVDictionaryEntry *t = NULL;
@@ -977,12 +978,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i
char *p = strchr(t->key, ':');
/* check stream specification in opt name */
- if (p)
- switch (check_stream_specifier(s, st, p + 1)) {
- case 1: *p = 0; break;
- case 0: continue;
- default: exit_program(1);
- }
+ if (p) {
+ int err = check_stream_specifier(s, st, p + 1);
+ if (err < 0) {
+ av_dict_free(&ret);
+ return err;
+ } else if (!err)
+ continue;
+
+ *p = 0;
+ }
if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
!codec ||
@@ -998,14 +1003,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i
if (p)
*p = ':';
}
- return ret;
+
+ *dst = ret;
+ return 0;
}
int setup_find_stream_info_opts(AVFormatContext *s,
AVDictionary *codec_opts,
AVDictionary ***dst)
{
- int i;
+ int ret;
AVDictionary **opts;
*dst = NULL;
@@ -1017,11 +1024,19 @@ int setup_find_stream_info_opts(AVFormatContext *s,
if (!opts)
return AVERROR(ENOMEM);
- for (i = 0; i < s->nb_streams; i++)
- opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
- s, s->streams[i], NULL);
+ for (int i = 0; i < s->nb_streams; i++) {
+ ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
+ s, s->streams[i], NULL, &opts[i]);
+ if (ret < 0)
+ goto fail;
+ }
*dst = opts;
return 0;
+fail:
+ for (int i = 0; i < s->nb_streams; i++)
+ av_dict_free(&opts[i]);
+ av_freep(&opts);
+ return ret;
}
int grow_array(void **array, int elem_size, int *size, int new_size)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 7e7fb700b7..97e49850c5 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -333,10 +333,12 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
* @param st A stream from s for which the options should be filtered.
* @param codec The particular codec for which the options should be filtered.
* If null, the default one is looked up according to the codec id.
- * @return a pointer to the created dictionary
+ * @param dst a pointer to the created dictionary
+ * @return a non-negative number on success, a negative error code on failure
*/
-AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
- AVFormatContext *s, AVStream *st, const AVCodec *codec);
+int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
+ AVFormatContext *s, AVStream *st, const AVCodec *codec,
+ AVDictionary **dst);
/**
* Setup AVCodecContext options for avformat_find_stream_info().
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index a41b59ceb8..d612c5f434 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1176,7 +1176,10 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
if (ret < 0)
return ret;
- ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
+ ret = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id,
+ ic, st, ist->dec, &ist->decoder_opts);
+ if (ret < 0)
+ return ret;
ist->reinit_filters = -1;
MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 92d62c7b89..63d86209ff 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1217,8 +1217,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL;
const char *enc_time_base = NULL;
- ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id,
- oc, st, enc->codec);
+ ret = filter_codec_opts(o->g->codec_opts, enc->codec_id,
+ oc, st, enc->codec, &ost->encoder_opts);
+ if (ret < 0)
+ return ret;
MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
ost->autoscale = 1;
@@ -1316,7 +1318,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
ost->enc_timebase = q;
}
} else {
- ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
+ ret = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st,
+ NULL, &ost->encoder_opts);
+ if (ret < 0)
+ return ret;
}
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 4e26b3309d..df20c6a29d 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -2584,7 +2584,11 @@ static int stream_component_open(VideoState *is, int stream_index)
if (fast)
avctx->flags2 |= AV_CODEC_FLAG2_FAST;
- opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index], codec);
+ ret = filter_codec_opts(codec_opts, avctx->codec_id, ic,
+ ic->streams[stream_index], codec, &opts);
+ if (ret < 0)
+ goto fail;
+
if (!av_dict_get(opts, "threads", NULL, 0))
av_dict_set(&opts, "threads", "auto", 0);
if (stream_lowres)
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index ba55437760..da8fc89830 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3421,8 +3421,12 @@ static int open_input_file(InputFile *ifile, const char *filename,
continue;
}
{
- AVDictionary *opts = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
- fmt_ctx, stream, codec);
+ AVDictionary *opts;
+
+ err = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
+ fmt_ctx, stream, codec, &opts);
+ if (err < 0)
+ exit(1);
ist->dec_ctx = avcodec_alloc_context3(codec);
if (!ist->dec_ctx)
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 37/47] fftools/ffmpeg_opt: consolidate printing errors in ffmpeg_parse_options()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (34 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 36/47] fftools/cmdutils: add error handling to filter_codec_opts() Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 38/47] fftools/ffmpeg: consolidate exiting from main() on error Anton Khirnov
` (10 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg_opt.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 44a6b49ed7..14b292f202 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1289,6 +1289,7 @@ static int open_files(OptionGroupList *l, const char *inout,
int ffmpeg_parse_options(int argc, char **argv)
{
OptionParseContext octx;
+ const char *errmsg = NULL;
int ret;
memset(&octx, 0, sizeof(octx));
@@ -1297,14 +1298,14 @@ int ffmpeg_parse_options(int argc, char **argv)
ret = split_commandline(&octx, argc, argv, options, groups,
FF_ARRAY_ELEMS(groups));
if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
+ errmsg = "splitting the argument list";
goto fail;
}
/* apply global options */
ret = parse_optgroup(NULL, &octx.global_opts);
if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
+ errmsg = "parsing global options";
goto fail;
}
@@ -1314,21 +1315,21 @@ int ffmpeg_parse_options(int argc, char **argv)
/* open input files */
ret = open_files(&octx.groups[GROUP_INFILE], "input", ifile_open);
if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
+ errmsg = "opening input files";
goto fail;
}
/* create the complex filtergraphs */
ret = init_complex_filters();
if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
+ errmsg = "initializing complex filters";
goto fail;
}
/* open output files */
ret = open_files(&octx.groups[GROUP_OUTFILE], "output", of_open);
if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
+ errmsg = "opening output files";
goto fail;
}
@@ -1345,7 +1346,8 @@ int ffmpeg_parse_options(int argc, char **argv)
fail:
uninit_parse_context(&octx);
if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
+ av_log(NULL, AV_LOG_FATAL, "Error %s: %s\n",
+ errmsg ? errmsg : "", av_err2str(ret));
}
return ret;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 38/47] fftools/ffmpeg: consolidate exiting from main() on error
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (35 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 37/47] fftools/ffmpeg_opt: consolidate printing errors in ffmpeg_parse_options() Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 39/47] fftools/cmdutils: return AVERROR_EXIT for OPT_EXIT options instead of aborting() Anton Khirnov
` (9 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index b4ea52ac1d..0c5e553c72 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1339,17 +1339,19 @@ int main(int argc, char **argv)
/* parse options and open all input/output files */
ret = ffmpeg_parse_options(argc, argv);
if (ret < 0)
- exit_program(1);
+ goto finish;
if (nb_output_files <= 0 && nb_input_files == 0) {
show_usage();
av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
- exit_program(1);
+ ret = 1;
+ goto finish;
}
if (nb_output_files <= 0) {
av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n");
- exit_program(1);
+ ret = 1;
+ goto finish;
}
current_time = ti = get_benchmark_time_stamps();
@@ -1368,6 +1370,7 @@ int main(int argc, char **argv)
ret = received_nb_signals ? 255 :
err_rate_exceeded ? 69 : ret;
+finish:
exit_program(ret);
return ret;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 39/47] fftools/cmdutils: return AVERROR_EXIT for OPT_EXIT options instead of aborting()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (36 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 38/47] fftools/ffmpeg: consolidate exiting from main() on error Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 40/47] fftools/ffmpeg: return an error from assert_avoptions() instead of aborting Anton Khirnov
` (8 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/cmdutils.c | 2 +-
fftools/ffmpeg.c | 3 +++
fftools/ffmpeg_opt.c | 2 +-
fftools/ffplay.c | 2 +-
fftools/ffprobe.c | 2 +-
5 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 9d9d8d44a6..f37b7d44d6 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -320,7 +320,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
}
}
if (po->flags & OPT_EXIT)
- exit_program(0);
+ return AVERROR_EXIT;
return 0;
}
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0c5e553c72..50d6658472 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1371,6 +1371,9 @@ int main(int argc, char **argv)
err_rate_exceeded ? 69 : ret;
finish:
+ if (ret == AVERROR_EXIT)
+ ret = 0;
+
exit_program(ret);
return ret;
}
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 14b292f202..700db706a1 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1345,7 +1345,7 @@ int ffmpeg_parse_options(int argc, char **argv)
fail:
uninit_parse_context(&octx);
- if (ret < 0) {
+ if (ret < 0 && ret != AVERROR_EXIT) {
av_log(NULL, AV_LOG_FATAL, "Error %s: %s\n",
errmsg ? errmsg : "", av_err2str(ret));
}
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index df20c6a29d..a491fdd9e3 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3657,7 +3657,7 @@ int main(int argc, char **argv)
ret = parse_options(NULL, argc, argv, options, opt_input_file);
if (ret < 0)
- exit(1);
+ exit(ret == AVERROR_EXIT ? 0 : 1);
if (!input_filename) {
show_usage();
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index da8fc89830..c83d20995e 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -4129,7 +4129,7 @@ int main(int argc, char **argv)
show_banner(argc, argv, options);
ret = parse_options(NULL, argc, argv, options, opt_input_file);
if (ret < 0)
- exit_program(1);
+ exit_program(ret == AVERROR_EXIT ? 0 : 1);
if (do_show_log)
av_log_set_callback(log_callback);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 40/47] fftools/ffmpeg: return an error from assert_avoptions() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (37 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 39/47] fftools/cmdutils: return AVERROR_EXIT for OPT_EXIT options instead of aborting() Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 41/47] fftools/ffmpeg: return an error from MATCH_PER_STREAM_OPT() " Anton Khirnov
` (7 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
Rename it to check_avoptions().
---
fftools/ffmpeg.c | 6 ++++--
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_dec.c | 5 ++++-
fftools/ffmpeg_demux.c | 5 ++++-
fftools/ffmpeg_enc.c | 5 ++++-
5 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 50d6658472..ecb3f89f85 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -457,13 +457,15 @@ void remove_avoptions(AVDictionary **a, AVDictionary *b)
}
}
-void assert_avoptions(AVDictionary *m)
+int check_avoptions(AVDictionary *m)
{
const AVDictionaryEntry *t;
if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
- exit_program(1);
+ return AVERROR_OPTION_NOT_FOUND;
}
+
+ return 0;
}
void update_benchmark(const char *fmt, ...)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 60dff87436..73baad238c 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -705,7 +705,7 @@ void term_exit(void);
void show_usage(void);
void remove_avoptions(AVDictionary **a, AVDictionary *b);
-void assert_avoptions(AVDictionary *m);
+int check_avoptions(AVDictionary *m);
int assert_file_overwrite(const char *filename);
char *file_read(const char *filename);
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 62c1baf287..8a3b52fd7e 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -1119,7 +1119,10 @@ int dec_open(InputStream *ist)
av_err2str(ret));
return ret;
}
- assert_avoptions(ist->decoder_opts);
+
+ ret = check_avoptions(ist->decoder_opts);
+ if (ret < 0)
+ return ret;
ret = dec_thread_start(ist);
if (ret < 0) {
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index d612c5f434..48edbd7f6b 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1511,7 +1511,10 @@ int ifile_open(const OptionsContext *o, const char *filename)
if (scan_all_pmts_set)
av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
remove_avoptions(&o->g->format_opts, o->g->codec_opts);
- assert_avoptions(o->g->format_opts);
+
+ ret = check_avoptions(o->g->format_opts);
+ if (ret < 0)
+ return ret;
/* apply forced codec ids */
for (i = 0; i < ic->nb_streams; i++) {
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 01e1b0656c..dde239657f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -411,7 +411,10 @@ int enc_open(OutputStream *ost, AVFrame *frame)
ost->sq_idx_encode, ost->enc_ctx->frame_size);
}
- assert_avoptions(ost->encoder_opts);
+ ret = check_avoptions(ost->encoder_opts);
+ if (ret < 0)
+ return ret;
+
if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000 &&
ost->enc_ctx->codec_id != AV_CODEC_ID_CODEC2 /* don't complain about 700 bit/s modes */)
av_log(ost, AV_LOG_WARNING, "The bitrate parameter is set too low."
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 41/47] fftools/ffmpeg: return an error from MATCH_PER_STREAM_OPT() instead of aborting
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (38 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 40/47] fftools/ffmpeg: return an error from assert_avoptions() instead of aborting Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 42/47] fftools/ffprobe: replace report_and_exit() with returning error codes Anton Khirnov
` (6 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 73baad238c..5c93b3aa29 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -912,7 +912,7 @@ static inline int err_merge(int err0, int err1)
so = &o->name[_i];\
_matches++;\
} else if (_ret < 0)\
- exit_program(1);\
+ return _ret;\
}\
if (_matches > 1)\
WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 42/47] fftools/ffprobe: replace report_and_exit() with returning error codes
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (39 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 41/47] fftools/ffmpeg: return an error from MATCH_PER_STREAM_OPT() " Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 43/47] fftools/ffplay: replace report_and_exit() with returning an error code Anton Khirnov
` (5 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffprobe.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index c83d20995e..6180a5c952 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3350,7 +3350,7 @@ static int open_input_file(InputFile *ifile, const char *filename,
fmt_ctx = avformat_alloc_context();
if (!fmt_ctx)
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
@@ -3377,7 +3377,7 @@ static int open_input_file(InputFile *ifile, const char *filename,
err = setup_find_stream_info_opts(fmt_ctx, codec_opts, &opts);
if (err < 0)
- report_and_exit(err);
+ return err;
err = avformat_find_stream_info(fmt_ctx, opts);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 43/47] fftools/ffplay: replace report_and_exit() with returning an error code
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (40 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 42/47] fftools/ffprobe: replace report_and_exit() with returning error codes Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 44/47] fftools/opt_common: " Anton Khirnov
` (4 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffplay.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index a491fdd9e3..5212ad053e 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -2784,8 +2784,12 @@ static int read_thread(void *arg)
int orig_nb_streams = ic->nb_streams;
err = setup_find_stream_info_opts(ic, codec_opts, &opts);
- if (err < 0)
- report_and_exit(err);
+ if (err < 0) {
+ av_log(NULL, AV_LOG_ERROR,
+ "Error setting up avformat_find_stream_info() options\n");
+ ret = err;
+ goto fail;
+ }
err = avformat_find_stream_info(ic, opts);
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 44/47] fftools/opt_common: replace report_and_exit() with returning an error code
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (41 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 43/47] fftools/ffplay: replace report_and_exit() with returning an error code Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 45/47] fftools/ffprobe: inline opt_output_file() into its only caller Anton Khirnov
` (3 subsequent siblings)
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
Remove report_and_exit(), as it has no more users.
---
fftools/cmdutils.c | 6 ------
fftools/cmdutils.h | 11 -----------
fftools/opt_common.c | 10 +++++++---
3 files changed, 7 insertions(+), 20 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index f37b7d44d6..bceb778ff0 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -90,12 +90,6 @@ void register_exit(void (*cb)(int ret))
program_exit = cb;
}
-void report_and_exit(int ret)
-{
- av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
- exit_program(AVUNERROR(ret));
-}
-
void exit_program(int ret)
{
if (program_exit)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 97e49850c5..cc2180f768 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -54,17 +54,6 @@ extern int hide_banner;
*/
void register_exit(void (*cb)(int ret));
-/**
- * Reports an error corresponding to the provided
- * AVERROR code and calls exit_program() with the
- * corresponding POSIX error code.
- * @note ret must be an AVERROR-value of a POSIX error code
- * (i.e. AVERROR(EFOO) and not AVERROR_FOO).
- * library functions can return both, so call this only
- * with AVERROR(EFOO) of your own.
- */
-void report_and_exit(int ret) av_noreturn;
-
/**
* Wraps exit with a program-specific cleanup routine.
*/
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 39258bb46c..913932c914 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -632,7 +632,7 @@ static int compare_codec_desc(const void *a, const void *b)
strcmp((*da)->name, (*db)->name);
}
-static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
+static int get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
{
const AVCodecDescriptor *desc = NULL;
const AVCodecDescriptor **codecs;
@@ -641,7 +641,7 @@ static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
while ((desc = avcodec_descriptor_next(desc)))
nb_codecs++;
if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs))))
- report_and_exit(AVERROR(ENOMEM));
+ return AVERROR(ENOMEM);
desc = NULL;
while ((desc = avcodec_descriptor_next(desc)))
codecs[i++] = desc;
@@ -666,7 +666,11 @@ static char get_media_type_char(enum AVMediaType type)
int show_codecs(void *optctx, const char *opt, const char *arg)
{
const AVCodecDescriptor **codecs;
- unsigned i, nb_codecs = get_codecs_sorted(&codecs);
+ unsigned i;
+ int nb_codecs = get_codecs_sorted(&codecs);
+
+ if (nb_codecs < 0)
+ return nb_codecs;
printf("Codecs:\n"
" D..... = Decoding supported\n"
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 45/47] fftools/ffprobe: inline opt_output_file() into its only caller
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (42 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 44/47] fftools/opt_common: " Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-08-02 5:28 ` Stefano Sabatini
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program() Anton Khirnov
` (2 subsequent siblings)
46 siblings, 1 reply; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
There is no reason to keep them separate.
Also, replace exit_program() with returning an error code.
---
fftools/ffprobe.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 6180a5c952..e234c92904 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3795,22 +3795,18 @@ static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
return 0;
}
-static void opt_output_file(void *optctx, const char *arg)
+static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
{
if (output_filename) {
av_log(NULL, AV_LOG_ERROR,
"Argument '%s' provided as output filename, but '%s' was already specified.\n",
arg, output_filename);
- exit_program(1);
+ return AVERROR(EINVAL);
}
if (!strcmp(arg, "-"))
arg = "fd:";
output_filename = arg;
-}
-static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
-{
- opt_output_file(optctx, arg);
return 0;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* Re: [FFmpeg-devel] [PATCH 45/47] fftools/ffprobe: inline opt_output_file() into its only caller
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 45/47] fftools/ffprobe: inline opt_output_file() into its only caller Anton Khirnov
@ 2023-08-02 5:28 ` Stefano Sabatini
0 siblings, 0 replies; 53+ messages in thread
From: Stefano Sabatini @ 2023-08-02 5:28 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On date Saturday 2023-07-15 12:46:09 +0200, Anton Khirnov wrote:
> There is no reason to keep them separate.
>
> Also, replace exit_program() with returning an error code.
> ---
> fftools/ffprobe.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index 6180a5c952..e234c92904 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -3795,22 +3795,18 @@ static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
> return 0;
> }
>
> -static void opt_output_file(void *optctx, const char *arg)
> +static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
> {
> if (output_filename) {
> av_log(NULL, AV_LOG_ERROR,
> "Argument '%s' provided as output filename, but '%s' was already specified.\n",
> arg, output_filename);
> - exit_program(1);
> + return AVERROR(EINVAL);
> }
> if (!strcmp(arg, "-"))
> arg = "fd:";
> output_filename = arg;
> -}
>
> -static int opt_output_file_o(void *optctx, const char *opt, const char *arg)
> -{
> - opt_output_file(optctx, arg);
> return 0;
> }
>
LGTM.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (43 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 45/47] fftools/ffprobe: inline opt_output_file() into its only caller Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-20 20:35 ` Marton Balint
2023-08-02 5:32 ` Stefano Sabatini
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 47/47] fftools/ffmpeg: " Anton Khirnov
2023-07-20 18:56 ` [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
46 siblings, 2 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
Inline the relevant part of ffprobe_cleanup() into main() and drop the
rest.
---
fftools/ffprobe.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index e234c92904..a39185f6fe 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -381,17 +381,6 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
#endif
}
-static void ffprobe_cleanup(int ret)
-{
- int i;
- for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
- av_dict_free(&(sections[i].entries_to_show));
-
-#if HAVE_THREADS
- pthread_mutex_destroy(&log_mutex);
-#endif
-}
-
struct unit_value {
union { double d; long long int i; } val;
const char *unit;
@@ -4113,7 +4102,6 @@ int main(int argc, char **argv)
}
#endif
av_log_set_flags(AV_LOG_SKIP_REPEATED);
- register_exit(ffprobe_cleanup);
options = real_options;
parse_loglevel(argc, argv, options);
@@ -4124,8 +4112,10 @@ int main(int argc, char **argv)
show_banner(argc, argv, options);
ret = parse_options(NULL, argc, argv, options, opt_input_file);
- if (ret < 0)
- exit_program(ret == AVERROR_EXIT ? 0 : 1);
+ if (ret < 0) {
+ ret = AVERROR_EXIT ? 0 : ret;
+ goto end;
+ }
if (do_show_log)
av_log_set_callback(log_callback);
@@ -4249,5 +4239,9 @@ end:
avformat_network_deinit();
+#if HAVE_THREADS
+ pthread_mutex_destroy(&log_mutex);
+#endif
+
return ret < 0;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* Re: [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program()
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program() Anton Khirnov
@ 2023-07-20 20:35 ` Marton Balint
2023-07-21 12:06 ` Anton Khirnov
2023-08-02 5:32 ` Stefano Sabatini
1 sibling, 1 reply; 53+ messages in thread
From: Marton Balint @ 2023-07-20 20:35 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sat, 15 Jul 2023, Anton Khirnov wrote:
> Inline the relevant part of ffprobe_cleanup() into main() and drop the
> rest.
> ---
> fftools/ffprobe.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index e234c92904..a39185f6fe 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -381,17 +381,6 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
> #endif
> }
>
[...]
> @@ -4124,8 +4112,10 @@ int main(int argc, char **argv)
>
> show_banner(argc, argv, options);
> ret = parse_options(NULL, argc, argv, options, opt_input_file);
> - if (ret < 0)
> - exit_program(ret == AVERROR_EXIT ? 0 : 1);
> + if (ret < 0) {
> + ret = AVERROR_EXIT ? 0 : ret;
This looks unintended.
Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* Re: [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program()
2023-07-20 20:35 ` Marton Balint
@ 2023-07-21 12:06 ` Anton Khirnov
2023-07-21 12:14 ` Anton Khirnov
0 siblings, 1 reply; 53+ messages in thread
From: Anton Khirnov @ 2023-07-21 12:06 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Marton Balint (2023-07-20 22:35:23)
>
>
> On Sat, 15 Jul 2023, Anton Khirnov wrote:
>
> > Inline the relevant part of ffprobe_cleanup() into main() and drop the
> > rest.
> > ---
> > fftools/ffprobe.c | 22 ++++++++--------------
> > 1 file changed, 8 insertions(+), 14 deletions(-)
> >
> > diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> > index e234c92904..a39185f6fe 100644
> > --- a/fftools/ffprobe.c
> > +++ b/fftools/ffprobe.c
> > @@ -381,17 +381,6 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
> > #endif
> > }
> >
>
>
> [...]
>
> > @@ -4124,8 +4112,10 @@ int main(int argc, char **argv)
> >
> > show_banner(argc, argv, options);
> > ret = parse_options(NULL, argc, argv, options, opt_input_file);
> > - if (ret < 0)
> > - exit_program(ret == AVERROR_EXIT ? 0 : 1);
> > + if (ret < 0) {
> > + ret = AVERROR_EXIT ? 0 : ret;
>
> This looks unintended.
Which part of it and why?
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* Re: [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program()
2023-07-21 12:06 ` Anton Khirnov
@ 2023-07-21 12:14 ` Anton Khirnov
0 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-21 12:14 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Anton Khirnov (2023-07-21 14:06:37)
> Quoting Marton Balint (2023-07-20 22:35:23)
> >
> >
> > On Sat, 15 Jul 2023, Anton Khirnov wrote:
> >
> > > Inline the relevant part of ffprobe_cleanup() into main() and drop the
> > > rest.
> > > ---
> > > fftools/ffprobe.c | 22 ++++++++--------------
> > > 1 file changed, 8 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> > > index e234c92904..a39185f6fe 100644
> > > --- a/fftools/ffprobe.c
> > > +++ b/fftools/ffprobe.c
> > > @@ -381,17 +381,6 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
> > > #endif
> > > }
> > >
> >
> >
> > [...]
> >
> > > @@ -4124,8 +4112,10 @@ int main(int argc, char **argv)
> > >
> > > show_banner(argc, argv, options);
> > > ret = parse_options(NULL, argc, argv, options, opt_input_file);
> > > - if (ret < 0)
> > > - exit_program(ret == AVERROR_EXIT ? 0 : 1);
> > > + if (ret < 0) {
> > > + ret = AVERROR_EXIT ? 0 : ret;
> >
> > This looks unintended.
>
> Which part of it and why?
Never mind, I see it now. I'll send a patch.
Thanks,
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* Re: [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program()
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program() Anton Khirnov
2023-07-20 20:35 ` Marton Balint
@ 2023-08-02 5:32 ` Stefano Sabatini
1 sibling, 0 replies; 53+ messages in thread
From: Stefano Sabatini @ 2023-08-02 5:32 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On date Saturday 2023-07-15 12:46:10 +0200, Anton Khirnov wrote:
> Inline the relevant part of ffprobe_cleanup() into main() and drop the
> rest.
> ---
> fftools/ffprobe.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index e234c92904..a39185f6fe 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -381,17 +381,6 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
> #endif
> }
>
> -static void ffprobe_cleanup(int ret)
> -{
> - int i;
> - for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
> - av_dict_free(&(sections[i].entries_to_show));
> -
Was this part discarded? This is mostly needed to avoid valgrind
warnings.
LGTM otherwise.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* [FFmpeg-devel] [PATCH 47/47] fftools/ffmpeg: stop calling exit_program()
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (44 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program() Anton Khirnov
@ 2023-07-15 10:46 ` Anton Khirnov
2023-07-20 18:56 ` [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-15 10:46 UTC (permalink / raw)
To: ffmpeg-devel
Remove exit_program() and register_exit(), as they are no longer used.
---
fftools/cmdutils.c | 15 ---------------
fftools/cmdutils.h | 10 ----------
fftools/ffmpeg.c | 4 +---
3 files changed, 1 insertion(+), 28 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index bceb778ff0..8a3b4bd285 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -83,21 +83,6 @@ void init_dynload(void)
#endif
}
-static void (*program_exit)(int ret);
-
-void register_exit(void (*cb)(int ret))
-{
- program_exit = cb;
-}
-
-void exit_program(int ret)
-{
- if (program_exit)
- program_exit(ret);
-
- exit(ret);
-}
-
int parse_number(const char *context, const char *numstr, int type,
double min, double max, double *dst)
{
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index cc2180f768..4779b280fd 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -49,16 +49,6 @@ extern AVDictionary *swr_opts;
extern AVDictionary *format_opts, *codec_opts;
extern int hide_banner;
-/**
- * Register a program-specific cleanup routine.
- */
-void register_exit(void (*cb)(int ret));
-
-/**
- * Wraps exit with a program-specific cleanup routine.
- */
-void exit_program(int ret) av_noreturn;
-
/**
* Initialize dynamic library loading
*/
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ecb3f89f85..6130fd06fc 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1324,8 +1324,6 @@ int main(int argc, char **argv)
init_dynload();
- register_exit(ffmpeg_cleanup);
-
setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
av_log_set_flags(AV_LOG_SKIP_REPEATED);
@@ -1376,6 +1374,6 @@ finish:
if (ret == AVERROR_EXIT)
ret = 0;
- exit_program(ret);
+ ffmpeg_cleanup(ret);
return ret;
}
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness
2023-07-15 10:45 [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
` (45 preceding siblings ...)
2023-07-15 10:46 ` [FFmpeg-devel] [PATCH 47/47] fftools/ffmpeg: " Anton Khirnov
@ 2023-07-20 18:56 ` Anton Khirnov
46 siblings, 0 replies; 53+ messages in thread
From: Anton Khirnov @ 2023-07-20 18:56 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Pushed the set except for deprecating the "smart" pixfmt selection, on
which there is no consensus yet.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 53+ messages in thread