-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from jamebal/develop
perf: 将heic格式的图片转换jpg
- Loading branch information
Showing
20 changed files
with
124 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/jmal/clouddisk/video/FFMPEGCommand.java → ...m/jmal/clouddisk/media/FFMPEGCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...com/jmal/clouddisk/video/FFMPEGUtils.java → ...com/jmal/clouddisk/media/FFMPEGUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.jmal.clouddisk.media; | ||
|
||
import cn.hutool.core.io.FileUtil; | ||
import com.jmal.clouddisk.service.Constants; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import static com.jmal.clouddisk.util.FFMPEGUtils.getWaitingForResults; | ||
|
||
@Slf4j | ||
public class HeifUtils { | ||
|
||
/** | ||
* 将heic转换为jpg | ||
*/ | ||
public static String heifConvert(String inputPath) { | ||
if (!checkHeif()) { | ||
return null; | ||
} | ||
String outputPath = inputPath + ".jpg"; | ||
if (FileUtil.exist(outputPath)) { | ||
return outputPath; | ||
} | ||
try { | ||
ProcessBuilder processBuilder = heifConvert(inputPath, outputPath); | ||
Process process = processBuilder.start(); | ||
return getWaitingForResults(outputPath, processBuilder, process); | ||
} catch (InterruptedException e) { | ||
log.error(e.getMessage(), e); | ||
return null; | ||
} catch (IOException e) { | ||
log.error(e.getMessage(), e); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* 将heic转换为jpg | ||
* @param filepath heic文件绝对路径 | ||
* @return ProcessBuilder | ||
*/ | ||
private static ProcessBuilder heifConvert(String filepath, String outputPath) { | ||
ProcessBuilder processBuilder = new ProcessBuilder( | ||
Constants.HEIF_CONVERT, | ||
filepath, | ||
outputPath | ||
); | ||
processBuilder.redirectErrorStream(true); | ||
return processBuilder; | ||
} | ||
|
||
|
||
/** | ||
* 检查是否安装了heif-convert | ||
*/ | ||
public static boolean checkHeif() { | ||
try { | ||
Process process = Runtime.getRuntime().exec(Constants.HEIF_CONVERT); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
if (line.contains("output")) { | ||
return true; | ||
} | ||
} | ||
return true; | ||
} catch (IOException e) { | ||
log.error(e.getMessage(), e); | ||
} | ||
return false; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...jmal/clouddisk/video/TranscodeConfig.java → ...jmal/clouddisk/media/TranscodeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...jmal/clouddisk/video/TranscodeStatus.java → ...jmal/clouddisk/media/TranscodeStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.jmal.clouddisk.video; | ||
package com.jmal.clouddisk.media; | ||
|
||
import lombok.Getter; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...a/com/jmal/clouddisk/video/VideoInfo.java → ...a/com/jmal/clouddisk/media/VideoInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...com/jmal/clouddisk/video/VideoInfoDO.java → ...com/jmal/clouddisk/media/VideoInfoDO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.jmal.clouddisk.video; | ||
package com.jmal.clouddisk.media; | ||
|
||
import lombok.Data; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...m/jmal/clouddisk/video/VideoInfoUtil.java → ...m/jmal/clouddisk/media/VideoInfoUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.jmal.clouddisk.video; | ||
package com.jmal.clouddisk.media; | ||
|
||
public class VideoInfoUtil { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters