CommonServiceImpl.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.fdkankan.scene.service.impl;
  2. import com.fdkankan.common.util.FileUtils;
  3. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  4. import com.fdkankan.model.constants.ConstantFilePath;
  5. import com.fdkankan.model.constants.UploadFilePath;
  6. import com.fdkankan.model.utils.CreateObjUtil;
  7. import com.fdkankan.scene.service.ICommonService;
  8. import org.springframework.stereotype.Service;
  9. import javax.annotation.Resource;
  10. import java.io.File;
  11. @Service
  12. public class CommonServiceImpl implements ICommonService {
  13. @Resource
  14. private FYunFileServiceInterface fYunFileService;
  15. @Override
  16. public void transferToFlv(String num, String fileName, String bucket) throws Exception {
  17. String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  18. String localImagesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
  19. String localFilePath = localImagesPath + fileName;
  20. File targetFile = new File(localImagesPath);
  21. if (!targetFile.exists()){
  22. targetFile.mkdirs();
  23. }
  24. targetFile = new File(localFilePath);
  25. if (targetFile.exists()){
  26. FileUtils.deleteFile(localFilePath);
  27. }
  28. //从用户编辑目录中下载视频到本地
  29. String filePath = userEditPath + fileName;
  30. fYunFileService.downloadFile(bucket, filePath, localImagesPath + fileName);
  31. //视频格式转换
  32. CreateObjUtil.mp4ToFlv(localFilePath, localFilePath.replace("mp4", "flv"));
  33. //上传
  34. String flvFileName = fileName.replace("mp4", "flv");
  35. fYunFileService.uploadFile(bucket, localFilePath.replace("mp4", "flv"), userEditPath+flvFileName);
  36. }
  37. }