diff mbox series

[FFmpeg-devel,7/9] lavf/img2enc: avoid a useless copy of the url

Message ID 20211125150500.25040-7-anton@khirnov.net
State Accepted
Commit c0e46ad9a97628b7af78c21c4628f878ca658184
Headers show
Series [FFmpeg-devel,1/9] lavd/jack: increase buffer size for snprintf() | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Anton Khirnov Nov. 25, 2021, 3:04 p.m. UTC
img2enc keeps a private (and possibly truncated) copy of the url that is
never modified. Just use AVFormatContext.url instead.
---
 libavformat/img2enc.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Andreas Rheinhardt Nov. 26, 2021, 5:52 p.m. UTC | #1
Anton Khirnov:
> img2enc keeps a private (and possibly truncated) copy of the url that is
> never modified. Just use AVFormatContext.url instead.
> ---
>  libavformat/img2enc.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
> index 62202de9f4..44895490e6 100644
> --- a/libavformat/img2enc.c
> +++ b/libavformat/img2enc.c
> @@ -36,7 +36,6 @@ typedef struct VideoMuxData {
>      const AVClass *class;  /**< Class for private options. */
>      int img_number;
>      int split_planes;       /**< use independent file for each Y, U, V plane */
> -    char path[1024];
>      char tmp[4][1024];
>      char target[4][1024];
>      int update;
> @@ -53,14 +52,12 @@ static int write_header(AVFormatContext *s)
>      AVStream *st = s->streams[0];
>      const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codecpar->format);
>  
> -    av_strlcpy(img->path, s->url, sizeof(img->path));
> -
>      if (st->codecpar->codec_id == AV_CODEC_ID_GIF) {
>          img->muxer = "gif";
>      } else if (st->codecpar->codec_id == AV_CODEC_ID_FITS) {
>          img->muxer = "fits";
>      } else if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) {
> -        const char *str = strrchr(img->path, '.');
> +        const char *str = strrchr(s->url, '.');
>          img->split_planes =     str
>                               && !av_strcasecmp(str + 1, "y")
>                               && s->nb_streams == 1
> @@ -136,29 +133,29 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
>      AVDictionary *options = NULL;
>  
>      if (img->update) {
> -        av_strlcpy(filename, img->path, sizeof(filename));
> +        av_strlcpy(filename, s->url, sizeof(filename));
>      } else if (img->use_strftime) {
>          time_t now0;
>          struct tm *tm, tmpbuf;
>          time(&now0);
>          tm = localtime_r(&now0, &tmpbuf);
> -        if (!strftime(filename, sizeof(filename), img->path, tm)) {
> +        if (!strftime(filename, sizeof(filename), s->url, tm)) {
>              av_log(s, AV_LOG_ERROR, "Could not get frame filename with strftime\n");
>              return AVERROR(EINVAL);
>          }
>      } else if (img->frame_pts) {
> -        if (av_get_frame_filename2(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
> +        if (av_get_frame_filename2(filename, sizeof(filename), s->url, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
>              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), img->path,
> +    } else if (av_get_frame_filename2(filename, sizeof(filename), s->url,
>                                        img->img_number,
>                                        AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 &&
>                 img->img_number > 1) {
>          av_log(s, AV_LOG_ERROR,
>                 "Could not get frame filename number %d from pattern '%s'. "
>                 "Use '-frames:v 1' for a single image, or '-update' option, or use a pattern such as %%03d within the filename.\n",
> -               img->img_number, img->path);
> +               img->img_number, s->url);
>          return AVERROR(EINVAL);
>      }
>      for (i = 0; i < 4; i++) {
> 

LGTM.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 62202de9f4..44895490e6 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -36,7 +36,6 @@  typedef struct VideoMuxData {
     const AVClass *class;  /**< Class for private options. */
     int img_number;
     int split_planes;       /**< use independent file for each Y, U, V plane */
-    char path[1024];
     char tmp[4][1024];
     char target[4][1024];
     int update;
@@ -53,14 +52,12 @@  static int write_header(AVFormatContext *s)
     AVStream *st = s->streams[0];
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codecpar->format);
 
-    av_strlcpy(img->path, s->url, sizeof(img->path));
-
     if (st->codecpar->codec_id == AV_CODEC_ID_GIF) {
         img->muxer = "gif";
     } else if (st->codecpar->codec_id == AV_CODEC_ID_FITS) {
         img->muxer = "fits";
     } else if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) {
-        const char *str = strrchr(img->path, '.');
+        const char *str = strrchr(s->url, '.');
         img->split_planes =     str
                              && !av_strcasecmp(str + 1, "y")
                              && s->nb_streams == 1
@@ -136,29 +133,29 @@  static int write_packet(AVFormatContext *s, AVPacket *pkt)
     AVDictionary *options = NULL;
 
     if (img->update) {
-        av_strlcpy(filename, img->path, sizeof(filename));
+        av_strlcpy(filename, s->url, sizeof(filename));
     } else if (img->use_strftime) {
         time_t now0;
         struct tm *tm, tmpbuf;
         time(&now0);
         tm = localtime_r(&now0, &tmpbuf);
-        if (!strftime(filename, sizeof(filename), img->path, tm)) {
+        if (!strftime(filename, sizeof(filename), s->url, tm)) {
             av_log(s, AV_LOG_ERROR, "Could not get frame filename with strftime\n");
             return AVERROR(EINVAL);
         }
     } else if (img->frame_pts) {
-        if (av_get_frame_filename2(filename, sizeof(filename), img->path, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
+        if (av_get_frame_filename2(filename, sizeof(filename), s->url, pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
             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), img->path,
+    } else if (av_get_frame_filename2(filename, sizeof(filename), s->url,
                                       img->img_number,
                                       AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 &&
                img->img_number > 1) {
         av_log(s, AV_LOG_ERROR,
                "Could not get frame filename number %d from pattern '%s'. "
                "Use '-frames:v 1' for a single image, or '-update' option, or use a pattern such as %%03d within the filename.\n",
-               img->img_number, img->path);
+               img->img_number, s->url);
         return AVERROR(EINVAL);
     }
     for (i = 0; i < 4; i++) {