如果我将一个 url 放入数组中,一切正常,但是当我向数组中添加多个 url 时,它会抛出一个错误:
HTTP error 403 Forbidden https://p16-sign-sg.tiktokcdn.com/tos-alisg-i-photomode-sg/2c182489bc4e42dcbb70f37a283cf5f1~tplv-photomode-image.jpeg?from=photomode.AWEME_DETAIL&x-expires=1681740000&x-signature=BaB75chVtpoZg6sE%2B0oWmxtzky0%3D https://p16-sign-sg.tiktokcdn.com/tos-alisg-i-photomode-sg/34cae24dad35476d96d8db03b46076b9~tplv-photomode-image.jpeg?from=photomode.AWEME_DETAIL&x-expires=1681740000&x-signature=RTyGbq%2BfLz3hNahtLJyaWycQtPI%3D: Server returned 403 Forbidden (access denied)
但是,如果我将每个 URL 一个一个地放置,那么就可以访问并且一切正常
感觉 ffmpeg 做出了三个 url 中的一个并因此捕获了一个错误。但我不明白如何处理网址。
我的代码:
from PIL import Image
from io import BytesIO
import requests
import ffmpeg
def make_even(n):
return n + n % 2
list_of_urls = [
"https://p16-sign-sg.tiktokcdn.com/tos-alisg-i-photomode-sg/2c182489bc4e42dcbb70f37a283cf5f1~tplv-photomode-image.jpeg?from=photomode.AWEME_DETAIL&x-expires=1681740000&x-signature=BaB75chVtpoZg6sE%2B0oWmxtzky0%3D",
"https://p16-sign-sg.tiktokcdn.com/tos-alisg-i-photomode-sg/34cae24dad35476d96d8db03b46076b9~tplv-photomode-image.jpeg?from=photomode.AWEME_DETAIL&x-expires=1681740000&x-signature=RTyGbq%2BfLz3hNahtLJyaWycQtPI%3D",
"https://p16-sign-sg.tiktokcdn.com/tos-alisg-i-photomode-sg/c2cb000f9332498caf6bd837f42e92c6~tplv-photomode-image.jpeg?from=photomode.AWEME_DETAIL&x-expires=1681740000&x-signature=4Zh5PFWNUYQhxQHuKM7P8rk8geU%3D"
]
response = requests.get(list_of_urls\[0\])
img = Image.open(BytesIO(response.content))
width, height = img.size
width = make_even(width)
height = make_even(height)
(
ffmpeg
.input(' '.join(list_of_urls), framerate=0.33)
.filter('scale', width, height)
.output('output.mp4')
.run()
)