### Install FFmpegKit Minimal Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_min Add the package dependency to your pubspec.yaml file. ```yaml dependencies: ffmpeg_kit_flutter_new_min: ^3.6.0 ``` -------------------------------- ### Install dependency Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_https Add the package to your pubspec.yaml file. ```yaml dependencies: ffmpeg_kit_flutter_new_https: ^2.6.0 ``` -------------------------------- ### Install Linux dependencies Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio Required system packages for Linux development. ```bash sudo apt-get install libjson-glib-dev # Debian/Ubuntu sudo dnf install json-glib-devel # Fedora ``` -------------------------------- ### Install FFmpegKit Full dependency Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_full Add the package to your pubspec.yaml file to include the full FFmpeg toolkit. ```yaml dependencies: ffmpeg_kit_flutter_new_full: ^2.5.0 ``` -------------------------------- ### Install FFmpeg Kit HTTPS-GPL dependency Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_https_gpl Add the package to your pubspec.yaml file to include the HTTPS-GPL variant of FFmpeg Kit. ```yaml dependencies: ffmpeg_kit_flutter_new_https_gpl: ^2.6.0 ``` -------------------------------- ### Install package via Flutter CLI Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio/install Use this command in your terminal to add the package to your project dependencies. ```bash $ flutter pub add ffmpeg_kit_flutter_new_audio ``` -------------------------------- ### Retrieve media information Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio Use FFprobe to get metadata from a file or URL. ```dart FFprobeKit.getMediaInformation('').then((session) async { final information = await session.getMediaInformation(); }); ``` -------------------------------- ### Initialize and Execute FFmpeg Commands in Flutter Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_https/example Demonstrates setting up a Flutter application to run FFmpeg commands, including handling file assets and updating the UI during execution. ```dart import 'dart:io'; import 'package:ffmpeg_kit_flutter_new_https/ffmpeg_kit.dart'; import 'package:ffmpeg_kit_flutter_new_https/log.dart'; import 'package:ffmpeg_kit_flutter_new_https/session.dart'; import 'package:ffmpeg_kit_flutter_new_https/statistics.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'FFmpeg Kit Example', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), ), home: const MyHomePage(title: 'FFmpeg Kit Example'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { String logString = 'FFmpeg Kit Example\n\n'; bool isProcessing = false; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), body: Column( children: [ Expanded( child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Center( child: Text( 'Logs:', style: Theme.of(context).textTheme.headlineSmall, ), ), const SizedBox(height: 16), Text( logString, style: const TextStyle( fontSize: 14, fontFamily: 'monospace', ), ), ], ), ), ), ), if (isProcessing) const Padding( padding: EdgeInsets.all(16.0), child: LinearProgressIndicator(), ), ], ), bottomNavigationBar: BottomAppBar( child: ListView( scrollDirection: Axis.horizontal, children: [ ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('list_codecs'), child: const Text('List Codecs'), ), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('mediacodec'), child: const Text('MediaCodec'), ), ], ), ), ); } void executeFFmpegCommand(String mode) async { setState(() { isProcessing = true; logString = 'Starting FFmpeg processing...\n\n'; }); try { final tempDir = await getTemporaryDirectory(); final sampleVideoRoot = await rootBundle.load('assets/sample_video.mp4'); final sampleVideoFile = File('${tempDir.path}/sample_video.mp4'); final outputFile = File('${tempDir.path}/output.mp4'); await sampleVideoFile.writeAsBytes(sampleVideoRoot.buffer.asUint8List()); if (outputFile.existsSync()) await outputFile.delete(); String command; String description; switch (mode) { case 'list_codecs': if (Platform.isAndroid) { command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; } else if (Platform.isIOS || Platform.isMacOS) { command = '-hide_banner -encoders | grep -i videotoolbox'; description = 'List VideoToolbox codecs'; } else { command = '-hide_banner -encoders'; description = 'List all codecs'; } break; case 'mediacodec': command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; break; default: command = '-i ${sampleVideoFile.path} -c:v mpeg4 -preset ultrafast ${outputFile.path}'; description = 'Default encoding'; } ``` -------------------------------- ### Initialize and Execute FFmpeg in Flutter Source: https://pub.dev/packages/ffmpeg_kit_flutter_new/example Demonstrates setting up a basic Flutter application and executing FFmpeg commands using the ffmpeg_kit_flutter_new package. ```dart import 'dart:io'; import 'package:ffmpeg_kit_flutter_new/ffmpeg_kit.dart'; import 'package:ffmpeg_kit_flutter_new/log.dart'; import 'package:ffmpeg_kit_flutter_new/session.dart'; import 'package:ffmpeg_kit_flutter_new/statistics.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'FFmpeg Kit', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), ), home: const MyHomePage(title: 'FFmpeg Kit Example'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { String logString = 'Logs will appear here...'; bool isProcessing = false; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), body: Column( children: [ Expanded( child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 16), Text( logString, style: const TextStyle( fontSize: 14, fontFamily: 'monospace', ), ), ], ), ), ), ), if (isProcessing) const Padding( padding: EdgeInsets.all(16.0), child: LinearProgressIndicator(), ), ], ), bottomNavigationBar: BottomAppBar( child: ListView( scrollDirection: Axis.horizontal, children: [ ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('software'), child: const Text('Software'), ), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('hardware'), child: const Text('Hardware'), ), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('test'), child: const Text('Test HW'), ), if (Platform.isIOS || Platform.isMacOS) ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('videotoolbox'), child: const Text('VideoToolbox'), ), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('list_codecs'), child: const Text('List Codecs'), ), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('mediacodec'), child: const Text('MediaCodec'), ), ], ), ), ); } void executeFFmpegCommand(String mode) async { setState(() { isProcessing = true; logString = 'Starting FFmpeg processing...\n\n'; }); try { final tempDir = await getTemporaryDirectory(); final sampleVideoRoot = await rootBundle.load('assets/sample_video.mp4'); final sampleVideoFile = File('${tempDir.path}/sample_video.mp4'); final outputFile = File('${tempDir.path}/output.mp4'); await sampleVideoFile.writeAsBytes(sampleVideoRoot.buffer.asUint8List()); if (outputFile.existsSync()) await outputFile.delete(); String command; String description; ``` -------------------------------- ### Initialize FFmpeg Kit Flutter Application Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_full/example Sets up the main entry point and basic UI structure for a Flutter app using the FFmpeg Kit package. ```dart import 'dart:io'; import 'package:ffmpeg_kit_flutter_new_full/ffmpeg_kit.dart'; import 'package:ffmpeg_kit_flutter_new_full/log.dart'; import 'package:ffmpeg_kit_flutter_new_full/session.dart'; import 'package:ffmpeg_kit_flutter_new_full/statistics.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'FFmpeg Kit Example', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), ), home: const MyHomePage(title: 'FFmpeg Kit Example'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { String logString = 'FFmpeg Kit Example\n\n'; bool isProcessing = false; final buttonShape = RoundedRectangleBorder( borderRadius: BorderRadius.circular(24), ); ``` -------------------------------- ### Execute FFmpeg Command Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_full/example Initializes the processing state and prepares the environment for running an FFmpeg command. ```dart void executeFFmpegCommand(String mode) async { setState(() { isProcessing = true; logString = 'Starting FFmpeg processing...\n\n'; }); try { String command = ''; String description = ''; File inputFile; File outputFile; final tempDir = await getTemporaryDirectory(); inputFile = await _copyAssetToTemp('sample_video.mp4'); ``` -------------------------------- ### Configure FFmpeg Command and Execute Asynchronously Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_min/example Selects an FFmpeg command based on the target mode and executes it using FFmpegKit.executeAsync, handling session output, logs, and statistics via callbacks. ```dart switch (mode) { case 'videotoolbox': command = '-i ${sampleVideoFile.path} -c:v h264_videotoolbox -b:v 2M ${outputFile.path}'; description = 'Hardware encoding (VideoToolbox)'; break; case 'list_codecs': if (Platform.isAndroid) { command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; } else if (Platform.isIOS || Platform.isMacOS) { command = '-hide_banner -encoders | grep -i videotoolbox'; description = 'List VideoToolbox codecs'; } else { command = '-hide_banner -encoders'; description = 'List all codecs'; } break; case 'mediacodec': command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; break; default: command = '-i ${sampleVideoFile.path} -c:v mpeg4 -preset ultrafast ${outputFile.path}'; description = 'Default encoding'; } setState(() { logString += 'Mode: $description\n'; logString += 'Command: $command\n\n'; logString += 'Processing...\n'; }); /// Execute FFmpeg command await FFmpegKit.executeAsync( command, (Session session) async { final output = await session.getOutput(); final returnCode = await session.getReturnCode(); final duration = await session.getDuration(); setState(() { logString += '\nāœ… Processing completed!\n'; logString += 'Return code: $returnCode\n'; logString += 'Duration: ${duration}ms\n'; logString += 'Output: $output\n'; isProcessing = false; }); debugPrint('session: $output'); }, (Log log) { setState(() { logString += log.getMessage(); }); debugPrint('log: ${log.getMessage()}'); }, (Statistics statistics) { setState(() { logString += '\nšŸ“Š Progress: ${statistics.getSize()} bytes, ${statistics.getTime()}ms\n'; }); debugPrint('statistics: ${statistics.getSize()}'); }, ); } catch (e) { setState(() { logString += '\nāŒ Error: $e\n'; isProcessing = false; }); } } } ``` -------------------------------- ### Configure global callbacks and fonts Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio Set global listeners for logs and statistics, and define font directories. ```dart FFmpegKitConfig.enableLogCallback((log) { final message = log.getMessage(); }); FFmpegKitConfig.enableStatisticsCallback((statistics) { final size = statistics.getSize(); }); FFmpegKitConfig.setFontDirectoryList(["/system/fonts", "/System/Library/Fonts", ""]); ``` -------------------------------- ### Configure FFmpeg Commands Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio/example Defines command strings and output files for different audio codecs and platform-specific requirements. ```dart switch (mode) { case 'list_codecs': if (Platform.isAndroid) { command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; } else if (Platform.isIOS || Platform.isMacOS) { command = '-hide_banner -encoders | grep -i videotoolbox'; description = 'List VideoToolbox codecs'; } else { command = '-hide_banner -encoders'; description = 'List all codecs'; } break; case 'mediacodec': command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; break; // Audio Library Test Cases case 'lame': outputFile = File('${tempDir.path}/output.mp3'); command = '-y -i ${inputFile.path} -c:a libmp3lame -q:a 2 ${outputFile.path}'; description = 'Encode with LAME (MP3)'; break; case 'libilbc': outputFile = File('${tempDir.path}/output.lbc'); command = '-y -i ${inputFile.path} -ac 1 -c:a libilbc -ar 8000 -b:a 15.2k ${outputFile.path}'; description = 'Encode with iLBC'; break; case 'libvorbis': outputFile = File('${tempDir.path}/output.ogg'); command = '-y -i ${inputFile.path} -c:a libvorbis -qscale:a 5 ${outputFile.path}'; description = 'Encode with Vorbis'; break; case 'opencore-amr': outputFile = File('${tempDir.path}/output.amr'); command = '-y -i ${inputFile.path} -ac 1 -c:a libopencore_amrnb -ar 8000 -b:a 12.2k ${outputFile.path}'; description = 'Encode with OpenCORE AMR-NB'; break; case 'opus': outputFile = File('${tempDir.path}/output.opus'); command = '-y -i ${inputFile.path} -c:a libopus -b:a 96k ${outputFile.path}'; description = 'Encode with Opus'; break; case 'shine': outputFile = File('${tempDir.path}/output.mp3'); command = '-y -i ${inputFile.path} -c:a libshine -b:a 128k ${outputFile.path}'; description = 'Encode with Shine (MP3)'; break; case 'soxr': outputFile = File('${tempDir.path}/output_resampled.wav'); command = '-y -i ${inputFile.path} -af "aresample=resampler=soxr" -ar 44100 ${outputFile.path}'; description = 'Resample with SoXr'; break; case 'speex': outputFile = File('${tempDir.path}/output.spx'); command = '-y -i ${inputFile.path} -ac 1 -c:a libspeex -ar 16000 ${outputFile.path}'; description = 'Encode with Speex'; break; case 'twolame': outputFile = File('${tempDir.path}/output.mp2'); command = '-y -i ${inputFile.path} -c:a libtwolame -b:a 192k ${outputFile.path}'; description = 'Encode with TwoLAME (MP2)'; break; case 'vo-amrwbenc': outputFile = File('${tempDir.path}/output.awb'); command = '-y -i ${inputFile.path} -ac 1 -c:a libvo_amrwbenc -ar 16000 -b:a 23.85k ${outputFile.path}'; description = 'Encode with AMR-WB'; break; default: outputFile = File('${tempDir.path}/output.mp4'); command = '-y -i ${inputFile.path} -c:v mpeg4 -preset ultrafast ${outputFile.path}'; description = 'Default video encoding'; } ``` -------------------------------- ### Add Dependency Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_video Include the package in your pubspec.yaml file to enable FFmpeg functionality. ```yaml dependencies: ffmpeg_kit_flutter_new_video: ^2.5.0 ``` -------------------------------- ### Execute FFmpeg Command Logic Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio/example Handles state management and file preparation for FFmpeg commands based on the selected processing mode. ```dart void executeFFmpegCommand(String mode) async { setState(() { isProcessing = true; logString = 'Starting FFmpeg processing...\n\n'; }); try { String command = ''; String description = ''; File inputFile; File outputFile; final tempDir = await getTemporaryDirectory(); // Determine if the command is for audio or video final audioModes = [ 'lame', 'libilbc', 'libvorbis', 'opencore-amr', 'opus', 'shine', 'soxr', 'speex', 'twolame', 'vo-amrwbenc', ]; if (audioModes.contains(mode)) { inputFile = await _copyAssetToTemp('sample_audio.wav'); } else { inputFile = await _copyAssetToTemp('sample_video.mp4'); } ``` -------------------------------- ### Execute FFmpeg command Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_full Run an FFmpeg command and handle the result using a return code. ```dart import 'package:ffmpeg_kit_flutter_new_full/ffmpeg_kit.dart'; FFmpegKit.execute('-i file1.mp4 -c:v mpeg4 file2.mp4').then((session) async { final returnCode = await session.getReturnCode(); if (ReturnCode.isSuccess(returnCode)) { // SUCCESS } else if (ReturnCode.isCancel(returnCode)) { // CANCEL } else { // ERROR } }); ``` -------------------------------- ### Import FFmpegKit Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_full Include the FFmpegKit library in your Dart files to access the API. ```dart import 'package:ffmpeg_kit_flutter_new_full/ffmpeg_kit.dart'; ``` -------------------------------- ### Configure FFmpeg Command Modes Source: https://pub.dev/packages/ffmpeg_kit_flutter_new/example Selects the appropriate FFmpeg command string based on the chosen encoding mode and platform requirements. ```dart switch (mode) { case 'software': command = '-i ${sampleVideoFile.path} -c:v mpeg4 -preset ultrafast ${outputFile.path}'; description = 'Software encoding (MPEG-4)'; break; case 'hardware': if (Platform.isAndroid) { command = '-i ${sampleVideoFile.path} -c:v h264_mediacodec -b:v 2M ${outputFile.path}'; description = 'Hardware encoding (Android MediaCodec)'; } else if (Platform.isIOS || Platform.isMacOS) { command = '-i ${sampleVideoFile.path} -c:v h264_videotoolbox -b:v 2M ${outputFile.path}'; description = 'Hardware encoding (VideoToolbox)'; } else { command = '-i ${sampleVideoFile.path} -c:v mpeg4 -preset ultrafast ${outputFile.path}'; description = 'Software encoding (fallback)'; } break; case 'test': command = '-f lavfi -i testsrc=duration=5:size=1280x720:rate=30 -c:v h264 -t 5 ${outputFile.path}'; description = 'Hardware acceleration test'; break; case 'videotoolbox': command = '-i ${sampleVideoFile.path} -c:v h264_videotoolbox -b:v 2M ${outputFile.path}'; description = 'Hardware encoding (VideoToolbox)'; break; case 'list_codecs': if (Platform.isAndroid) { command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; } else if (Platform.isIOS || Platform.isMacOS) { command = '-hide_banner -encoders | grep -i videotoolbox'; description = 'List VideoToolbox codecs'; } else { command = '-hide_banner -encoders'; description = 'List all codecs'; } break; case 'mediacodec': command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; break; default: command = '-i ${sampleVideoFile.path} -c:v mpeg4 -preset ultrafast ${outputFile.path}'; description = 'Default encoding'; } setState(() { logString += 'Mode: $description\n'; logString += 'Command: $command\n\n'; logString += 'Processing...\n'; }); ``` -------------------------------- ### Execute Asynchronous FFmpeg Command Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_https/example Uses FFmpegKit.executeAsync to run commands without blocking the UI thread. Requires callbacks for session completion, log capture, and statistics monitoring. ```dart setState(() { logString += 'Mode: $description\n'; logString += 'Command: $command\n\n'; logString += 'Processing...\n'; }); /// Execute FFmpeg command await FFmpegKit.executeAsync( command, (Session session) async { final output = await session.getOutput(); final returnCode = await session.getReturnCode(); final duration = await session.getDuration(); setState(() { logString += '\nāœ… Processing completed!\n'; logString += 'Return code: $returnCode\n'; logString += 'Duration: ${duration}ms\n'; logString += 'Output: $output\n'; isProcessing = false; }); debugPrint('session: $output'); }, (Log log) { setState(() { logString += log.getMessage(); }); debugPrint('log: ${log.getMessage()}'); }, (Statistics statistics) { setState(() { logString += '\nšŸ“Š Progress: ${statistics.getSize()} bytes, ${statistics.getTime()}ms\n'; }); debugPrint('statistics: ${statistics.getSize()}'); }, ); } catch (e) { setState(() { logString += '\nāŒ Error: $e\n'; isProcessing = false; }); } } } ``` -------------------------------- ### Add dependency via command line Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_https_gpl/install Use this command in your terminal to add the package to your Flutter project. ```bash $ flutter pub add ffmpeg_kit_flutter_new_https_gpl ``` -------------------------------- ### FFmpegKit.execute Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio Executes an FFmpeg command synchronously and returns a session object to track the execution result. ```APIDOC ## FFmpegKit.execute(String command) ### Description Executes an FFmpeg command and returns a Future that resolves to a session object. ### Parameters - **command** (String) - Required - The FFmpeg command string to execute. ### Response - **session** (FFmpegSession) - The session object containing execution details and return codes. ``` -------------------------------- ### Configure FFmpeg Command Modes Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_full/example Defines various FFmpeg command configurations based on the selected mode, including codec listing and specific encoding parameters. ```dart switch (mode) { case 'list_codecs': if (Platform.isAndroid) { command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; } else if (Platform.isIOS || Platform.isMacOS) { command = '-hide_banner -encoders | grep -i videotoolbox'; description = 'List VideoToolbox codecs'; } else { command = '-hide_banner -encoders'; description = 'List all codecs'; } break; case 'mediacodec': command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; break; case 'kvazaar': outputFile = File('${tempDir.path}/output_kvazaar.mp4'); command = '-y -i ${inputFile.path} -c:v libkvazaar -preset ultrafast ${outputFile.path}'; description = 'Encode HEVC with kvazaar'; break; case 'libtheora': outputFile = File('${tempDir.path}/output.ogv'); command = '-y -i ${inputFile.path} -c:v libtheora -q:v 7 ${outputFile.path}'; description = 'Encode with libtheora'; break; case 'libvpx': outputFile = File('${tempDir.path}/output.webm'); command = '-y -i ${inputFile.path} -c:v libvpx-vp9 -b:v 1M -c:a libopus ${outputFile.path}'; description = 'Encode VP9 with libvpx'; break; case 'libwebp': outputFile = File('${tempDir.path}/output.webp'); command = '-y -i ${inputFile.path} -c:v libwebp -loop 0 -an -vsync 0 ${outputFile.path}'; description = 'Encode to animated WebP'; break; case 'snappy': outputFile = File('${tempDir.path}/output_hap.mov'); command = '-y -i ${inputFile.path} -c:v hap -format hap_q ${outputFile.path}'; description = 'Encode with HAP (uses snappy)'; break; case 'zimg': outputFile = File('${tempDir.path}/output_zscale.mp4'); command = '-y -i ${inputFile.path} -vf "zscale=w=640:h=480" -c:a copy ${outputFile.path}'; description = 'Apply filter with zimg (zscale)'; break; default: outputFile = File('${tempDir.path}/output_default.mp4'); command = '-y -i ${inputFile.path} -c:v mpeg4 -preset ultrafast ${outputFile.path}'; description = 'Default video encoding'; } ``` -------------------------------- ### FFmpegKit.executeAsync Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio Executes an FFmpeg command asynchronously with provided callbacks for session completion, logging, and statistics. ```APIDOC ## FFmpegKit.executeAsync(String command, Function sessionCallback, Function logCallback, Function statisticsCallback) ### Description Executes an FFmpeg command in the background and triggers callbacks for lifecycle events. ### Parameters - **command** (String) - Required - The FFmpeg command string. - **sessionCallback** (Function) - Optional - Callback invoked when the session completes. - **logCallback** (Function) - Optional - Callback invoked when logs are generated. - **statisticsCallback** (Function) - Optional - Callback invoked when statistics are generated. ``` -------------------------------- ### FFprobeKit.getMediaInformation Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio Retrieves media information for a given file path or URL using FFprobe. ```APIDOC ## FFprobeKit.getMediaInformation(String path) ### Description Analyzes a media file and returns information about its streams and metadata. ### Parameters - **path** (String) - Required - The file path or URL to analyze. ### Response - **session** (FFprobeSession) - The session object containing media information. ``` -------------------------------- ### Build Flutter UI for FFmpeg Execution Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_full/example Defines the Scaffold layout including a log display area and a horizontal list of buttons to trigger specific FFmpeg commands. ```dart @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), body: Column( children: [ Expanded( child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Center( child: Text( 'Logs:', style: Theme.of(context).textTheme.headlineSmall, ), ), const SizedBox(height: 16), Text( logString, style: const TextStyle( fontSize: 14, fontFamily: 'monospace', ), ), ], ), ), ), ), if (isProcessing) const Padding( padding: EdgeInsets.all(16.0), child: LinearProgressIndicator(), ), BottomAppBar( child: SizedBox( height: 40, child: ListView( padding: const EdgeInsets.all(2), scrollDirection: Axis.horizontal, children: [ ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('list_codecs'), child: const Text('List Codecs'), ), const SizedBox(width: 8), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('mediacodec'), child: const Text('MediaCodec'), ), const SizedBox(width: 8), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('kvazaar'), child: const Text('kvazaar'), ), const SizedBox(width: 8), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('libtheora'), child: const Text('libtheora'), ), const SizedBox(width: 8), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('libvpx'), child: const Text('libvpx'), ), const SizedBox(width: 8), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('libwebp'), child: const Text('libwebp'), ), const SizedBox(width: 8), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('snappy'), child: const Text('snappy'), ), const SizedBox(width: 8), ElevatedButton( onPressed: isProcessing ? null : () => executeFFmpegCommand('zimg'), child: const Text('zimg'), ), ], ), ), ), ], ), ); } ``` -------------------------------- ### Inspect FFmpeg session Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio Retrieve detailed information about an executed session. ```dart FFmpegKit.execute('-i file1.mp4 -c:v mpeg4 file2.mp4').then((session) async { final sessionId = session.getSessionId(); final command = session.getCommand(); final state = await session.getState(); final returnCode = await session.getReturnCode(); final duration = await session.getDuration(); final output = await session.getOutput(); final logs = await session.getLogs(); final statistics = await (session as FFmpegSession).getStatistics(); }); ``` -------------------------------- ### Execute asynchronously with callbacks Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio Run commands in the background and handle logs and statistics via callbacks. ```dart FFmpegKit.executeAsync('-i file1.mp4 -c:v mpeg4 file2.mp4', (Session session) async { // CALLED WHEN SESSION IS EXECUTED }, (Log log) { // CALLED WHEN SESSION PRINTS LOGS }, (Statistics statistics) { // CALLED WHEN SESSION GENERATES STATISTICS }); ``` -------------------------------- ### Configure FFmpeg Encoding Modes Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_video/example Defines various FFmpeg command strings and output file paths based on the selected encoding mode. ```dart switch (mode) { case 'list_codecs': if (Platform.isAndroid) { command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; } else if (Platform.isIOS || Platform.isMacOS) { command = '-hide_banner -encoders | grep -i videotoolbox'; description = 'List VideoToolbox codecs'; } else { command = '-hide_banner -encoders'; description = 'List all codecs'; } break; case 'mediacodec': command = '-hide_banner -encoders | grep -i mediacodec'; description = 'List MediaCodec codecs'; break; case 'kvazaar': outputFile = File('${tempDir.path}/output_kvazaar.mp4'); command = '-y -i ${inputFile.path} -c:v libkvazaar -preset ultrafast ${outputFile.path}'; description = 'Encode HEVC with kvazaar'; break; case 'libtheora': outputFile = File('${tempDir.path}/output.ogv'); command = '-y -i ${inputFile.path} -c:v libtheora -q:v 7 ${outputFile.path}'; description = 'Encode with libtheora'; break; case 'libvpx': outputFile = File('${tempDir.path}/output.webm'); command = '-y -i ${inputFile.path} -c:v libvpx-vp9 -b:v 1M -c:a libopus ${outputFile.path}'; description = 'Encode VP9 with libvpx'; break; case 'libwebp': outputFile = File('${tempDir.path}/output.webp'); command = '-y -i ${inputFile.path} -c:v libwebp -loop 0 -an -vsync 0 ${outputFile.path}'; description = 'Encode to animated WebP'; break; case 'snappy': outputFile = File('${tempDir.path}/output_hap.mov'); command = '-y -i ${inputFile.path} -c:v hap -format hap_q ${outputFile.path}'; description = 'Encode with HAP (uses snappy)'; break; case 'zimg': outputFile = File('${tempDir.path}/output_zscale.mp4'); command = '-y -i ${inputFile.path} -vf "zscale=w=640:h=480" -c:a copy ${outputFile.path}'; description = 'Apply filter with zimg (zscale)'; break; default: outputFile = File('${tempDir.path}/output_default.mp4'); command = '-y -i ${inputFile.path} -c:v mpeg4 -preset ultrafast ${outputFile.path}'; description = 'Default video encoding'; } ``` -------------------------------- ### Import package modules in Dart Source: https://pub.dev/packages/ffmpeg_kit_flutter_new_audio/install Import the necessary library files to access FFmpeg Kit functionality in your Dart code. ```dart import 'package:ffmpeg_kit_flutter_new_audio/abstract_session.dart'; import 'package:ffmpeg_kit_flutter_new_audio/arch_detect.dart'; import 'package:ffmpeg_kit_flutter_new_audio/chapter.dart'; import 'package:ffmpeg_kit_flutter_new_audio/extensions.dart'; import 'package:ffmpeg_kit_flutter_new_audio/ffmpeg_kit.dart'; import 'package:ffmpeg_kit_flutter_new_audio/ffmpeg_kit_config.dart'; import 'package:ffmpeg_kit_flutter_new_audio/ffmpeg_session.dart'; import 'package:ffmpeg_kit_flutter_new_audio/ffmpeg_session_complete_callback.dart'; import 'package:ffmpeg_kit_flutter_new_audio/ffprobe_kit.dart'; import 'package:ffmpeg_kit_flutter_new_audio/ffprobe_session.dart'; import 'package:ffmpeg_kit_flutter_new_audio/ffprobe_session_complete_callback.dart'; import 'package:ffmpeg_kit_flutter_new_audio/level.dart'; import 'package:ffmpeg_kit_flutter_new_audio/log.dart'; import 'package:ffmpeg_kit_flutter_new_audio/log_callback.dart'; import 'package:ffmpeg_kit_flutter_new_audio/log_redirection_strategy.dart'; import 'package:ffmpeg_kit_flutter_new_audio/media_information.dart'; import 'package:ffmpeg_kit_flutter_new_audio/media_information_json_parser.dart'; import 'package:ffmpeg_kit_flutter_new_audio/media_information_session.dart'; import 'package:ffmpeg_kit_flutter_new_audio/media_information_session_complete_callback.dart'; import 'package:ffmpeg_kit_flutter_new_audio/packages.dart'; import 'package:ffmpeg_kit_flutter_new_audio/return_code.dart'; import 'package:ffmpeg_kit_flutter_new_audio/session.dart'; import 'package:ffmpeg_kit_flutter_new_audio/session_state.dart'; import 'package:ffmpeg_kit_flutter_new_audio/signal.dart'; import 'package:ffmpeg_kit_flutter_new_audio/statistics.dart'; import 'package:ffmpeg_kit_flutter_new_audio/statistics_callback.dart'; import 'package:ffmpeg_kit_flutter_new_audio/stream_information.dart'; ```