Skip to content

Commit

Permalink
Merge pull request #1 from MauriRojas/stream-from-sas-url
Browse files Browse the repository at this point in the history
Stream from sas url
  • Loading branch information
MauriRojas authored Mar 27, 2024
2 parents e1ddabc + 103ac11 commit 7eea8c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 10 additions & 9 deletions VirtualEncoder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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);
};
3 changes: 2 additions & 1 deletion host.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
}
},
"functionTimeout": "-1"
}

0 comments on commit 7eea8c7

Please sign in to comment.