我有一個 Google App Engine ( GAE ) 應用程式,在前端使用 Vue.js,在后端使用 Flask。我的應用程式允許用戶上傳大型視頻并對其進行分析。但由于 GAE 的上傳大小限制為 32MB,所以我允許用戶使用簽名的 url直接上傳到 Google Cloud Storage( GCS ) 。
我面臨的問題是用戶可以成功將視頻上傳到GCS,但是在后端(flask)下載視頻進行分析時,得到以下錯誤:
*** OSError: MoviePy error: failed to read the duration of file /tmp/source_video.mp4.
Here are the file infos returned by ffmpeg:
ffmpeg version 4.2.2-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7444500] Format mov,mp4,m4a,3gp,3g2,mj2 detected only with low score of 1, misdetection possible!
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7444500] moov atom not found
/tmp/source_video.mp4: Invalid data found when processing input
燒瓶代碼下載:
class Analyser:
def __init__(self):
self.gcs_bucket = 'bucket_name'
self.gcs_blob_video = 'videos/'
def __storage_bucket(self):
client = storage.Client()
bucket = client.get_bucket(self.gcs_bucket)
bucket.cors = [
{
"origin": ["*"],
"responseHeader": [
"Access-Control-Allow-Origin"
],
"method": ['PUT', 'POST', 'GET'],
"maxAgeSeconds": 3600
}
]
bucket.patch()
return bucket
def __generate_upload_signed_url(self, bucket, blob):
blob = bucket.blob(blob)
return blob.generate_signed_url(
version='v4',
expiration=datetime.timedelta(minutes=15),
method='PUT',
)
def analyze_video(self, pid):
src_filepath = '/tmp/source_video.mp4'
bucket = self.__storage_bucket()
blob = bucket.blob(self.gcs_blob_video 'filename.mp4')
blob.download_to_filename(src_filepath)
#error is here
video = VideoFileClip(src_filepath)
Vuejs代碼上傳:
注意:上傳成功,gcs上有檔案要上傳。
async uploadVideo(_: any, video: File): Promise<string> {
signed_url = "https://storage.googleapis.com/bucket_name...." #signed url is return from flask
const formData = new FormData();
formData.append('file', video);
const response_upload_file = await fetch(
signed_url,
{
method: 'PUT',
body: formData
}
)
return true
}
我在谷歌上搜索了很多,但仍然沒有找到解決方案。
我真的不知道它是在上傳程序中壞了還是在我下載分析時壞了。如果有人可以建議我解決此問題的解決方案,我將不勝感激。
謝謝閱讀。
uj5u.com熱心網友回復:
您正在將formData與 HTTP PUT方法一起使用,該方法會破壞上傳,因為預期的二進制資料流而不是 MIME 資料。
要使用表單資料:
上傳帶有 HTML 表單的物件
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/425143.html
