diff mbox series

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

Message ID 20200808133717.2311422-4-zane@zanevaniperen.com
State Superseded
Headers show
Series [FFmpeg-devel,v2,1/4] 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, 1:38 p.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 | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index 7eaf2fec73..371c10f7c8 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -310,10 +310,24 @@  static int argo_asf_write_header(AVFormatContext *s)
     fhdr.version_minor = (uint16_t)ctx->version_minor;
     fhdr.num_chunks    = 1;
     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(fhdr.name, ctx->name, sizeof(fhdr.name));
-    else
-        strncpy(fhdr.name, av_basename(s->url), sizeof(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(fhdr.name, start, FFMIN(len, sizeof(fhdr.name)));
+    }
 
     chdr.num_blocks    = 0;
     chdr.num_samples   = ASF_SAMPLE_COUNT;