FFmpeg Helper
Use this skill when working with ffmpeg_kit_flutter_new.
1. Syntax Handling
- Space Escaping: Paths with spaces must be escaped.
- Incorrect:
-i /storage/emulated/0/My Folder/video.mp4 - Correct:
-i "/storage/emulated/0/My Folder/video.mp4"
- Incorrect:
- Codecs: Mobile devices often prefer
aacfor audio andlibx264(software) orh264_mediacodec(hardware) for video.
2. Common Recipes
Merge Audio and Video
final command = '-i "$videoPath" -i "$audioPath" -c:v copy -c:a aac "$outputPath"';
Convert to MP3
final command = '-i "$inputPath" -vn -acodec libmp3lame -q:a 2 "$outputPath"';
-vn: Disable video recording.-acodec libmp3lame: Use MP3 codec.-q:a 2: Variable bit rate (high quality).
Trim Video
final command = '-ss 00:00:10 -i "$inputPath" -t 00:00:30 -c copy "$outputPath"';
-ss: Start time.-t: Duration.
3. Session Handling
Always check the return code:
FFmpegKit.execute(command).then((session) async {
final returnCode = await session.getReturnCode();
if (ReturnCode.isSuccess(returnCode)) {
// Success
} else {
// Failure
final failStackTrace = await session.getFailStackTrace();
print("FFmpeg failed: $failStackTrace");
}
});
4. Permissions
- Ensure
Permission.manageExternalStorage(Android 11+) orPermission.storageis granted before running commands involving external files.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.