The Goal
I want to make a POC that allows me to upload a part of a RTMP stream to azure blob storage, using ffmpeg. In my case this will be done with Azure functions as a QueueTrigger background job.
Currently I manually close ffmpeg (pressing q in terminal) so the stream ends and can be fully written to the blob storage.
I use Emulated Storage with Azurite and locally hosted Azure functions
Progress
I found enough info about how to make ffmpeg work with C#
var process = new ProcessStartInfo();
process.FileName = "ffmpeg";
process.RedirectStandardOutput = true;
process.UseShellExecute = false;
process.Arguments = "-i rtmp://10.10.10.4/live/test -loglevel panic -f flv pipe:1";
This should start ffmpeg with no logs -loglevel panic, correct format -f flvand pipe it to standard output pipe:1.
Then I access the blob container and create a new file:
uniqueFileName = string.Format(@"{0}" + ".flv", Guid.NewGuid());
blob = blobClient.GetBlobClient(uniqueFileName);
Current problem
Uploading to the blob storage. It seems there is no method that works.
Attempt 1: Upload Async
I would start the process and tell the blobclient to upload whatever is on the stream.
var runningProcess = Process.Start(process);
await blob.UploadAsync(runningProcess.StandardOutput.BaseStream, true);
This results in the following error when accessing the StorageExplorer:
The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
This also breaks the blob container, it must be deleted and another container must be made.
Attempt 2: OpenWriteAsync
I would open the Blob's stream and write to it as the ffmpeg stream went on.
using (var stream = await blob.OpenWriteAsync(true))
{
log.LogInformation("Starting FFmpeg");
var runningProcess = Process.Start(process);
log.LogInformation("Started FFMPEG");
while ((bytesRead = runningProcess.StandardOutput.BaseStream.Read(buffer)) != 0)
{
stream.Write(buffer, 0, bytesRead);
}
}
The same error occurred, though I seem closer to actually writing content to the blob as the live stream progresses.
At this point I wonder if it is possible to do what I intend. I looked at multiple other threads that worked with files, but all are using completed files, not stream that are still being written to.