opencv的报错
KeyError: ‘video_fps’
---------------------------------------------------------------------------KeyError Traceback (most recent call last)<ipython-input-28-aa49daf0c5c8> in <module>39 # 第六步:加上音频40 if not os.path.exists(out_video_path):
---> 41 sound2video(org_video_path=human_video_path, new_video_path=img2video_path, out_video_path=out_video_path)42 else:43 print('最终视频已存在,请查看输出路径')
<ipython-input-26-df6486375f5b> in sound2video(org_video_path, new_video_path, out_video_path)14 15 # 2.读取新生成视频
---> 16 video_clip = VideoFileClip(new_video_path)17 18 # 3.合成音频与视频
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/moviepy/video/io/VideoFileClip.py in __init__(self, filename, has_mask, audio, audio_buffersize, target_resolution, resize_algorithm, audio_fps, audio_nbytes, verbose, fps_source)89 target_resolution=target_resolution,90 resize_algo=resize_algorithm,
---> 91 fps_source=fps_source)92 93 # Make some of the reader's attributes accessible from the clip
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/moviepy/video/io/ffmpeg_reader.py in __init__(self, filename, print_infos, bufsize, pix_fmt, check_duration, target_resolution, resize_algo, fps_source)32 infos = ffmpeg_parse_infos(filename, print_infos, check_duration,33 fps_source)
---> 34 self.fps = infos['video_fps']35 self.size = infos['video_size']36 self.rotation = infos['video_rotation']
KeyError: 'video_fps'
没办法,直接把代码里的fps设定了个定值,不报错了,但是输出的视频无法播放
然后又尝试了不输出MP4,输出AVI格式,可以输出,可以播放
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
videoWrite = cv2.VideoWriter('test-2.avi', fourcc, 30, size)
但是,又出来个新的错误
OSError: MoviePy error: failed to read the duration of
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5b29b80] moov atom not found
./c.mp4: Invalid data found when processing input
---------------------------------------------------------------------------IndexError Traceback (most recent call last)/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/moviepy/video/io/ffmpeg_reader.py in ffmpeg_parse_infos(filename, print_infos, check_duration, fps_source)288 index = -1 if is_GIF else 0
--> 289 line = [l for l in lines if keyword in l][index]290 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:
OSError Traceback (most recent call last)<ipython-input-89-aa49daf0c5c8> in <module>39 # 第六步:加上音频40 if not os.path.exists(out_video_path):
---> 41 sound2video(org_video_path=human_video_path, new_video_path=img2video_path, out_video_path=out_video_path)42 else:43 print('最终视频已存在,请查看输出路径')
<ipython-input-87-7c9c64c5b2f0> in sound2video(org_video_path, new_video_path, out_video_path)14 15 # 2.读取新生成视频
---> 16 video_clip = VideoFileClip(new_video_path)17 18 # 3.合成音频与视频
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/moviepy/video/io/VideoFileClip.py in __init__(self, filename, has_mask, audio, audio_buffersize, target_resolution, resize_algorithm, audio_fps, audio_nbytes, verbose, fps_source)89 target_resolution=target_resolution,90 resize_algo=resize_algorithm,
---> 91 fps_source=fps_source)92 93 # Make some of the reader's attributes accessible from the clip
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/moviepy/video/io/ffmpeg_reader.py in __init__(self, filename, print_infos, bufsize, pix_fmt, check_duration, target_resolution, resize_algo, fps_source)31 self.proc = None32 infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
---> 33 fps_source)34 self.fps = infos['video_fps']35 self.size = infos['video_size']
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/moviepy/video/io/ffmpeg_reader.py in ffmpeg_parse_infos(filename, print_infos, check_duration, fps_source)293 raise IOError(("MoviePy error: failed to read the duration of file %s.\n"294 "Here are the file infos returned by ffmpeg:\n\n%s")%(
--> 295 filename, infos))296 297 # get the output line that speaks about video
OSError: MoviePy error: failed to read the duration of file ./c.mp4.
Here are the file infos returned by ffmpeg:ffmpeg version 4.1-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2018 the FFmpeg developersbuilt with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --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-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimglibavutil 56. 22.100 / 56. 22.100libavcodec 58. 35.100 / 58. 35.100libavformat 58. 20.100 / 58. 20.100libavdevice 58. 5.100 / 58. 5.100libavfilter 7. 40.101 / 7. 40.101libswscale 5. 3.100 / 5. 3.100libswresample 3. 3.100 / 3. 3.100libpostproc 55. 3.100 / 55. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5b29b80] moov atom not found
./c.mp4: Invalid data found when processing input
针对第二个问题,我尝试看合成之后的视频的持续时间
参考了这个帖子
https://blog.csdn.net/weixin_45475063/article/details/101440793
# 读入视频
cap = cv2.VideoCapture('./test-4.mp4')
#( 视频总帧数cap.get(7) / 帧速率cap.get(5) = 时间video_time )
video_time = float(cap.get(7) / cap.get(5))
print(cap.get(7) )
print(cap.get(5) )
print(video_time)
发现打印出来的视频总帧数,帧速率,时间全是0
并且通过这个方法,我发现第一个问题的错误所在了,那个视频读不出来帧速率,所以那个KeyError: 'video_fps’就是空的,所以报错了
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
