从Java视频中获取缩略图
我想从servlet或任何其他服务器端Java方法中的视频创建缩略图 视频文件上传到服务器上,上传后应创建缩略图 我的问题不是创建缩略图,而是只创建一个或一定数量的缩略图 到目前为止,我的代码是:从Java视频中获取缩略图,java,video,thumbnails,Java,Video,Thumbnails,我想从servlet或任何其他服务器端Java方法中的视频创建缩略图 视频文件上传到服务器上,上传后应创建缩略图 我的问题不是创建缩略图,而是只创建一个或一定数量的缩略图 到目前为止,我的代码是: public class Test { public static void main(String[] args) throws IOException, InterruptedException, IM4JavaException { createThumbnail(new
public class Test {
public static void main(String[] args) throws IOException, InterruptedException, IM4JavaException {
createThumbnail(new File("00-50-C2-1D-7F-85_005.avi"), 512);
}
private static void createThumbnail(File sourceImage, int width) throws IOException,
InterruptedException, IM4JavaException {
ConvertCmd cmd = new ConvertCmd();
String destinationFileName = sourceImage.getName() + "_" + width + "_" + "thumb.png";
File thumbNailFile = new File(destinationFileName);
if (!thumbNailFile.exists()) {
IMOperation op = new IMOperation();
op.addImage(sourceImage.toString());
op.thumbnail(width);
op.addImage(destinationFileName);
cmd.run(op);
}
}
}
这里的问题是:对于视频中的每一帧,都会创建一个缩略图。在我的21012测试视频中,超过1000个缩略图被创建
在Java中,是否有任何方法可以每隔X
秒或帧从视频创建缩略图
编辑1:
我还尝试使用ffmpegwfom.day.cq.dam.handler.ffmpeg.FFMpegWrapper作为Maven依赖项:
<dependency>
<groupId>com.day.cq.dam</groupId>
<artifactId>cq-dam-video</artifactId>
<version>5.6.2</version>
</dependency>
另外,ViedeoImageSource取自:不起作用。
使用FFMpegWrapper()时,我没有收到任何缓冲图像
(getThumnbails()
返回null
),使用VideoImageSource时,我收到错误:
无法处理以下格式:H264、1536x1024、帧速率=50.0、长度=4722688 0个额外字节
未能实现:com.sun.media。PlaybackEngine@5defbbf
错误:无法实现com.sun.media。PlaybackEngine@5defbbf
线程“main”java.lang.IllegalArgumentException中出现异常:image
==零!在javax.imageio.ImageTypeSpecifier.CreateFromRenderImages(ImageTypeSpecifier.java:925)中
位于javax.imageio.imageio.getWriter(imageio.java:1591)
write(imageio.java:1520)位于
testVideos.Test2.main(Test2.java:37)
test2类中的任何方法都不起作用,类测试为每个帧提供了一个缩略图…:(我曾在另一个项目中使用过ffmpeg,您可以使用此工具阅读每种格式并创建缩略图want@chokdee我试过了(见我刚刚添加的test2类),但它返回“null”什么是FFMepgwrapper?我直接调用ffmepg实现了这一点:首先请看这里,谢谢您的帮助。但是当我从控制台使用ffmpeg时(顺便说一句,我使用的是arch linux 64位)如果没有
-vf“select=gt(scene\,0.4)”
的话,我的过滤器似乎是不正确的
public class Test2 {
public static void main(String[] args) throws IOException {
String videoName = "Roentgen_A_VisarioG2_005.avi";
File videoFile = new File(videoName);
testFFMpeg(videoFile); // FFMpeg
// lets try VideoImageSource
VideoImageSource viSource = new VideoImageSource(videoFile);
viSource.setMediaTime(10);
BufferedImage thumb = viSource.getImage();
File output = new File(videoName + "_thumb.png");
ImageIO.write(thumb, "png", output);
}
public static void testFFMpeg(File videoFile) throws IOException {
FFMpegWrapper wraper = new FFMpegWrapper(videoFile);
int length = (int) wraper.getInputDuration() / 1000 / 2;
BufferedImage[] thumbnail = wraper.getThumbnails(10, length);
if (thumbnail == null) {
System.out.println("[ERROR] no thumbnail created!");
return;
}
ImageIO.write(thumbnail[0], "png", new File(videoFile.getAbsolutePath() + "_thumb.png"));
}
}