生成视频的GIF缩略图-颤动-图片

问题描述

我正在尝试为设备上的视频创建动画缩略图。它是一个android / ios flutter应用程序。 所以我的方法是在手机上使用以下飞镖包进行操作:

  flutter_video_compress: ^0.3.7+8
  image: ^2.1.13

下面的代码不是完整的代码,.convertVideoToGif(flutter_video_compress)效果很好。但是,生成的GIF文件很大,因此我使用了图像包来缩小尺寸并减少帧数。但是从Image包生成的GIF始终会生成带有红色假象的GIF文件,有人知道为什么要这么做吗?

生成的示例gif文件: https://cdn.tracorder.com/videos/3tIbEYH_1601602948035.mp4.gif

import 'package:image/image.dart' as pic;
import 'package:flutter_video_compress/flutter_video_compress.dart';

{
    thumb = await _flutterVideoCompress.convertVideoToGif(
            videoPath,startTime: 0,// default(0)
            duration: 3,// default(-1)
            endTime: -1 // default(-1)
          );
    
    
          debugPrint("Thumb : " + thumb.path);
    
    
          pic.Animation thumbTemp = pic.decodeGifAnimation(thumb.readAsBytesSync());
          int frameDividor = (thumbTemp.length/5).round();
          pic.GifEncoder gifEnc = new pic.GifEncoder(delay: 50,repeat: 0,samplingFactor: 100);
          pic.Image tmpImage;
    
          for(int t=0; t < thumbTemp.length; t++){
    
            if((t % frameDividor) == 0){
              tmpImage = pic.copyResize(thumbTemp.frames[t],width: 250);
              gifEnc.addFrame(tmpImage,duration: 30);
    
            }
    
          }
          thumbAnime = pic.decodeGifAnimation(gifEnc.finish());
    

          thumb.writeAsBytesSync(pic.encodeGifAnimation(thumbAnime));
}

编辑:


最终使用flutter_ffmpeg,这就是我最终使用的内容:

  var arguments = ["-i",videoPath,"-ss","00:00:01","-t","00:00:03","-vf","fps=3,scale=120:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse","-loop","0",thumb.path];
  _flutterFFmpeg.executeWithArguments(arguments).then((rc) {
        print("FFmpeg process exited with rc $rc");
        setState(() {
          _thumbReady = true;
        });
    }
  );

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)