当部署到Azure函数时,我在使用python的视频哈希包时遇到了问题。
我部署的azure函数似乎无法正确地使用嵌套依赖项。具体来说,我试图使用包“视频散列”和它的函数VideoHash。VideoHash的输入是放置在Azure blob存储中的视频的SAS令牌。
在我输出的监视器中,它打印:
直接访问sas url令牌将我带到视频,因此该部分似乎正在工作。
查看视频哈希的源代码,此错误似乎发生在从给定的url (link:https://github.com/akamhy/videohash/blob/main/videohash/downloader.py). 下载视频的过程中。
。。其中self.yt_dlp_path =str(其中(“yt”))。在我看来,这表明在部署函数之后,包yt-dlp
没有被正确激活。这是来自videohash
模块的依赖项,但是直接将yt-dlp
添加到azure函数的需求文件中也不能解决这个问题。
对正在发生的事有什么想法吗?
将代码部署到Azure函数,这将导致问题描述中突出显示的详细信息。
发布于 2022-11-30 10:03:58
我在这里做了一项工作,您可以下载自己的视频文件,而不是使用azure.storage.blob
下载videohash
。
要下载
BlobServiceClient
、ContainerClient
和azure存储帐户的连接字符串.v1.mp3
和v2.mp3
的文件。档案结构:
完整守则:
import logging
from videohash import VideoHash
import azure.functions as func
import subprocess
import tempfile
import os
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
def main(req: func.HttpRequest) -> func.HttpResponse:
# local file path on the server
local_path = tempfile.gettempdir()
filepath1 = os.path.join(local_path, "v1.mp3")
filepath2 = os.path.join(local_path,"v2.mp3")
# Reference to Blob Storage
client = BlobServiceClient.from_connection_string("<Connection String >")
# Reference to Container
container = client.get_container_client(container= "test")
# Downloading the file
with open(file=filepath1, mode="wb") as download_file:
download_file.write(container.download_blob("v1.mp3").readall())
with open(file=filepath2, mode="wb") as download_file:
download_file.write(container.download_blob("v2.mp3").readall())
// video hash code .
videohash1 = VideoHash(path=filepath1)
videohash2 = VideoHash(path=filepath2)
t = videohash2.is_similar(videohash1)
return func.HttpResponse(f"Hello, {t}. This HTTP triggered function executed successfully.")
产出:
现在,我得到了ffmpeg
错误,它与我的测试文件有关,而与您所面临的错误无关。
据我所知,这一工作不会影响性能,因为在这两种情况下,您都在下载blobs。
https://stackoverflow.com/questions/74552478
复制相似问题