From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 10/33] fftools/ffmpeg_mux_init: return error codes from map_*() instead of aborting
Date: Thu, 13 Jul 2023 12:55:30 +0200
Message-ID: <20230713105553.21052-10-anton@khirnov.net> (raw)
In-Reply-To: <20230713105553.21052-1-anton@khirnov.net>
---
fftools/ffmpeg_mux_init.c | 92 +++++++++++++++++++++++----------------
1 file changed, 55 insertions(+), 37 deletions(-)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 47b6f826b6..8e640610cd 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1297,7 +1297,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
return ost;
}
-static void map_auto_video(Muxer *mux, const OptionsContext *o)
+static int map_auto_video(Muxer *mux, const OptionsContext *o)
{
AVFormatContext *oc = mux->fc;
InputStream *best_ist = NULL;
@@ -1306,7 +1306,7 @@ static void map_auto_video(Muxer *mux, const OptionsContext *o)
/* video: highest resolution */
if (av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_VIDEO) == AV_CODEC_ID_NONE)
- return;
+ return 0;
qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
for (int j = 0; j < nb_input_files; j++) {
@@ -1346,9 +1346,11 @@ static void map_auto_video(Muxer *mux, const OptionsContext *o)
}
if (best_ist)
ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist, NULL);
+
+ return 0;
}
-static void map_auto_audio(Muxer *mux, const OptionsContext *o)
+static int map_auto_audio(Muxer *mux, const OptionsContext *o)
{
AVFormatContext *oc = mux->fc;
InputStream *best_ist = NULL;
@@ -1356,7 +1358,7 @@ static void map_auto_audio(Muxer *mux, const OptionsContext *o)
/* audio: most channels */
if (av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_AUDIO) == AV_CODEC_ID_NONE)
- return;
+ return 0;
for (int j = 0; j < nb_input_files; j++) {
InputFile *ifile = input_files[j];
@@ -1388,9 +1390,11 @@ static void map_auto_audio(Muxer *mux, const OptionsContext *o)
}
if (best_ist)
ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist, NULL);
+
+ return 0;
}
-static void map_auto_subtitle(Muxer *mux, const OptionsContext *o)
+static int map_auto_subtitle(Muxer *mux, const OptionsContext *o)
{
AVFormatContext *oc = mux->fc;
char *subtitle_codec_name = NULL;
@@ -1398,7 +1402,7 @@ static void map_auto_subtitle(Muxer *mux, const OptionsContext *o)
/* subtitles: pick first */
MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
if (!avcodec_find_encoder(oc->oformat->subtitle_codec) && !subtitle_codec_name)
- return;
+ return 0;
for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist))
if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
@@ -1426,16 +1430,18 @@ static void map_auto_subtitle(Muxer *mux, const OptionsContext *o)
break;
}
}
+
+ return 0;
}
-static void map_auto_data(Muxer *mux, const OptionsContext *o)
+static int map_auto_data(Muxer *mux, const OptionsContext *o)
{
AVFormatContext *oc = mux->fc;
/* Data only if codec id match */
enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_DATA);
if (codec_id == AV_CODEC_ID_NONE)
- return;
+ return 0;
for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
if (ist->user_set_discard == AVDISCARD_ALL)
@@ -1444,14 +1450,16 @@ static void map_auto_data(Muxer *mux, const OptionsContext *o)
ist->st->codecpar->codec_id == codec_id )
ost_add(mux, o, AVMEDIA_TYPE_DATA, ist, NULL);
}
+
+ return 0;
}
-static void map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map)
+static int map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map)
{
InputStream *ist;
if (map->disabled)
- return;
+ return 0;
if (map->linklabel) {
FilterGraph *fg;
@@ -1472,7 +1480,7 @@ loop_end:
if (!ofilter) {
av_log(mux, AV_LOG_FATAL, "Output with label '%s' does not exist "
"in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
- exit_program(1);
+ return AVERROR(EINVAL);
}
av_log(mux, AV_LOG_VERBOSE, "Creating output stream from an explicitly "
@@ -1484,16 +1492,16 @@ loop_end:
if (ist->user_set_discard == AVDISCARD_ALL) {
av_log(mux, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
map->file_index, map->stream_index);
- exit_program(1);
+ return AVERROR(EINVAL);
}
if(o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
- return;
+ return 0;
if(o-> audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
- return;
+ return 0;
if(o-> video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
- return;
+ return 0;
if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
- return;
+ return 0;
if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN &&
!copy_unknown_streams) {
@@ -1505,13 +1513,15 @@ loop_end:
"If you want unsupported types ignored instead "
"of failing, please use the -ignore_unknown option\n"
"If you want them copied, please use -copy_unknown\n");
- exit_program(1);
+ return AVERROR(EINVAL);
}
- return;
+ return 0;
}
ost_add(mux, o, ist->st->codecpar->codec_type, ist, NULL);
}
+
+ return 0;
}
static int of_add_attachments(Muxer *mux, const OptionsContext *o)
@@ -1583,11 +1593,21 @@ read_fail:
static int create_streams(Muxer *mux, const OptionsContext *o)
{
+ static const int (*map_func[])(Muxer *mux, const OptionsContext *o) = {
+ [AVMEDIA_TYPE_VIDEO] = map_auto_video,
+ [AVMEDIA_TYPE_AUDIO] = map_auto_audio,
+ [AVMEDIA_TYPE_SUBTITLE] = map_auto_subtitle,
+ [AVMEDIA_TYPE_DATA] = map_auto_data,
+ };
+
AVFormatContext *oc = mux->fc;
- int auto_disable_v = o->video_disable;
- int auto_disable_a = o->audio_disable;
- int auto_disable_s = o->subtitle_disable;
- int auto_disable_d = o->data_disable;
+
+ int auto_disable =
+ o->video_disable * (1 << AVMEDIA_TYPE_VIDEO) |
+ o->audio_disable * (1 << AVMEDIA_TYPE_AUDIO) |
+ o->subtitle_disable * (1 << AVMEDIA_TYPE_SUBTITLE) |
+ o->data_disable * (1 << AVMEDIA_TYPE_DATA);
+
int ret;
/* create streams for all unlabeled output pads */
@@ -1599,11 +1619,7 @@ static int create_streams(Muxer *mux, const OptionsContext *o)
if (ofilter->linklabel || ofilter->ost)
continue;
- switch (ofilter->type) {
- case AVMEDIA_TYPE_VIDEO: auto_disable_v = 1; break;
- case AVMEDIA_TYPE_AUDIO: auto_disable_a = 1; break;
- case AVMEDIA_TYPE_SUBTITLE: auto_disable_s = 1; break;
- }
+ auto_disable |= 1 << ofilter->type;
av_log(mux, AV_LOG_VERBOSE, "Creating output stream from unlabeled "
"output of complex filtergraph %d.", fg->index);
@@ -1620,19 +1636,21 @@ static int create_streams(Muxer *mux, const OptionsContext *o)
av_log(mux, AV_LOG_VERBOSE, "No explicit maps, mapping streams automatically...\n");
/* pick the "best" stream of each type */
- if (!auto_disable_v)
- map_auto_video(mux, o);
- if (!auto_disable_a)
- map_auto_audio(mux, o);
- if (!auto_disable_s)
- map_auto_subtitle(mux, o);
- if (!auto_disable_d)
- map_auto_data(mux, o);
+ for (int i = 0; i < FF_ARRAY_ELEMS(map_func); i++) {
+ if (!map_func[i] || auto_disable & (1 << i))
+ continue;
+ ret = map_func[i](mux, o);
+ if (ret < 0)
+ return ret;
+ }
} else {
av_log(mux, AV_LOG_VERBOSE, "Adding streams from explicit maps...\n");
- for (int i = 0; i < o->nb_stream_maps; i++)
- map_manual(mux, o, &o->stream_maps[i]);
+ for (int i = 0; i < o->nb_stream_maps; i++) {
+ ret = map_manual(mux, o, &o->stream_maps[i]);
+ if (ret < 0)
+ return ret;
+ }
}
ret = of_add_attachments(mux, o);
--
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".
next prev parent reply other threads:[~2023-07-13 11:00 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-13 10:55 [FFmpeg-devel] [PATCH 01/33] fftools/ffmpeg_mux_init: return errors from of_open() " Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 02/33] fftools/ffmpeg_demux: return errors from ifile_open() " Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 03/33] fftools/ffmpeg_demux: drop a redundant avio_flush() Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 04/33] fftools/ffmpeg_demux: forward errors from dump_attachment() instead of aborting Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 05/33] fftools/ffmpeg_demux: add logging for -dump_attachment Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 06/33] fftools/ffmpeg: return errors from assert_file_overwrite() instead of aborting Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 07/33] fftools/ffmpeg_demux: return errors from ist_add() " Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 08/33] fftools/ffmpeg_mux_init: return errors from create_streams() " Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 09/33] fftools/ffmpeg_mux_init: improve error handling in of_add_attachments() Anton Khirnov
2023-07-13 10:55 ` Anton Khirnov [this message]
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 11/33] fftools/ffmpeg_mux_init: move allocation out of prologue Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 12/33] fftools/ffmpeg_mux_init: return error codes from ost_add() instead of aborting Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 13/33] fftools/ffmpeg_mux_init: return error codes from copy_meta() " Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 14/33] fftools/ffmpeg_mux_init: return error codes from parse_forced_key_frames() " Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 15/33] fftools/ffmpeg_mux_init: return error codes from validate_enc_avopt() " Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 16/33] fftools/ffmpeg_mux_init: improve of_add_programs() Anton Khirnov
2023-07-13 23:30 ` Michael Niedermayer
2023-07-14 9:07 ` Anton Khirnov
2023-07-14 18:12 ` Michael Niedermayer
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 17/33] fftools/ffmpeg_mux_init: return error codes from metadata processing instead of aborting Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 18/33] fftools/ffmpeg_mux_init: replace all remaining aborts with returning error codes Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 19/33] fftools/ffmpeg: return an error instead of aborting Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 20/33] fftools/ffmpeg: handle error codes from process_input_packet() Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 21/33] fftools/ffmpeg_mux: return errors from of_streamcopy() instead of aborting Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 22/33] fftools/ffmpeg_enc: return errors from enc_subtitle() " Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 23/33] fftools/ffmpeg_mux_init: drop an obsolete assignment Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 24/33] fftools/ffmpeg_mux_init: handle pixel format endianness Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 25/33] fftools/ffmpeg_filter: stop disregarding user-specified pixel format Anton Khirnov
2023-07-13 23:11 ` Michael Niedermayer
2023-07-14 9:44 ` Anton Khirnov
2023-07-14 10:20 ` Timo Rothenpieler
2023-07-14 15:47 ` Michael Niedermayer
2023-07-14 17:06 ` Anton Khirnov
2023-07-15 8:59 ` Paul B Mahol
2023-07-15 20:01 ` Michael Niedermayer
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 26/33] fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 27/33] fftools/ffmpeg: rework initializing encoders with no frames Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 28/33] fftools/ffmpeg_filter: only flush vsync code if encoding actually started Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 29/33] fftools/ffmpeg_enc: initialize audio/video encoders from frame parameters Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 30/33] fftools/ffmpeg_filter: make OutputFilter.filter private Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 31/33] fftools/ffmpeg: add more structure to FrameData Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 32/33] fftools/ffmpeg: rework -enc_time_base handling Anton Khirnov
2023-07-13 10:55 ` [FFmpeg-devel] [PATCH 33/33] doc/ffmpeg: fix -enc_time_base documentation Anton Khirnov
2023-07-13 12:01 ` [FFmpeg-devel] [PATCH 01/33] fftools/ffmpeg_mux_init: return errors from of_open() instead of aborting "zhilizhao(赵志立)"
2023-07-13 13:01 ` Anton Khirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230713105553.21052-10-anton@khirnov.net \
--to=anton@khirnov.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git