FFMediaToolkit is a cross-platform video decoder/encoder library for .NET that uses FFmpeg native libraries. It supports video frames extraction, reading stream metadata and creating videos from bitmaps in any format supported by FFmpeg.
I am using this package to create a thumbnail for video via the azure function. when the video uploads to the blob it triggers the function. I am getting below error
System.Exception
HResult=0x80131500
Message=Failed to open the media stream
Source=FFMediaToolkit
StackTrace:
at FFMediaToolkit.Decoding.MediaFile.Open(Stream stream, MediaOptions options)
at FFMediaToolkit.Decoding.MediaFile.Open(Stream stream)
at Flexiata.Fcrm.ThumbnailCreator.VideoThumbNailCreateWithDrawing.Run(Stream stream, String name) in E:\Flexiata Code\fcrm2023\src\Flexiata.Fcrm.ThumbnailCreator\VideoThumbNailCreateWithDrawing.cs:line 49
at Microsoft.Azure.Functions.Worker.Invocation.VoidMethodInvoker2.InvokeAsync(TReflected instance, Object[] arguments) at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker2.InvokeAsync(Object instance, Object[] arguments)
at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.d__4.MoveNext()
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
FFmpegException: An error occurred while opening the file Error code: -1 : Operation not permitted
Azure function v4
net7.0
Code:
` using FFMediaToolkit;
using FFMediaToolkit.Decoding;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace Flexiata.Fcrm.ThumbnailCreator
{
public class VideoThumbNailCreate
{
private readonly ILogger _logger;
public VideoThumbNailCreate(ILogger<VideoThumbNailCreate> logger)
{
_logger = logger;
}
[Function(nameof(VideoThumbNailCreate))]
public async Task Run([BlobTrigger("%InputVideoBlobContainer%", Connection = "AzureWebJobsStorage")] Stream stream, string name)
{
try
{
var azure_root = $"{Environment.GetEnvironmentVariable("HOME")}/site/wwwroot";
FFmpegLoader.FFmpegPath = Path.Combine(azure_root, "ffmpeg", "x86_64");
_logger.LogInformation("FFmpeg {0}", FFmpegLoader.FFmpegPath);
}
catch (Exception ex)
{
// Ignore exceptions while loading the assemblies.
_logger.LogError(ex, "Error loading FFmpeg assemblies");
}
using var file = MediaFile.Open(stream);
}
}
}
`
The same code works with older .net versions. Any idea why this happens?
I am using this package to create a thumbnail for video via the azure function. when the video uploads to the blob it triggers the function. I am getting below error
System.Exception HResult=0x80131500 Message=Failed to open the media stream Source=FFMediaToolkit StackTrace: at FFMediaToolkit.Decoding.MediaFile.Open(Stream stream, MediaOptions options) at FFMediaToolkit.Decoding.MediaFile.Open(Stream stream) at Flexiata.Fcrm.ThumbnailCreator.VideoThumbNailCreateWithDrawing.Run(Stream stream, String name) in E:\Flexiata Code\fcrm2023\src\Flexiata.Fcrm.ThumbnailCreator\VideoThumbNailCreateWithDrawing.cs:line 49 at Microsoft.Azure.Functions.Worker.Invocation.VoidMethodInvokerd__4.MoveNext()
2.InvokeAsync(TReflected instance, Object[] arguments) at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker
2.InvokeAsync(Object instance, Object[] arguments) at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.This exception was originally thrown at this call stack: [External Code]
Inner Exception 1: FFmpegException: An error occurred while opening the file Error code: -1 : Operation not permitted
Azure function v4
Code: ` using FFMediaToolkit; using FFMediaToolkit.Decoding; using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging;
namespace Flexiata.Fcrm.ThumbnailCreator { public class VideoThumbNailCreate { private readonly ILogger _logger;
} `
The same code works with older .net versions. Any idea why this happens?