package com.iplatform.recvideo.util;
|
|
import com.iplatform.recvideo.Constants;
|
import com.iplatform.recvideo.VideoFolderInfo;
|
import com.walker.infrastructure.utils.StringUtils;
|
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);
|
|
/**
|
* 拼接视频批量(存储)文件夹路径,如: /opt/ai/video/20220921,其中'20220921'为批量号
|
* @param videoDataFolder
|
* @param batchId
|
* @return
|
*/
|
public static final String combineBatchPath(String videoDataFolder, String batchId){
|
String batchFolderPath = null;
|
if(videoDataFolder.endsWith(StringUtils.FOLDER_SEPARATOR)){
|
batchFolderPath = videoDataFolder + batchId;
|
} else {
|
batchFolderPath = videoDataFolder + StringUtils.FOLDER_SEPARATOR + batchId;
|
}
|
return batchFolderPath;
|
}
|
|
public static final List<VideoFolderInfo> getBatchVideoFolderInfo(String videoDataFolder, String batchId){
|
// String batchFolderPath = videoDataFolder + File.separator + batchId;
|
String batchFolderPath = combineBatchPath(videoDataFolder, batchId);
|
// if(videoDataFolder.endsWith(StringUtils.FOLDER_SEPARATOR)){
|
// batchFolderPath = videoDataFolder + batchId;
|
// } else {
|
// batchFolderPath = videoDataFolder + StringUtils.FOLDER_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());
|
}
|
}
|
}
|