[FFmpeg-devel] [PATCH] Notify user when encode a CBR mp3 file without "-write_xing false". This 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.

wm4 nfxjfg at googlemail.com
Sun Apr 23 18:30:44 EEST 2017


On Fri, 21 Apr 2017 22:59:41 +0800
sharpbai at gmail.com wrote:

> From: sharpbai <sharpbai at gmail.com>
> 
> 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.
> ---
>  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);

What's "ios browser". I'm not sure what this message is supposed to
help either - I think until now we usually haven't added warnings when
using or not using options that result in problems with specific
consuming applications.

The commit message subject line should not be longer than 72 characters.


More information about the ffmpeg-devel mailing list