[FFmpeg-devel] [PATCH 6/6] avformat/argo_asf: strip file extension from name
Zane van Iperen
zane at zanevaniperen.com
Sat Aug 8 11:01:29 EEST 2020
Only when the user hasn't manually specified one.
Matches the original files more closely.
Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>
---
libavformat/argo_asf.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
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;
--
2.25.1
More information about the ffmpeg-devel
mailing list