package com.fdkankan.scene.service.impl; import com.fdkankan.common.util.FileUtils; import com.fdkankan.fyun.face.FYunFileServiceInterface; import com.fdkankan.model.constants.ConstantFilePath; import com.fdkankan.model.constants.UploadFilePath; import com.fdkankan.model.utils.CreateObjUtil; import com.fdkankan.scene.service.ICommonService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.File; @Service public class CommonServiceImpl implements ICommonService { @Resource private FYunFileServiceInterface fYunFileService; @Override public void transferToFlv(String num, String fileName, String bucket) throws Exception { String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num); String localImagesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num); String localFilePath = localImagesPath + fileName; File targetFile = new File(localImagesPath); if (!targetFile.exists()){ targetFile.mkdirs(); } targetFile = new File(localFilePath); if (targetFile.exists()){ FileUtils.deleteFile(localFilePath); } //从用户编辑目录中下载视频到本地 String filePath = userEditPath + fileName; fYunFileService.downloadFile(bucket, filePath, localImagesPath + fileName); //视频格式转换 CreateObjUtil.mp4ToFlv(localFilePath, localFilePath.replace("mp4", "flv")); //上传 String flvFileName = fileName.replace("mp4", "flv"); fYunFileService.uploadFile(bucket, localFilePath.replace("mp4", "flv"), userEditPath+flvFileName); } }