[FFmpeg-devel] [PATCH v6 1/2] avformat/img2enc: seperate getting frame filename
Marton Balint
cus at passwd.hu
Wed Sep 25 10:55:52 EEST 2024
On Sun, 22 Sep 2024, Marcus B Spencer wrote:
> Seperate the action of getting the frame filename in write_packet into
> the function ff_img_get_frame_filename.
>
> This for img2-like muxers that need this functionality.
But why don't you simply extend img2 muxer/demuxer with this image format?
That seems the right place, not a separate demuxer / demuxer.
Thanks,
Marton
>
> Signed-off-by: Marcus B Spencer <marcus at marcusspencer.xyz>
> ---
> Identical to v1.
>
> libavformat/img2.h | 5 +++++
> libavformat/img2enc.c | 41 +++++++++++++++++++++++++++--------------
> 2 files changed, 32 insertions(+), 14 deletions(-)
>
> diff --git a/libavformat/img2.h b/libavformat/img2.h
> index e98902c96f..292b90bdbf 100644
> --- a/libavformat/img2.h
> +++ b/libavformat/img2.h
> @@ -76,4 +76,9 @@ extern const AVOption ff_img_options[];
> int ff_img_read_header(AVFormatContext *s1);
>
> int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt);
> +
> +int ff_img_get_frame_filename(AVFormatContext *s, char *filename,
> + size_t filename_len, int start_img_number,
> + int img_number);
> +
> #endif
> diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
> index 526a11e5ee..ec2941e293 100644
> --- a/libavformat/img2enc.c
> +++ b/libavformat/img2enc.c
> @@ -137,6 +137,28 @@ static int write_and_close(AVFormatContext *s, AVIOContext **pb, const unsigned
> return ff_format_io_close(s, pb);
> }
>
> +int ff_img_get_frame_filename(AVFormatContext *s, char *filename,
> + size_t filename_len, int start_img_number,
> + int img_number)
> +{
> + if (av_get_frame_filename2(filename, filename_len, s->url,
> + img_number,
> + AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
> + if (img_number == start_img_number) {
> + av_log(s, AV_LOG_WARNING, "The specified filename '%s' does not contain an image sequence pattern or a pattern is invalid.\n", s->url);
> + av_log(s, AV_LOG_WARNING,
> + "Use a pattern such as %%03d for an image sequence or "
> + "use the -update option (with -frames:v 1 if needed) to write a single image.\n");
> + av_strlcpy(filename, s->url, filename_len);
> + } else {
> + av_log(s, AV_LOG_ERROR, "Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?\n");
> + return AVERROR(EINVAL);
> + }
> + }
> +
> + return 0;
> +}
> +
> static int write_packet(AVFormatContext *s, AVPacket *pkt)
> {
> VideoMuxData *img = s->priv_data;
> @@ -164,20 +186,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
> av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the frames.");
> return AVERROR(EINVAL);
> }
> - } else if (av_get_frame_filename2(filename, sizeof(filename), s->url,
> - img->img_number,
> - AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
> - if (img->img_number == img->start_img_number) {
> - av_log(s, AV_LOG_WARNING, "The specified filename '%s' does not contain an image sequence pattern or a pattern is invalid.\n", s->url);
> - av_log(s, AV_LOG_WARNING,
> - "Use a pattern such as %%03d for an image sequence or "
> - "use the -update option (with -frames:v 1 if needed) to write a single image.\n");
> - av_strlcpy(filename, s->url, sizeof(filename));
> - } else {
> - av_log(s, AV_LOG_ERROR, "Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?\n");
> - return AVERROR(EINVAL);
> - }
> - }
> + } else if ((ret = ff_img_get_frame_filename(s, filename, sizeof(filename),
> + img->start_img_number,
> + img->img_number)) < 0)
> + return ret;
> +
> for (i = 0; i < 4; i++) {
> av_dict_copy(&options, img->protocol_opts, 0);
> snprintf(img->tmp[i], sizeof(img->tmp[i]), "%s.tmp", filename);
> --
> 2.46.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
More information about the ffmpeg-devel
mailing list