图片转视频

依赖库:

[plain]  view plain  copy
  1. compile 'org.jcodec:jcodec-android:0.1.9'  
这个框架原本是javaee用的,现在可以支持android了.

2.在安卓中的提供的API主要是

[java]  view plain  copy
  1. SequenceEncoder.class  
这个类.然后这个类只是一个兼容性过度类,很多方法都在父类中,所以导致了有些不灵活.所以在使用的时候是建议集成这个类去重写一些必要的方法.

3.图片转换的代码主要如下:

[java]  view plain  copy
  1. public static void Image2Mp4(Context context , String videoName){  
  2.         try {  
  3.             Logger.e("performJcodec: ""执行开始");  
  4.             SequenceEncoderMp4 se   = null;  
  5.             File               file = new File(Constants.FILE_SCREEN_FLODER);  
  6.   
  7.   
  8.             File out = new File(Constants.FILE_VIDEO_FLODER, videoName + ".mp4");  
  9.             se = new SequenceEncoderMp4(out);  
  10.   
  11.             File[] files = file.listFiles();  
  12.             for (int i = 0; i < files.length; i++) {  
  13.                 if (!files[i].exists()) { break; }  
  14.                 Bitmap frame = BitmapUtil.decodeSampledBitmapFromFile(files[i].getAbsolutePath() , 480 , 320);  
  15.   
  16.                 se.encodeImage(frame);  
  17.                 Logger.e("performJcodec: ""执行到的图片是 " + i);  
  18.             }  
  19.             se.finish();  
  20.             Logger.e("performJcodec: ""执行完成");  
  21.             //发送广播通知挂载文件  
  22.             context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(out)));  
  23.         } catch (IOException e) {  
  24.             Logger.e("performJcodec: ""执行异常 " + e.toString());  
  25.         }  
  26.     }  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值