Просмотр исходного кода

FFmpegWrapper 添加音频转换方法

reghao 2 лет назад
Родитель
Сommit
9b2e52c3c7
1 измененных файлов с 16 добавлено и 12 удалено
  1. 16 12
      media/src/main/java/cn/reghao/jutil/media/FFmpegWrapper.java

+ 16 - 12
media/src/main/java/cn/reghao/jutil/media/FFmpegWrapper.java

@@ -77,23 +77,22 @@ public class FFmpegWrapper {
                 }
             }
 
-            if (videoProps == null) {
-                return null;
-            }
-
             JsonObject format = jsonObject.get("format").getAsJsonObject();
-            if (format.get("duration") != null) {
-                Double duration = format.get("duration").getAsDouble();
-                videoProps.setDuration(duration);
-            }
+            if (videoProps != null) {
+                if (format.get("duration") != null) {
+                    Double duration = format.get("duration").getAsDouble();
+                    videoProps.setDuration(duration);
+                }
 
-            Long size = format.get("size").getAsLong();
-            if (format.get("bit_rate") != null) {
-                Double bitRate = format.get("bit_rate").getAsDouble();
-                videoProps.setBitRate(bitRate);
+                Long size = format.get("size").getAsLong();
+                if (format.get("bit_rate") != null) {
+                    Double bitRate = format.get("bit_rate").getAsDouble();
+                    videoProps.setBitRate(bitRate);
+                }
             }
 
             MediaProps mediaProps = new MediaProps(audioProps, videoProps);
+            // Metadata
             JsonElement tagsElement = format.get("tags");
             if (tagsElement != null) {
                 JsonObject tags = tagsElement.getAsJsonObject();
@@ -115,6 +114,11 @@ public class FFmpegWrapper {
         return Shell.exec(cmd);
     }
 
+    public static int convertAudio(String srcPath, String destPath) {
+        String cmd = String.format("%s -loglevel error -y -i '%s' -c:a aac '%s'", ffmpeg, srcPath, destPath);
+        return Shell.exec(cmd);
+    }
+
     public static int qualityCovert(String srcPath, int width, int height, String destPath) {
         String audioBitRate = "128k";
         String videoBitRate = "1500k";