Browse Source

Quick fix for http resp writer in ffmpeg

Toby Chui 1 year ago
parent
commit
7715a8895f

+ 3 - 4
mod/agi/agi.ffmpeg.go

@@ -2,7 +2,6 @@ package agi
 
 import (
 	"errors"
-	"fmt"
 	"log"
 	"os"
 	"path/filepath"
@@ -60,8 +59,8 @@ func (g *Gateway) injectFFmpegFunctions(payload *static.AgiLibInjectionPayload)
 
 		compression, err := call.Argument(2).ToInteger()
 		if err != nil {
-			g.RaiseError(err)
-			return otto.FalseValue()
+			//Do not use compression
+			compression = 0
 		}
 
 		//Rewrite the vpath if it is relative
@@ -91,7 +90,7 @@ func (g *Gateway) injectFFmpegFunctions(payload *static.AgiLibInjectionPayload)
 			return otto.FalseValue()
 		}
 
-		fmt.Println(rinput, routput, bufferedFilepath)
+		//fmt.Println(rinput, routput, bufferedFilepath)
 
 		//Convert it to target format using ffmpeg
 		outputTmpFilename := uuid.NewV4().String() + filepath.Ext(routput)

+ 1 - 2
mod/agi/static/ffmpegutil/ffmpegutil.go

@@ -2,7 +2,6 @@ package ffmpegutil
 
 import (
 	"fmt"
-	"net/http"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -28,7 +27,7 @@ set to 512, then the output will be 512 * 1024
 
 Set compression to 0 if resizing / compression is not required
 */
-func FFmpeg_conv(input string, output string, compression int, w *http.ResponseWriter) error {
+func FFmpeg_conv(input string, output string, compression int) error {
 	var cmd *exec.Cmd
 
 	switch {

+ 8 - 1
web/FFmpeg Factory/backend/ffmpeg.js

@@ -33,8 +33,15 @@ function main(){
         return;
     }
 
+    var compressionRate = 0;
+    if (typeof(COMP) != "undefined"){
+        compressionRate = parseInt(COMP)
+    }
+    console.log("Using compression rate " + compressionRate);
+
+
     //Ok. Proceed with conversion
-    var succ = ffmpeg.convert(INPUT, OUTPUT);
+    var succ = ffmpeg.convert(INPUT, OUTPUT, compressionRate);
     if (succ){
         sendJSONResp(JSON.stringify("ok"));
     }else{

+ 1 - 1
web/FFmpeg Factory/index.html

@@ -16,7 +16,7 @@
                 {
                     "INPUT": "user:/Desktop/test.flac",
                     "OUTPUT":"user:/Desktop/out.mp3",
-                    "COMPRESS": 128 //128k
+                    "COMP": 32 //kbps
                 }, function(data){
                     console.log(data);
                     alert(data);