【发布时间】:2023-01-24 05:08:42
【问题描述】:
我正在寻找 box.com 文件列表的视频持续时间,但在 API 中找不到任何地方如何做。我需要这个用于上传到 Box 的大量视频,所以我希望获取视频持续时间(您可以在视频预览中看到它)而不是下载整个文件。我在 Python 工作
【问题讨论】:
我正在寻找 box.com 文件列表的视频持续时间,但在 API 中找不到任何地方如何做。我需要这个用于上传到 Box 的大量视频,所以我希望获取视频持续时间(您可以在视频预览中看到它)而不是下载整个文件。我在 Python 工作
【问题讨论】:
这个问题一直困扰着我一段时间,以某种方式阅读视频的长度而不下载整个文件。 使用 pymediainfo 库进行一些测试,得出以下结果:
import time
from boxsdk import JWTAuth, Client
from pymediainfo import MediaInfo
video_folder_id = '191494027812'
user_rb_id = '18622116055'
def main():
auth = JWTAuth.from_settings_file('.jwt.config.json')
auth.authenticate_instance()
client = Client(auth)
user = client.user(user_rb_id).get()
print(f"User: {user.id}:{user.name}")
user_client = client.as_user(user)
folder = user_client.folder(video_folder_id).get()
print(f"Folder: {folder.id}:{folder.name}")
items = folder.get_items()
for item in items:
print(f"Item: {item.id}:{item.name}:{item.type}")
if item.type != 'file':
continue
item_url = item.get_download_url()
# print(f"URL {item_url}")
tic_download = time.perf_counter()
media_info = MediaInfo.parse(item_url)
print(f"MediaInfo w/ URL time: {time.perf_counter() - tic_download} seconds")
tic_download = time.perf_counter()
with open('./tmp/tpm_'+item.name, 'wb') as tmp_file:
item.download_to(tmp_file)
media_info = MediaInfo.parse('./tmp/tpm_'+item.name)
print(f"MediaInfo w/ download time: {time.perf_counter() - tic_download} seconds")
结果如下:
Folder: 191494027812:Video Samples
Item: 1121082178302:BigBuckBunny.mp4:file
MediaInfo w/ URL time: 3.798498541000299 seconds
MediaInfo w/ download time: 21.247453375020996 seconds
Done
查看运行 MediaInfo.parse() 所需的时间,似乎不需要下载整个文件。
在您的用例的小样本上尝试这种方法,看看它是否适合您。
【讨论】: