如何让 FFProbe 使用 dotnet core 作为 Docker 中的 Azure 函数运行?

编程入门 行业动态 更新时间:2024-10-21 13:32:54
本文介绍了如何让 FFProbe 使用 dotnet core 作为 Docker 中的 Azure 函数运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从基于 URL 的视频中获取视频详细信息(长度、高度、宽度和内容类型).通过使用 nuget 包 www.nuget/packages/NReco.VideoInfo.LT 我能够创建一个本地运行的 Azure 函数,指向我本地安装的 FFProbe 相当容易.然而,现在的诀窍是让它与 Azure 函数兼容,据我所知,最简单的方法是提供一个包含所需一切的 Docker 映像(这将在 Linux 机器上运行).

I am trying to get video details (length, height, width, and content type) from a video based on a URL. By using the nuget package www.nuget/packages/NReco.VideoInfo.LT I was able to create an Azure Function running locally pointing to my local install of FFProbe rather easily. However, the trick is now making it compatible with an Azure Function and, to the best of my knowledge, the easiest way to do that is by providing a Docker image that contains everything needed (this would be running on a Linux machine).

那么,让我们进入代码.以前,如果我在本地运行该函数,这就是我的工作:

So, let's get into the code. Previously, this is what I had working if I ran the function locally:

var ffProbe = new NReco.VideoInfo.FFProbe(); ffProbe.FFProbeExeName = "ffprobe.exe"; // just "ffprobe" for Linux/OS-X ffProbe.ToolPath = "C:\tools\ffmpeg\bin"; var videoInfo = ffProbe.GetMediaInfo(videoUrl);

现在,(再一次,这是我所知道的最好的),为了让它在使用 Docker 的 Linux 环境中运行,我遇到了几个问题.

Now, (and again, this is the best to my knowledge), to get it to run in a Linux environment using Docker, I've run into several issues.

所以,第一次尝试是我认为的简单方法,并尝试执行 apt-get install ffmpeg.这是 Dockerfile(抱歉,这将是一篇很长的文章……但最好展示我认为的所有内容):

So, the first attempt was the easy way I suppose and try to do a apt-get install ffmpeg. This was the Dockerfile (Sorry, this is going to be a long post... but better to show everything I suppose):

FROM mcr.microsoft/dotnet/core/sdk:3.1 AS installer-env # 0. Install essential packages RUN apt-get -y update RUN apt-get -y upgrade RUN apt-get install -y ffmpeg ENV AzureWebJobsStorage="" COPY . /src/dotnet-function-app RUN cd /src/dotnet-function-app && mkdir -p /home/site/wwwroot && dotnet publish *.csproj --output /home/site/wwwroot RUN mkdir -p /home/site/wwwroot/bin RUN mv /usr/bin/* /home/site/wwwroot/bin # To enable ssh & remote debugging on app service change the base image to the one below # FROM mcr.microsoft/azure-functions/dotnet:3.0-appservice FROM mcr.microsoft/azure-functions/dotnet:3.0 ENV AzureWebJobsScriptRoot=/home/site/wwwroot AzureFunctionsJobHost__Logging__Console__IsEnabled=true COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

我把代码改成

var ffProbe = new NReco.VideoInfo.FFProbe(); ffProbe.FFProbeExeName = "ffprobe"; // just "ffprobe" for Linux/OS-X ffProbe.ToolPath = "/home/site/wwwroot/bin"; var videoInfo = ffProbe.GetMediaInfo(videoUrl);

构建,但是当我运行它时,我得到一个错误:加载共享库时出错:libavdevice.so.58

That builds, but when I run it, I get an error: error while loading shared libraries: libavdevice.so.58

所以,我做了一些挖掘工作,看起来我必须走手动构建路线.这并不理想,但我试了一下并调整了 Dockerfile:

So, I do some digging and it looks like I have to go the manual build route. Which isn't ideal, but I give it a go and adjust the Dockerfile:

FROM mcr.microsoft/dotnet/core/sdk:3.1 AS installer-env # 0. Install essential packages RUN apt-get update -qq && apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev nasm yasm libx265-dev libnuma-dev libvpx-dev libmp3lame-dev libopus-dev libx264-dev RUN mkdir -p /home/site/wwwroot RUN mkdir -p /home/site/wwwroot/ffmpeg_sources /home/site/wwwroot/bin && cd /home/site/wwwroot/ffmpeg_sources && wget -O ffmpeg-4.3.1.tar.bz2 ffmpeg/releases/ffmpeg-4.3.1.tar.bz2 && tar xjvf ffmpeg-4.3.1.tar.bz2 && cd ffmpeg-4.3.1 && PATH="/home/site/wwwroot/bin:$PATH" PKG_CONFIG_PATH="/home/site/wwwroot/ffmpeg_build/lib/pkgconfig" ./configure --prefix="/home/site/wwwroot/ffmpeg_build" --pkg-config-flags="--static" --extra-cflags="-I/home/site/wwwroot/ffmpeg_build/include" --extra-ldflags="-L/home/site/wwwroot/ffmpeg_build/lib" --extra-libs="-lpthread -lm" --bindir="/home/site/wwwroot/bin" --enable-gpl --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree && PATH="/home/site/wwwroot/bin:$PATH" make -j8 && make install -j8 && hash -r ENV AzureWebJobsStorage="" COPY . /src/dotnet-function-app RUN cd /src/dotnet-function-app && dotnet publish *.csproj --output /home/site/wwwroot FROM mcr.microsoft/azure-functions/dotnet:3.0 ENV AzureWebJobsScriptRoot=/home/site/wwwroot AzureFunctionsJobHost__Logging__Console__IsEnabled=true COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

再次构建,然后我尝试运行,这次得到相同的错误,但文件不同:加载共享库时出错:libxcb.so.1

Again, that builds and then I try to run, this time getting the same error but for a different file: error while loading shared libraries: libxcb.so.1

所以,我应该提到 Docker 对我来说有点新,所以我可能会遗漏一些简单的东西.但我整晚都在试图解决这个问题,直到我决定需要一些建议.我的主应用程序也托管在一台 linux 机器上,所以那是不行的.除了 Azure Function 方法之外,另一个疯狂的想法是以每月 20 美元的价格构建一个低优先级的 Windows VM……但是我必须配置 IIS 和所有这些东西.因此,弄清楚我做错了什么或者它是否可行会很棒.在基于 github/rebremer/azure-function-selenium...所以我希望只是我对 Docker 不够熟悉.

So, I should mention that Docker is somewhat new to me, so I could be missing something easy. But I've tried to figure this out all night until I decided that I needed some advice. My main app is also hosted on a linux machine, so that would be a no go there. Besides the Azure Function approach, the other crazy idea is spinning up a low-priority Windows VM for like $20 a month... but then I have to configure IIS and all that stuff. So, it would be great to figure out what I'm doing wrong or if it's even feasible. I've gotten Python/Selenium to work using Docker and Azure Functions before based off of github/rebremer/azure-function-selenium... so I'm hoping it's just me not being familiar with Docker enough.

如果能帮助我完成这项工作,我们将不胜感激.如果您有任何问题,请不要犹豫.

Any help to get this working for me would be greatly appreciated. If you have any questions, please don't hesitate to ask.

谢谢!

推荐答案

当我意识到 Docker 中 Azure Functions 的镜像基本上是从 Ubuntu 开始时,我的解决方案最终没有使用另一个 Docker 镜像.意识到这一点,我的 Dockerfile 出来了

My solution ended up not using another Docker image once I realized that basically the image for Azure Functions in Docker starts off with Ubuntu. Realizing that, my Dockerfile came out to be

FROM mcr.microsoft/dotnet/core/sdk:3.1 AS installer-env COPY . /src/dotnet-function-app RUN cd /src/dotnet-function-app && mkdir -p /home/site/wwwroot && dotnet publish *.csproj --output /home/site/wwwroot FROM mcr.microsoft/azure-functions/dotnet:3.0 ENV AzureWebJobsScriptRoot=/home/site/wwwroot AzureFunctionsJobHost__Logging__Console__IsEnabled=true AzureWebJobsStorage="" COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"] RUN apt-get update && apt-get install -y ffmpeg

所以,它最终成为一个非常简单的解决方案.让 Azure 构建映像,将网站复制到 wwwroot,然后像通常在 Ubuntu 上一样安装 ffmpeg!然后,只需将代码更新为:

So, it ended up being a really simple solution. Have Azure build the image, copy the website to wwwroot and then install ffmpeg like you would normally on Ubuntu! Then, it was a matter of just updating the code to:

var ffProbe = new NReco.VideoInfo.FFProbe(); ffProbe.FFProbeExeName = "ffprobe"; // just "ffprobe" for Linux/OS-X ffProbe.ToolPath = "/usr/bin"; var mediaInfo = ffProbe.GetMediaInfo(videoUrl);

就是这样!

更多推荐

如何让 FFProbe 使用 dotnet core 作为 Docker 中的 Azure 函数运行?

本文发布于:2023-11-17 04:50:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608895.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   dotnet   FFProbe   core   Azure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!