import os
import subprocess
class FFMPEGFrames:
def __init__(self, output):
self.output = output
def extract_frames(self, input, fps):
output = input.split('/')[-1].split('.')[0]
if not os.path.exists(self.output + output):
os.makedirs(self.output + output)
query = "ffmpeg -y -hwaccel cuvid -c:v h264_cuvid -resize 1024x70 -i " + input + " -vf scale_npp=format=yuv420p,hwdownload,format=yuv420p -vf fps=" + str(fps) + " -pix_fmt yuvj420p -color_range 2 -vframes 1 -y " + self.output + output + "/output%06d.jpg"
response = subprocess.Popen(query, shell=True, stdout=subprocess.PIPE).stdout.read()
s = str(response).encode('utf-8')
我收到了这个错误:
Impossible to convert between the formats supported by the filter 'Parsed_fps_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
Conversion failed!
最佳答案
您可能错过了一条错误消息:
Only '-vf fps' read, ignoring remaining -vf options: Use ',' to separate filters
结合你的
-vf
合而为一。另外,考虑替换-pix_fmt yuvj420p
使用格式过滤器,因此所有过滤都可以在一个过滤器图中,您可以准确选择过滤器图中出现的位置。
关于ffmpeg - 使用FFMPEG gpu python从视频中读取帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59307933/