java 视频 缩略图_如何使用java提取视频缩略图或某一帧的图片
[Java] 純文本查看 復制代碼public class CreateImage {
/**
* 獲取指定視頻的幀并保存為圖片至指定目錄
* [url=home.php?mod=space&uid=952169]@Param[/url] videofile 源視頻文件路徑
* @param framefile 截取幀的圖片存放路徑
* @throws Exception
*/
public static void fetchFrame(String videofile, String framefile)
throws Exception {
long start = System.currentTimeMillis();
File targetFile = new File(framefile);
FFmpegFrameGrabber ff = new FFmpegFrameGrabber(videofile);
ff.start();
int lenght = ff.getLengthInFrames();
int i = 0;
Frame f = null;
while (i < lenght) {
// 過濾前5幀,避免出現(xiàn)全黑的圖片,依自己情況而定
f = ff.grabFrame();
if ((i > 5) && (f.image != null)) {
break;
}
i++;
}
opencv_core.IplImage img = f.image;
int owidth = img.width();
int oheight = img.height();
// 對截取的幀進行等比例縮放
int width = 800;
int height = (int) (((double) width / owidth) * oheight);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
bi.getGraphics().drawImage(f.image.getBufferedImage().getScaledInstance(width, height, Image.SCALE_SMOOTH),
0, 0, null);
ImageIO.write(bi, "jpg", targetFile);
//ff.flush();
ff.stop();
System.out.println(System.currentTimeMillis() - start);
}
public static void main(String[] args) {
try {
CreateImage.fetchFrame("D:\\1.mp4", "D:\\test5.jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
}
總結
以上是生活随笔為你收集整理的java 视频 缩略图_如何使用java提取视频缩略图或某一帧的图片的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机网络日志查询,系统资源管理_百络网
- 下一篇: ajax通过什么实现,ajax(通过jQ