diff --git a/VirtualEncoder/index.js b/VirtualEncoder/index.js index 6fcbd57..39bc4e0 100644 --- a/VirtualEncoder/index.js +++ b/VirtualEncoder/index.js @@ -3,17 +3,15 @@ const { resolve } = require('path'); const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path; const path = require("path"); -const streamToMux = (context) => { +const streamToMux = (context, blobSasUrl) => { return new Promise(async (resolve, reject) => { context.log(`Running ffmpeg from ${ffmpegPath}`); - var inputAbsolutePath = path.resolve("./input.mp4"); - - // ffmpeg -re -i myfile_1.mp4 -r 30 -c:v libx264 -x264-params keyint=60:scenecut=0 -preset fast -b:v 5M -maxrate 6M -bufsize 3M -threads 4 -f flv rtmp://global-live.mux.com:5222/app/{my_stream_key} + // ffmpeg -i myfile_1.mp4 -f flv rtmp://global-live.mux.com:5222/app/{my_stream_key} const child = childProcess.spawn( ffmpegPath, // note, args must be an array when using spawn - ['-i', `${inputAbsolutePath}`, '-f', 'flv', 'rtmp://global-live.mux.com:5222/app/5ac28812-8320-0c76-2ba2-313288af035f'], + ['-i', `${blobSasUrl}`, '-f', 'flv', 'rtmp://global-live.mux.com:5222/app/5ac28812-8320-0c76-2ba2-313288af035f'], { windowsVerbatimArguments: true, } @@ -40,20 +38,23 @@ const streamToMux = (context) => { resolve('Streamed successfully') } else { context.log(`FFmpeg encountered an error, check the console output`); - console.log(child); reject(`FFmpeg encountered an error, check the console output`); } }); }); }; -module.exports = async function (context, myQueueItem) { - context.log('JavaScript queue trigger function processing work item', myQueueItem); +module.exports = async function (context, blobSasUrl) { + context.log('JavaScript queue trigger function processing work item', blobSasUrl); // 2. Process the message here context.log('Starting streaming blob'); - var finished = await streamToMux(context); + try { + var finished = await streamToMux(context, blobSasUrl); + } catch (error) { + context.log("Error while streaming to Mux " + error); + } context.log("Finished execution", finished); }; \ No newline at end of file diff --git a/host.json b/host.json index fd4bee7..376cba4 100644 --- a/host.json +++ b/host.json @@ -11,5 +11,6 @@ "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[3.*, 4.0.0)" - } + }, + "functionTimeout": "-1" } \ No newline at end of file