You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于FFmpegKit的Flutter多图转带音频视频幻灯片开发问题

Using FFmpegKit to Create Videos from Images (with Audio & Animations)

1. Basic: Single Image + MP3 to Video

First, let's get the simple case working. Here's the FFmpeg command you can run via FFmpegKit:

ffmpeg -loop 1 -i input.jpg -i audio.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -shortest output.mp4

Breakdown of key parameters:

  • -loop 1: Loops the input image until the audio ends
  • -i input.jpg: Your source image file
  • -i audio.mp3: Your source audio file
  • -c:v libx264: Uses the H.264 codec (standard for MP4 compatibility)
  • -tune stillimage: Optimizes encoding for static images (reduces file size without quality loss)
  • -c:a aac: Uses the AAC audio codec (widely supported)
  • -b:a 192k: Sets audio bitrate to 192kbps (adjust based on quality needs)
  • -shortest: Ends the video when the audio finishes
  • output.mp4: The final video file

2. Multiple Images with Animations & Transitions

For multiple images with animations (fades, slides, etc.), use FFmpeg's filter complex. Below is an example with 3 images, each displayed for 5 seconds, with crossfade transitions, plus background audio:

ffmpeg -i img1.jpg -i img2.jpg -i img3.jpg -i audio.mp3 \
-filter_complex "
[0:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v0];
[1:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1];
[2:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2];
[v0][v1]xfade=transition=fade:duration=1:offset=4[v01];
[v01][v2]xfade=transition=fade:duration=1:offset=9[v];
" \
-map "[v]" -map 3:a -c:v libx264 -c:a aac -b:a 192k -shortest output.mp4

Key explanations:

  • Each image gets fade filters: fade=t=in:st=0:d=1 adds a 1-second fade-in, fade=t=out:st=4:d=1 adds a 1-second fade-out starting at 4 seconds (total 5 seconds per image)
  • xfade creates crossfade transitions: transition=fade uses a fade effect, duration=1 makes transitions last 1 second, offset=4 starts the transition when the first image's fade-out begins
  • -map "[v]" uses the filtered video stream, -map 3:a uses the 4th input (audio) stream

Common Animation Variations

  • Slide transitions: Replace xfade=transition=fade with xfade=transition=slideleft (or slideright, slideup, slidedown)
  • Zoom effect: Add zoompan=z='min(zoom+0.001,1.5)':d=125 to an image filter (adjust zoom speed and max zoom level as needed)
  • Pan effect: Use pan=w=1920:h=1080:x='if(gte(t,2),100+(t-2)*50,0)':y=0 to pan across a larger image (tweak dimensions and speed values)

Troubleshooting Tips

  • Ensure all images have the same resolution, or add a scale filter to standardize: e.g., [0:v]scale=1920:1080,fade=...
  • If audio is out of sync, double-check image durations and transition timings, or rely on -shortest to match audio length
  • For mobile FFmpegKit (Android/iOS), use the full package variant to access all codecs and filters

内容的提问来源于stack exchange,提问作者Ajeet Kumar Sah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 11:40:20