package com.iplatform.recvideo.util;
|
|
import com.iplatform.recvideo.Constants;
|
import com.iplatform.recvideo.ImageInfo;
|
import com.iplatform.recvideo.VideoFolderInfo;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
import java.io.File;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
public class VideoFileUtils {
|
|
protected static final transient Logger logger = LoggerFactory.getLogger(VideoFileUtils.class);
|
|
public static final List<VideoFolderInfo> getBatchVideoFolderInfo(String videoDataFolder, String batchId){
|
String batchFolderPath = videoDataFolder + File.separator + batchId;
|
File batchFolder = new File(batchFolderPath);
|
if(!batchFolder.exists()){
|
logger.error("视频文件夹不存在,无法获取图片集合信息。batchFolderPath = " + batchFolderPath);
|
return null;
|
}
|
File[] files = batchFolder.listFiles();
|
if(files == null || files.length == 0){
|
logger.error("视频文件夹下没有任何图像文件夹: " + batchFolderPath);
|
return null;
|
}
|
|
List<VideoFolderInfo> resultList = new ArrayList<>();
|
|
VideoFolderInfo videoFolderInfo = null;
|
for(File file : files){
|
if(file.isFile()){
|
continue; // 视频文件忽略,只看文件夹
|
}
|
videoFolderInfo = new VideoFolderInfo(file.getName());
|
// logger.debug("find folder = " + file.getName() + ", " + file.getAbsolutePath());
|
acquireImagesInVideoFolder(file, videoFolderInfo);
|
resultList.add(videoFolderInfo);
|
}
|
return resultList;
|
}
|
|
private static void acquireImagesInVideoFolder(File imageFolder, VideoFolderInfo videoFolderInfo){
|
// ImageInfo imageInfo = null;
|
File[] imageFiles = imageFolder.listFiles();
|
for(File file : imageFiles){
|
if(!file.isFile()){
|
continue;
|
}
|
if(!file.getName().endsWith(Constants.IMAGE_SUFFIX)){
|
logger.warn("图像后缀名不是指定格式'.jpg', name = " + file.getName());
|
continue;
|
}
|
// imageInfo = new ImageInfo();
|
// imageInfo.setVideoId(videoFolderInfo.getVideoId());
|
// imageInfo.setImagePath(file.getAbsolutePath());
|
// imageInfo.setImageName(file.getName());
|
videoFolderInfo.addImageInfo(file.getAbsolutePath(), file.getName());
|
}
|
}
|
}
|