From patchwork Sun Aug 9 23:45:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 21572 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4391944A560 for ; Mon, 10 Aug 2020 02:45:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2937768AD4D; Mon, 10 Aug 2020 02:45:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40136.protonmail.ch (mail-40136.protonmail.ch [185.70.40.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C5E686881F1 for ; Mon, 10 Aug 2020 02:45:38 +0300 (EEST) Date: Sun, 09 Aug 2020 23:45:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail; t=1597016738; bh=IiM3aS6TrWqL19UpS+cyJtIO4fVZgYp/3MgSmeseWpI=; h=Date:To:From:Cc:Reply-To:Subject:From; b=lR/4UyeDIkyMoykoz/8Fh8RAgnhbmjXFN8R52+bt5rm0lBnVrK5rpe8FHiHKfsyeZ D5v+cVzY2z4McCbjmPLCjElvhfb4ekLW29XNIwkrMVVZAkQtzwuSGMsmPu+jt463kn y/ooWzCLn3NgNVFRggqZpP0PnKxyWbJ5G8JyZyOM= To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200809234441.2365933-5-zane@zanevaniperen.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mail.protonmail.ch Subject: [FFmpeg-devel] [PATCH v3 5/5] avformat/argo_asf: strip file extension from name X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Only when the user hasn't manually specified one. Matches the original files more closely. Signed-off-by: Zane van Iperen --- libavformat/argo_asf.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c index 577b9d9c01..37ad2bf5e9 100644 --- a/libavformat/argo_asf.c +++ b/libavformat/argo_asf.c @@ -329,10 +329,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;