arthenica / ffmpeg-kit

FFmpeg Kit for applications. Supports Android, Flutter, iOS, Linux, macOS, React Native and tvOS. Supersedes MobileFFmpeg, flutter_ffmpeg and react-native-ffmpeg.
https://arthenica.github.io/ffmpeg-kit
GNU Lesser General Public License v3.0
4.54k stars 605 forks source link

mp3 to pcm command crash on iOS #596

Closed dukewuzhao closed 1 year ago

dukewuzhao commented 2 years ago

my code:

      final String ffmpegCommand = '-hide_banner -y -i "$path" -f s16le -ar 44100 -af pan=stereo|c0=FL -ac 1 -acodec pcm_s16le "$newPath"';
      FFmpegSession session = await FFmpegKit.execute(ffmpegCommand);
      final state = FFmpegKitConfig.sessionStateToString(await session.getState());
      final returnCode = await session.getReturnCode();
      final failStackTrace = await session.getFailStackTrace();
      final output = await session.getOutput();
      print("FFmpeg process exited with state ${state} and rc ${returnCode}");
      if (state == SessionState.failed || !ReturnCode.isSuccess(returnCode)) {
        print("Command failed. Please check output for the details$output");
        print("转码失败");
        return Future.value({"code":false});
      }else{
        print("转码成功");
        final file = File(newPath);
        List<int> doubleList = file.readAsBytesSync().buffer.asInt16List();
        //print("pcm数据---$doubleList");
        file.delete();
        return Future.value({"code":true,"sampleRate":44100,"data":doubleList,"mDataLen":doubleList.length});
      }

Platform: iOS Version:ffmpeg_kit_flutter_audio: 4.5.1-LTS Source branch: main

crash log: Loading ffmpeg-kit. Loaded ffmpeg-kit-audio-arm64-4.5.1-lts-20220114 flutter: Loaded ffmpeg-kit-flutter-ios-audio-arm64-4.5.1-lts. Input #0, mp3, from '/var/mobile/Containers/Data/Application/7CED271E-5BAD-4EEE-A814-19282368D3E8/Documents/music/当阳常志此心丹.mp3': Metadata: artist : null Duration: 00:01:59.82, start: 0.025057, bitrate: 128 kb/s Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s Metadata: encoder : LAME3.98r Side data: replaygain: track gain - -5.700000, track peak - unknown, album gain - unknown, album peak - unknown, [mp3float @ 0x101eb2ef0] The "sub_text_format" option is deprecated: Deprecated, does nothing Stream mapping: Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16be (native)) Press [q] to stop, [?] for help Output #0, s16be, to '/var/mobile/Containers/Data/Application/7CED271E-5BAD-4EEE-A814-19282368D3E8/Documents/music/当阳常志此心丹.pcm': Metadata: artist : null encoder : Lavf59.10.100 Stream #0:0: Audio: pcm_s16be, 16000 Hz, mono, s16, 256 kb/s Metadata: encoder : Lavc59.15.102 pcm_s16be Side data: replaygain: track gain - -5.700000, track peak - unknown, album gain - unknown, album peak - unknown, size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
size= 3743kB time=00:01:59.77 bitrate= 256.0kbits/s speed= 460x
video:0kB audio:3743kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000% Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument' First throw call stack: (0x1905d8d78 0x1a923d734 0x1906e35d0 0x19067ec20 0x19055c530 0x101682d74 0x100fe4620 0x100fe1064 0x108bf195c 0x108742130 0x108abeafc 0x1089ec214 0x1089eff6c 0x1905ee168 0x190572144 0x19056c8f0 0x19054afa0 0x19055e6b8 0x1ac5f8374 0x192ec3e88 0x192c455ec 0x100f9963c 0x101219ce4) libc++abi: terminating with uncaught exception of type NSException

image

What's the reason

tanersener commented 2 years ago

Thanks for creating this issue. That exception is not normal. Can you try with the latest LTS version we have: 5.1.0 ?

dukewuzhao commented 2 years ago

crash log: Input #0, mp3, from '/var/mobile/Containers/Data/Application/A7096AE5-7176-492A-B5E3-61A428602719/Documents/music/当阳常志此心丹.mp3': Metadata: artist : null Duration: 00:01:59.82, start: 0.025057, bitrate: 128 kb/s Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s Metadata: encoder : LAME3.98r Side data: replaygain: track gain - -5.700000, track peak - unknown, album gain - unknown, album peak - unknown, Stream mapping: Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16be (native)) Press [q] to stop, [?] for help Output #0, s16be, to '/var/mobile/Containers/Data/Application/A7096AE5-7176-492A-B5E3-61A428602719/Documents/music/当阳常志此心丹.pcm': Metadata: artist : null encoder : Lavf59.27.100 Stream #0:0: Audio: pcm_s16be, 16000 Hz, mono, s16, 256 kb/s Metadata: encoder : Lavc59.37.100 pcm_s16be Side data: replaygain: track gain - -5.700000, track peak - unknown, album gain - unknown, album peak - unknown, size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
size= 3743kB time=00:01:59.77 bitrate= 256.0kbits/s speed= 481x
video:0kB audio:3743kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000% size=N/A time=00:01:59.77 bitrate=N/A speed= 480x
video:0kB audio:3743kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Platform: iOS Version:ffmpeg_kit_flutter_full: 5.1.0-LTS Source branch: main

It's still crashing, it's still in the same place, but it's just this piece of music that crashes, the others are ok, I'm a little confused, this is the crashing music 当阳常志此心丹.mp3.zip

tanersener commented 2 years ago

Thanks for the example file. I managed to reproduce the issue.

It seems like we cannot properly read some of the fields inside that file. I'm not 100 % sure, but I suspect some ID3 tags have an encoding that we cannot process. When that happens we generate null log messages. That's why you have this issue.

The crash comes from the iOS library. I pushed a commit on the development branch to prevent it.

Unfortunately, it's not very easy to use this fix on flutter. You need to build the iOS library from the development branch and replace the original ffmpeg-kit iOS dependency of the flutter plugin with it. Or wait until we publish a new release.

tanersener commented 2 years ago

I manually modified the ID3 tags and cleared the artist tag of that file. After that, tested in ffmpeg-kit again. This time the file didn't receive any errors. That proves my theory. The encoding of ID3 tags is the issue for that file.

tanersener commented 1 year ago

Fixed in flutter v6.0.0.