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.32k stars 580 forks source link

Video to Audio not converting in ffmpeg_kit_flutter #782

Closed pksunny closed 11 months ago

pksunny commented 1 year ago

Restarted application in 4,158ms. [GETX] Instance "GetMaterialController" has been created [GETX] Instance "GetMaterialController" has been initialized I/flutter (27718): Temporary File Exists: true I/flutter (27718): Temporary File Size: 1116881 bytes I/flutter (27718): -i /data/user/0/com.dsl.bulbulapp/cache/input_temp.mp4 -c:a aac /data/user/0/com.dsl.bulbulapp/cache/audio.aac I/flutter (27718): Loading ffmpeg-kit-flutter. D/ffmpeg-kit-flutter(27718): FFmpegKitFlutterPlugin stopped listening to events. D/ffmpeg-kit-flutter(27718): FFmpegKitFlutterPlugin com.arthenica.ffmpegkit.flutter.FFmpegKitFlutterPlugin@c815a48 started listening to events on io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation@acbd85e. I/flutter (27718): Loaded ffmpeg-kit-flutter-android-https-arm64-v8a-5.1.0. I/flutter (27718): Log Message: ffmpeg version n5.1.2 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Copyright (c) 2000-2022 the FFmpeg developers I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d) I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --target-os=android --enable-neon --enable-asm --enable-inline-asm --ar=aarch64-linux-android-ar --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --ranlib=aarch64-linux-android-ranlib --strip=aarch64-linux-android-strip --nm=aarch64-linux-android-nm --extra-libs='-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/cpu-features/lib -lndk_compat' --disable-autodetect --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-pthreads --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-pro I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: libavutil 57. 28.100 / 57. 28.100 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: libavcodec 59. 37.100 / 59. 37.100 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: libavformat 59. 27.100 / 59. 27.100 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: libavdevice 59. 7.100 / 59. 7.100 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: libavfilter 8. 44.100 / 8. 44.100 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: libswscale 6. 7.100 / 6. 7.100 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: libswresample 4. 7.100 / 4. 7.100 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/user/0/com.dsl.bulbulapp/cache/input_temp.mp4': I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Metadata: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: major_brand : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: mp42 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: minor_version : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 0 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: compatible_brands: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: isommp42 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: creation_time : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 2023-06-22T20:30:41.000000Z I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Duration: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 00:00:49.74 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: , start: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 0.000000 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: , bitrate: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 956 kb/s I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Stream #0:0 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: [0x1] I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: (und) I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: : Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709, progressive), 720x960 [SAR 1:1 DAR 3:4], 823 kb/s I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: , I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 30 fps, I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 30 tbr, I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 15360 tbn I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: (default) I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Metadata: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: creation_time : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 2023-06-22T20:30:41.000000Z I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: handler_name : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: ISO Media file produced by Google Inc. Created on: 06/22/2023. I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: vendor_id : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: [0][0][0][0] I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Stream #0:1 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: [0x2] I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: (und) I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: : Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: (default) I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Metadata: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: creation_time : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 2023-06-22T20:30:41.000000Z I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: handler_name : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: ISO Media file produced by Google Inc. Created on: 06/22/2023. I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: vendor_id : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: [0][0][0][0] I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Stream mapping: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Stream #0:1 -> #0:0 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: (aac (native) -> aac (native)) I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Press [q] to stop, [?] for help I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Output #0, adts, to '/data/user/0/com.dsl.bulbulapp/cache/audio.aac': I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Metadata: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: major_brand : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: mp42 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: minor_version : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 0 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: compatible_brands: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: isommp42 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: encoder : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Lavf59.27.100 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Stream #0:0 I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: (und) I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: : Audio: aac, 44100 Hz, stereo, fltp, 128 kb/s I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: (default) I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Metadata: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: creation_time : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: 2023-06-22T20:30:41.000000Z I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: handler_name : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: ISO Media file produced by Google Inc. Created on: 06/22/2023. I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: vendor_id : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: [0][0][0][0] I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: encoder : I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: Lavc59.37.100 aac I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: I/flutter (27718): Log Level: 32 I/flutter (27718): Log Message: size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x I/flutter (27718): Log Level: 32 I/flutter (27718): MP4 to AAC conversion failed.

Function I'm using is:

import 'dart:io';

import 'package:bul_bul_app/utils/custom_style.dart'; import 'package:flutter/material.dart'; import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart'; import 'package:ffmpeg_kit_flutter/ffprobe_kit.dart'; import 'package:ffmpeg_kit_flutter/return_code.dart'; import 'package:ffmpeg_kit_flutter/log.dart'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart';

class Mp4ToMp3ConverterApp extends StatefulWidget { @override _Mp4ToMp3ConverterAppState createState() => _Mp4ToMp3ConverterAppState(); }

class _Mp4ToMp3ConverterAppState extends State {

final String inputFilePath = 'assets/v1.mp4'; // final String outputFilePath = 'output_audio.mp3';

Future _loadAsset() async { final ByteData byteData = await rootBundle.load(inputFilePath); return byteData.buffer.asUint8List(); }

void _convertMp4ToAac() async { final Uint8List inputFileData = await _loadAsset();

// Save the input file to a temporary file final tempDir = await getTemporaryDirectory(); final inputFileTempPath = '${tempDir.path}/input_temp.mp4'; final inputFileTemp = File(inputFileTempPath);

final exists = await inputFileTemp.exists(); print('Temporary File Exists: $exists'); final size = await inputFileTemp.length(); print('Temporary File Size: $size bytes');

// await inputFileTemp.writeAsBytes(inputFileData); try { await inputFileTemp.writeAsBytes(inputFileData); } catch (e) { print('Error writing temporary file: $e'); }

final outputFilePath = '${tempDir.path}/audio.aac';

final command = '-i $inputFileTempPath -c:a aac $outputFilePath'; final outputFile = File(outputFilePath);

print(command);

if (await outputFile.exists()) { await outputFile.delete(); }

try { final executeCallback = await FFmpegKit.executeAsync(command); final returnCode = await executeCallback.getReturnCode();

final logs = await executeCallback.getAllLogs();
for (final log in logs) {
  print('Log Message: ${log.getMessage()}');
  print('Log Level: ${log.getLevel().toString()}');
}

if (ReturnCode.isSuccess(returnCode)) {
  print('MP4 to AAC conversion successful.');

  // Get the duration of the output audio file
  final ffprobeCallback = await FFprobeKit.getMediaInformation(outputFilePath);
  final mediaInformation = await ffprobeCallback.getMediaInformation();
  final duration = mediaInformation?.getDuration();
  print('Output Audio Duration: $duration');

  setState(() {
    outputDuration = 'Duration: $duration'; // Update the output duration
  });

} else {
  print('MP4 to AAC conversion failed.');
}

} catch (e) { print('Error during conversion: $e'); // Show an error message or handle the exception appropriately } }

String outputDuration = '';

@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text('MP4 to MP3 Converter')), body: Center( child: Column( children: [ ElevatedButton( onPressed: _convertMp4ToAac, child: Text('Convert to MP3'), ), Text('$outputDuration', style: TxtStyle.halfBoldText.copyWith(color: Colors.black),) ], ), ), ), ); } }

Everything is fine but output path show empty

TheMelody commented 1 year ago

So, what kind of error are you reporting? There are a lot of incomprehensible Logs coming up.

github-actions[bot] commented 12 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 11 months ago

This issue was closed because it has been stalled for 7 days with no activity.