tanersener / mobile-ffmpeg

FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.
https://tanersener.github.io/mobile-ffmpeg
GNU General Public License v3.0
3.85k stars 787 forks source link

BUG: Wrong duration after converting WAV to MP3 audio file #666

Closed tim162 closed 3 years ago

tim162 commented 3 years ago

Description Inside my app I record and save a WAV audio file (needs to be in this format) and after that I convert it to MP3 using following command: ffmpeg -i inputfile.wav -vn -ar 44100 -ac 1 -b:a 96k -y outputfile.mp3 (The input wav file has the exact same sample rate)

Expected behavior The MP3 file should have the same audio data like the input WAV file (talking about same duration & that e.g. a specific noise is at the exact same time in both files)

Current behavior The MP3 file shows the same duration but when I play it and reach the end of the duration the file is not finished. It goes on for several seconds and then finishes. The actual audio time is longer than the input duration. This also leads to a shift in the audio noise, e.g. I make a noise at 2:00:00.000 (in the input WAV file) and the noise shifts 12 seconds to 2:00:12.000 in the output MP3 file. This happens only for the converted mp3 file and not the input wav file and it happens with every conversion (the longer the duration the bigger the offset gets). For my purpose I need this to be correctly synchronized even after a long duration of ~10 hours.

Screenshots You can see the current playtime on the left (3:59:55) that is bigger than the duration of the mp3 file (3:59:50) and the file is still playing.

mp3file

Logs

Loaded mobile-ffmpeg-custom-arm64-v8a-4.4-lts-20201121
ffmpeg version v4.4-dev-416

libavutil      56. 55.100 / 56. 55.100
      libavcodec     58. 96.100 / 58. 96.100
      libavformat    58. 48.100 / 58. 48.100
      libavdevice    58. 11.101 / 58. 11.101
      libavfilter     7. 87.100 /  7. 87.100
      libswscale      5.  8.100 /  5.  8.100
      libswresample   3.  8.100 /  3.  8.100
    Guessed Channel Layout for Input Stream #0.0 : mono
    Input #0, wav, from 'input.wav':
      Duration: 05:59:50.04, bitrate: 705 kb/s
        Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (pcm_s16le (native) -> mp3 (libmp3lame))
    Press [q] to stop, [?] for help
    Output #0, mp3, to 'output.mp3':
      Metadata:
        TSSE            : Lavf58.48.100
        Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, mono, s16p, 96 kb/s
        Metadata:
          encoder         : Lavc58.96.100 libmp3lame

video:0kB audio:253009kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000138%

Environment

tim162 commented 3 years ago

If anyone is interested or comes across the same bug, its working if you convert to FLAC or AAC for example. Don't know why it is happening with MP3 as this would be our preferred audio format.

mgood7123 commented 3 years ago

Description Inside my app I record and save a WAV audio file (needs to be in this format) and after that I convert it to MP3 using following command: ffmpeg -i inputfile.wav -vn -ar 44100 -ac 1 -b:a 96k -y outputfile.mp3 (The input wav file has the exact same sample rate)

Expected behavior The MP3 file should have the same audio data like the input WAV file (talking about same duration & that e.g. a specific noise is at the exact same time in both files)

Current behavior The MP3 file shows the same duration but when I play it and reach the end of the duration the file is not finished. It goes on for several seconds and then finishes. The actual audio time is longer than the input duration. This also leads to a shift in the audio noise, e.g. I make a noise at 2:00:00.000 (in the input WAV file) and the noise shifts 12 seconds to 2:00:12.000 in the output MP3 file. This happens only for the converted mp3 file and not the input wav file and it happens with every conversion (the longer the duration the bigger the offset gets). For my purpose I need this to be correctly synchronized even after a long duration of ~10 hours.

Screenshots You can see the current playtime on the left (3:59:55) that is bigger than the duration of the mp3 file (3:59:50) and the file is still playing.

mp3file

Logs

Loaded mobile-ffmpeg-custom-arm64-v8a-4.4-lts-20201121
ffmpeg version v4.4-dev-416

libavutil      56. 55.100 / 56. 55.100
      libavcodec     58. 96.100 / 58. 96.100
      libavformat    58. 48.100 / 58. 48.100
      libavdevice    58. 11.101 / 58. 11.101
      libavfilter     7. 87.100 /  7. 87.100
      libswscale      5.  8.100 /  5.  8.100
      libswresample   3.  8.100 /  3.  8.100
    Guessed Channel Layout for Input Stream #0.0 : mono
    Input #0, wav, from 'input.wav':
      Duration: 05:59:50.04, bitrate: 705 kb/s
        Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (pcm_s16le (native) -> mp3 (libmp3lame))
    Press [q] to stop, [?] for help
    Output #0, mp3, to 'output.mp3':
      Metadata:
        TSSE            : Lavf58.48.100
        Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, mono, s16p, 96 kb/s
        Metadata:
          encoder         : Lavc58.96.100 libmp3lame

video:0kB audio:253009kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000138%

Environment

  • Platform: Android
  • Version (if applicable): own build based on 4.4-LTS
  • Android Studio version (if applicable) 4.1

can you try this using the official FFMPEG from https://ffmpeg.org/download.html and see if the bug persists

(convert using host environment, not android environment)

if it persists then this is a bug in FFMPEG itself, not Mobile FFMPEG

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

tanersener commented 3 years ago

This project will be retired. Please consider switching to FFmpegKit.