问题描述
这个函数需要一个 URL 、目的地和文件名,然后下载文件。但是当我尝试使用 Google Photos API 制作视频时,视频文件出现此错误:
OSError: MoviePy error: Failed to read the duration of file .\ImageBin\yolo.mp4.
这里是下载部分的代码:
def download_file(url: str,destination_folder: str,file_name: str):
response = requests.get(url)
if response.status_code == 200:
with open(os.path.join(destination_folder,file_name),'wb') as f:
f.write(response.content)
编辑:我在运行时遇到的所有错误:
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\moviepy\video\io\ffmpeg_reader.py",line 286,in ffmpeg_parse_infos
match = re.findall("([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])",line)[0]
IndexError: list index out of range
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "C:/Users/defaultuser100000/Google Meets Intagram/Downloading_random_image_from_Google_Photos.py",line 122,in <module>
upload_video_to_instagram(r'.\ImageBin\yolo.mp4',cap)
File "C:\Users\defaultuser100000\Google Meets Intagram\Uploading_Photo_to_Instagram.py",line 14,in upload_video_to_instagram
bot.upload_video(video,caption=caption)
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\instabot\bot\bot.py",line 822,in upload_video
return upload_video(self,video,caption,thumbnail,options)
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\instabot\bot\bot_video.py",line 20,in upload_video
video,caption=caption,thumbnail=thumbnail,options=options
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\instabot\api\api.py",line 865,upload_id,options)
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\instabot\api\api_video.py",line 110,width,height,duration = resize_video(video,thumbnail)
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\instabot\api\api_video.py",line 248,in resize_video
vid = mp.VideoFileClip(fname)
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\moviepy\video\io\VideoFileClip.py",line 91,in __init__
fps_source=fps_source)
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\moviepy\video\io\ffmpeg_reader.py",line 36,in __init__
fps_source)
File "C:\Users\Aryan Garg\PycharmProjects\Google Meets Intagram\venv\lib\site-packages\moviepy\video\io\ffmpeg_reader.py",line 291,in ffmpeg_parse_infos
filename,infos))
OSError: MoviePy error: Failed to read the duration of file .\ImageBin\yolo.mp4.
Here are the file infos returned by ffmpeg:
ffmpeg version 4.2.2 copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20200122
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
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
Input #0,jpeg_pipe,from '.\ImageBin\yolo.mp4':
Duration: N/A,bitrate: N/A
Stream #0:0: Video: mjpeg (Baseline),yuvj444p(pc,bt470bg/unkNown/unkNown),262x512 [SAR 1:1 DAR 131:256],25 tbr,25 tbn,25 tbc
At least one output file must be specified
holy_image = choice(Base_URL_list)
尽管它的名字是 Holy_image 实际上只是一个 URL 列表,既可以是视频也可以是图像
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)