Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
use
<dependency>
<groupId>org.mountcloud</groupId>
<artifactId>ffmpeg-operate</artifactId>
<version>1.0</version>
</dependency>
description
Prerequisites The project uses environment installed FFMPEG, and can use FFMPEG command in the console. The project greatly facilitates the use of java FFMPEG function.
Project built three operations on video 1: video format into M3U8 (FFMpegVideoFormatM3u8), 2: View Video Properties (FFMpegVideoInfo), 3: Video capture (FFMpegVideoScreenShot). It can also be extended through inheritance FFMpegOperationBase.
Feature
1: You can get a percentage of the implementation progress of the task.
2: very high scalability.
3: multi-threaded operating mode.
Demo example
@Test
public void convertM3u8() {
//create result bean
FFVideoInfoResult result = new FFVideoInfoResult();
//find video info
FFMpegVideoInfo ffMpegVideoInfo = new FFMpegVideoInfo();
ffMpegVideoInfo.setVideoUrl("D:\\cma_15307640036trzll1p.mp4");
FFMepgVideoInfoTask videoInfoTask = new FFMepgVideoInfoTask(result,ffMpegVideoInfo);
FFTaskContext.getContext().submit(videoInfoTask,null);
String bitrate = "5286k";
//create to m3u8 operation
FFMpegVideoFormatM3u8 m3u8Operation = new FFMpegVideoFormatM3u8();
m3u8Operation.setVideoFileName("D:\\cma_15307640036trzll1p.mp4");
m3u8Operation.setBitrate(bitrate);
m3u8Operation.setTimes(5);
m3u8Operation.setM3u8File("D:\\cma_15307640036trzll1p\\cma_15307640036trzll1p.m3u8");
m3u8Operation.setTsFiles("D:\\cma_15307640036trzll1p\\cma_15307640036trzll1p%5d.ts");
//to m3u8 task
FFMepgVideoFormatM3u8Task task = new FFMepgVideoFormatM3u8Task(m3u8Operation);
//add task
FFTaskContext.getContext().addTask(task);
while(!task.getProgress().getState().equals(FFTaskStateEnum.COMPLETE)){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
}
System.out.println("COMPLETE");
}
note Notes
1:.. FFTaskContext.getContext () addTask (task) is an asynchronous task, FFTaskContext.getContext () submit (taks) is a synchronization task