javacv視頻抽幀的實現(xiàn)過程詳解(附代碼)
更新時間:2019年07月11日 10:16:26 作者:行走在江湖
這篇文章主要介紹了javacv視頻抽幀的實現(xiàn)過程詳解(附代碼),視頻抽幀可以做一些處理,比如水印,去水印等操作,然后再合成視頻,需要的朋友可以參考下
視頻抽幀可以做一些處理,比如水印,去水印等操作,然后再合成視頻。下面直接上代碼:
引入maven步驟看javacv去水印的文章
這里直接上關(guān)鍵操作:
/** * 視頻文件指定時間段的幀截取 * @param file * @param start * @param end */ public static List<File> videoIntercept(File file, Integer start, Integer end) { Frame frame = null; List<File> files = Lists.newArrayList(); FFmpegFrameGrabber fFmpegFrameGrabber = new FFmpegFrameGrabber(file); String filePath = "D://video//images//"; String fileTargetName = "movie"; try { fFmpegFrameGrabber.start(); int ftp = fFmpegFrameGrabber.getLengthInFrames(); System.out.println("開始視頻提取幀"); for (int i=0 ; i < ftp ; i++){ if( i >= start && i <= end){ frame = fFmpegFrameGrabber.grabImage(); doExecuteFrame(frame, filePath, fileTargetName, i ,files); } } System.out.println("============運行結(jié)束============"); fFmpegFrameGrabber.stop(); } catch (IOException E) { // Loggers.ERROR.error("視頻抽幀異常", e); } return files; } public static void doExecuteFrame(Frame frame, String targetFilePath, String targetFileName, int index ,List<File> files) { if ( frame == null || frame.image == null) { return; } Java2DFrameConverter converter = new Java2DFrameConverter(); String imageMat = "jpg"; String fileName = targetFilePath + targetFileName + "_" + index + "." + imageMat; BufferedImage bi = converter.getBufferedImage(frame); File output = new File(fileName); files.add(output); try{ ImageIO.write(bi, imageMat, output); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { List<File> files = videoIntercept(new File("D://video//1553583033205-480p.mp4"), 10, 20); System.out.println(files); }
我們可以看到文件夾下抽取了視頻的第10,20之間的幀。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
如何使用Spring AOP預(yù)處理Controller的參數(shù)
這篇文章主要介紹了如何使用Spring AOP預(yù)處理Controller的參數(shù)操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08如何修改FeginCilent定義的服務(wù)名到指定服務(wù)
這篇文章主要介紹了修改FeginCilent定義的服務(wù)名到指定服務(wù)的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07Springboot使用Redis中ZSetOperations實現(xiàn)博客訪問量
在日常的網(wǎng)站使用中,經(jīng)常會碰到頁面的訪問量,本文主要介紹了Springboot使用Redis中ZSetOperations實現(xiàn)博客訪問量,具有一定的參考價值,感興趣的可以了解一下2024-01-01Java concurrency之AtomicLongFieldUpdater原子類_動力節(jié)點Java學(xué)院整理
AtomicLongFieldUpdater可以對指定"類的 'volatile long'類型的成員"進行原子更新。它是基于反射原理實現(xiàn)的。下面通過本文給大家分享Java concurrency之AtomicLongFieldUpdater原子類的相關(guān)知識,感興趣的朋友一起看看吧2017-06-06