diff mbox series

[FFmpeg-devel,6/6] avformat/argo_asf: strip file extension from name

Message ID 20200808075914.2296555-6-zane@zanevaniperen.com
State Superseded
Headers show
Series [FFmpeg-devel,1/6] avformat/argo_asf: don't check or probe file version
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Zane van Iperen Aug. 8, 2020, 8:01 a.m. UTC
Only when the user hasn't manually specified one.
Matches the original files more closely.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
---
 libavformat/argo_asf.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index 3499519903..779f27c860 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -302,10 +302,25 @@  static int argo_asf_write_header(AVFormatContext *s)
     /* version_{major,minor} set by options. */
     ctx->fhdr.num_chunks         = 1;
     ctx->fhdr.chunk_offset       = ASF_FILE_HEADER_SIZE;
-    if (ctx->name)
+
+    /*
+     * If the user specified a name, use it as is. Otherwise take the
+     * basename and lop off the extension (if any).
+     */
+    if (ctx->name) {
         strncpy(ctx->fhdr.name, ctx->name, FF_ARRAY_ELEMS(ctx->fhdr.name));
-    else
-        strncpy(ctx->fhdr.name, av_basename(s->url), FF_ARRAY_ELEMS(ctx->fhdr.name));
+    } else {
+        const char *start = av_basename(s->url);
+        const char *end   = strrchr(start, '.');
+        size_t      len;
+
+        if(end)
+            len = end - start;
+        else
+            len = strlen(start);
+
+        memcpy(ctx->fhdr.name, start, FFMIN(len, FF_ARRAY_ELEMS(ctx->fhdr.name)));
+    }
 
     ctx->ckhdr.num_blocks        = 0;
     ctx->ckhdr.num_samples       = ASF_SAMPLE_COUNT;