From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/8] fftools/ffmpeg_mux_init: move more code from of_open() to create_streams()
Date: Mon, 14 Nov 2022 16:13:44 +0100
Message-ID: <20221114151350.5134-2-anton@khirnov.net> (raw)
In-Reply-To: <20221114151350.5134-1-anton@khirnov.net>
Specificaly, the of_add_attachments() call (which can add attachment
streams to the output) and the check whether the output file contains
any streams. They both logically belong in create_streams().
---
fftools/ffmpeg_mux_init.c | 99 ++++++++++++++++++++-------------------
1 file changed, 50 insertions(+), 49 deletions(-)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 4755a2cc38..303bf25096 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1062,8 +1062,50 @@ loop_end:
}
}
+static void of_add_attachments(Muxer *mux, const OptionsContext *o)
+{
+ OutputStream *ost;
+ int err;
+
+ for (int i = 0; i < o->nb_attachments; i++) {
+ AVIOContext *pb;
+ uint8_t *attachment;
+ const char *p;
+ int64_t len;
+
+ if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
+ av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
+ o->attachments[i]);
+ exit_program(1);
+ }
+ if ((len = avio_size(pb)) <= 0) {
+ av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
+ o->attachments[i]);
+ exit_program(1);
+ }
+ if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
+ !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
+ av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
+ o->attachments[i]);
+ exit_program(1);
+ }
+ avio_read(pb, attachment, len);
+ memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+ ost = new_attachment_stream(mux, o, -1);
+ ost->attachment_filename = o->attachments[i];
+ ost->st->codecpar->extradata = attachment;
+ ost->st->codecpar->extradata_size = len;
+
+ p = strrchr(o->attachments[i], '/');
+ av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
+ avio_closep(&pb);
+ }
+}
+
static void create_streams(Muxer *mux, const OptionsContext *o)
{
+ 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;
@@ -1101,6 +1143,14 @@ static void create_streams(Muxer *mux, const OptionsContext *o)
for (int i = 0; i < o->nb_stream_maps; i++)
map_manual(mux, o, &o->stream_maps[i]);
}
+
+ of_add_attachments(mux, o);
+
+ if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
+ av_dump_format(oc, nb_output_files - 1, oc->url, 1);
+ av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
+ exit_program(1);
+ }
}
static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_us)
@@ -1194,47 +1244,6 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u
return 0;
}
-static void of_add_attachments(Muxer *mux, const OptionsContext *o)
-{
- OutputStream *ost;
- int err;
-
- for (int i = 0; i < o->nb_attachments; i++) {
- AVIOContext *pb;
- uint8_t *attachment;
- const char *p;
- int64_t len;
-
- if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
- av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
- o->attachments[i]);
- exit_program(1);
- }
- if ((len = avio_size(pb)) <= 0) {
- av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
- o->attachments[i]);
- exit_program(1);
- }
- if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
- !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
- av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
- o->attachments[i]);
- exit_program(1);
- }
- avio_read(pb, attachment, len);
- memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
-
- ost = new_attachment_stream(mux, o, -1);
- ost->attachment_filename = o->attachments[i];
- ost->st->codecpar->extradata = attachment;
- ost->st->codecpar->extradata_size = len;
-
- p = strrchr(o->attachments[i], '/');
- av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
- avio_closep(&pb);
- }
-}
-
static void of_add_programs(AVFormatContext *oc, const OptionsContext *o)
{
/* process manually set programs */
@@ -1782,14 +1791,6 @@ int of_open(const OptionsContext *o, const char *filename)
/* create all output streams for this file */
create_streams(mux, o);
- of_add_attachments(mux, o);
-
- if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
- av_dump_format(oc, nb_output_files - 1, oc->url, 1);
- av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
- exit_program(1);
- }
-
/* check if all codec options have been used */
unused_opts = strip_specifiers(o->g->codec_opts);
for (int i = 0; i < of->nb_streams; i++) {
--
2.35.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:[~2022-11-14 15:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 15:13 [FFmpeg-devel] [PATCH 1/8] fftools/ffmpeg: simplify ost_iter() Anton Khirnov
2022-11-14 15:13 ` Anton Khirnov [this message]
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 3/8] fftools/ffmpeg: stop handling max_frames in do_video_out() Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 4/8] fftools/ffmpeg: move OutputStream.max_frames to MuxStream Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 5/8] fftools/ffmpeg_mux_init: move validating codec avoptions to a separate function Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 6/8] fftools/ffmpeg_mux_init: do not call av{codec, format}_get_class() repeatedly Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 7/8] fftools/ffmpeg_mux_init: use av_dict_iterate() where appropriate Anton Khirnov
2022-11-14 15:13 ` [FFmpeg-devel] [PATCH 8/8] fftools/ffmpeg_mux_init: drop an always-false check Anton Khirnov
2022-11-14 17:29 ` [FFmpeg-devel] [PATCH 1/8] fftools/ffmpeg: simplify ost_iter() Soft Works
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=20221114151350.5134-2-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