gpt4 book ai didi

python - TypeError : expected str, 字节或 os.PathLike 对象,不是 FilterableStream

转载 作者:行者123 更新时间:2023-12-04 23:18:40 27 4
gpt4 key购买 nike

我正在尝试使用 ffmpeg 将 mp4 视频转换为 jpeg 帧:

 from __future__ import unicode_literals
import argparse
import ffmpeg
import cv2
import numpy as np
import os
from glob import glob
#from __future__ import unicode_literals, print_function
import sys



def main():

try:
probe = ffmpeg.probe('./frames.mp4')
except ffmpeg.Error as e:
print(e.stderr, file=sys.stderr)
sys.exit(1)

video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
if video_stream is None:
print('No video stream found', file=sys.stderr)
sys.exit(1)

width = int(video_stream['width'])
height = int(video_stream['height'])
num_frames = int(video_stream['nb_frames'])
print('width: {}'.format(width))
print('height: {}'.format(height))
print('num_frames: {}'.format(num_frames))


inputt = ffmpeg.input('./frames.mp4')
(
ffmpeg
.input(inputt)
.filter('select', 'gte(n,{})'.format(num_frames))
.output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
.run()#capture_stdout=True)
)


if __name__ == '__main__':
main()
结果:
Traceback (most recent call last):
File "/Users/paula/Desktop/GameOn/video-segmentation-tests/video_to_image.py", line 51, in <module>
main()
File "/Users/paula/Desktop/video_to_image.py", line 42, in main
ffmpeg
File "/opt/anaconda3/lib/python3.9/site-packages/ffmpeg/_run.py", line 313, in run
process = run_async(
File "/opt/anaconda3/lib/python3.9/site-packages/ffmpeg/_run.py", line 284, in run_async
return subprocess.Popen(
File "/opt/anaconda3/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/opt/anaconda3/lib/python3.9/subprocess.py", line 1754, in _execute_child
self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not FilterableStream
我尝试更改路径,尝试设置 argparse 而不是直接设置路径,搜索类似问题......但没有任何效果。
我还在 ffmpeg 文档中进行了搜索。

最佳答案

尝试:

ffmpeg.input('./frames.mp4') \
.filter('select', 'gte(n,{})'.format(num_frames)) \
.output('pipe:', vframes=1, format='image2', vcodec='mjpeg') \
.run()#capture_stdout=True

关于python - TypeError : expected str, 字节或 os.PathLike 对象,不是 FilterableStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71472531/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com