From patchwork Sun Apr 23 04:11:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sharpbai X-Patchwork-Id: 3476 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp929849vsd; Sat, 22 Apr 2017 21:19:19 -0700 (PDT) X-Received: by 10.223.164.6 with SMTP id d6mr296966wra.144.1492921159815; Sat, 22 Apr 2017 21:19:19 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s206si8916920wmf.36.2017.04.22.21.19.19; Sat, 22 Apr 2017 21:19:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 45D006883C3; Sun, 23 Apr 2017 07:19:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f177.google.com (mail-io0-f177.google.com [209.85.223.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 733F268833D for ; Sun, 23 Apr 2017 07:19:08 +0300 (EEST) Received: by mail-io0-f177.google.com with SMTP id a103so152942530ioj.1 for ; Sat, 22 Apr 2017 21:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=u2qiLbijM4elBYczBRHAmGcI4lmuqecQgiWtv3mzrvk=; b=crfoKavv3AAlLc8VLFXjom/gWG+0tm634F9FkNilE5mlieL8dBKrlm+NdwyChLq9eZ 9zqp/6vWZxUulrp8BTNntt37Sd5p4J/lpunC/5g0tEyIOLprNPJUeIfHr91KCwMGvtzC SLCfiz5eNi0YogvIs7kew9Hg83G3k/kEVbJg4pUP/vobdlSSpUCw1dPjDo5+2lKbmKKF cuvOkXhqLqbu2T6ZYnqGwJLDYdTTe5K8NBUdqVX4+capxOAjGZof1kePfgh+1ffzA5Fn hPm9y8mma1AiOKRC0kr6kesBUb8u0lqhOQIXp2jvmcngvTol62off90pVHSr1ddbHX8c W4Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=u2qiLbijM4elBYczBRHAmGcI4lmuqecQgiWtv3mzrvk=; b=dHl4RnmuuxyPRoDq1Oa1SLyLrvQqL3Dfkj8vOp4+wqqQGsWmMCj2iXSQS8bePmaoAB ehBPzNjEKJ5lEkkdxQu0JdYM4IqPqRPeTmKzJFnIpyoJNrbQGf+g/h3g9BDr5D5qVSm6 PAxP+MAzpZepxuGzCVAk43soknwVmP5r9NBQnjTmkTpd3N7HEzt0zdv4UgOZ3Ggh7vZY R/Ixt4d61LaX5cOcr9Nb4QHaPU5XRwoDM3cCHBPkm+ti+w/E9VXLy3bxWCA7zWZBNUWi BUOpcGUE4/fIDTio4CGQBO8vlXAoqn3LhnjbS74Qi0im1rovRYapJHtLLvycT+jH0cpr c4SA== X-Gm-Message-State: AN3rC/48HjGTHalgRWNQbc/xoArET4HBJOqgPDF5nvMCfQLRBMi1CuZH Zoz5LFQ2jexX7A== X-Received: by 10.98.34.212 with SMTP id p81mr19094964pfj.118.1492920729667; Sat, 22 Apr 2017 21:12:09 -0700 (PDT) Received: from localhost.localdomain (li377-58.members.linode.com. [106.187.34.58]) by smtp.gmail.com with ESMTPSA id e22sm23721787pgn.11.2017.04.22.21.12.07 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 22 Apr 2017 21:12:09 -0700 (PDT) From: sharpbai@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 23 Apr 2017 12:11:51 +0800 Message-Id: <1492920711-7569-1-git-send-email-sharpbai@gmail.com> X-Mailer: git-send-email 2.2.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavformat/mp3enc: Notify to add "-write_xing false" in CBR mode 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: sharpbai Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: sharpbai Encoding a CBR mp3 file without "-write_xing false" may result in mp3 file duration incorect on ios safari browser and webview. I try to fix it but it can’t be done as mp3 muxer don’t know it is a CBR file until encode process finished. And it’s hard to remove the first frame at that time. Only the mp3 encoder (such as libmp3lame) know it is CBR or not before encoding start. Bug example: ffmpeg -i a.mp3 -c:a mp3 -ab 32k -ar 44100 -ac 1 b.mp3 The duration of the generated file b.mp3 is wrong on ios safari browser from ios7 to ios10. Working example: ffmpeg -i a.mp3 -c:a mp3 -ab 32k -ar 44100 -ac 1 \ -write_xing false b.mp3 --- libavformat/mp3enc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 3cbf7bd..a55dbf4 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -395,8 +395,13 @@ static void mp3_update_xing(AVFormatContext *s) int i, rg_size; /* replace "Xing" identification string with "Info" for CBR files. */ - if (!mp3->has_variable_bitrate) + if (!mp3->has_variable_bitrate) { AV_WL32(mp3->xing_frame + mp3->xing_offset, MKTAG('I', 'n', 'f', 'o')); + av_log(s, AV_LOG_WARNING, + "This is a CBR mp3 file. But its first frame header might be wrong, " + "which result in file duration incorrect on ios browser. " + "Please add \"-write_xing false\" to avoid this problem.\n"); + } AV_WB32(mp3->xing_frame + mp3->xing_offset + 8, mp3->frames); AV_WB32(mp3->xing_frame + mp3->xing_offset + 12, mp3->size);