我正在尝试将图像转换为视频。 我成功地将图像转换为avi视频,但是我尝试在mp4中进行转换,但出现此错误:
[libx264 @ 0x15e2140] broken ffmpeg default settings detected
[libx264 @ 0x15e2140] use an encoding preset (e.g. -vpre medium)
[libx264 @ 0x15e2140] preset usage: -vpre <speed> -vpre <profile>
[libx264 @ 0x15e2140] speed presets are listed in x264 --help
[libx264 @ 0x15e2140] profile is optional; x264 defaults to high
Could not open codec 'libx264': Unspecified error
我的mp4代码(输入错误):
# -*- coding: utf-8 -*-
import os
import cv2
import numpy as np
print(cv2.__version__)
FILENAME = "test.jpg"
if FILENAME.endswith('.mp4'):
print('.mp4')
elif FILENAME.endswith('.jpg'):
print('.jpg')
if not os.path.exists(FILENAME):
print('File not found')
img = cv2.imread(FILENAME, cv2.IMREAD_COLOR)
height, width, layers = img.shape
fourcc = cv2.cv.CV_FOURCC(*'X264')
video = cv2.VideoWriter('video.mp4', fourcc, 1, (width, height))
video.write(img)
#cv2.imshow('image', img)
#cv2.waitKey(0)
cv2.destroyAllWindows()
video.release()
我的avi代码(哪个工作):
# -*- coding: utf-8 -*-
import os
import cv2
import numpy as np
print(cv2.__version__)
FILENAME = "test.jpg"
if FILENAME.endswith('.mp4'):
print('.mp4')
elif FILENAME.endswith('.jpg'):
print('.jpg')
if not os.path.exists(FILENAME):
print('File not found')
img = cv2.imread(FILENAME, cv2.IMREAD_COLOR)
height, width, layers = img.shape
fourcc = cv2.cv.CV_FOURCC(*'XVID')
video = cv2.VideoWriter('video.avi', fourcc, 1, (width, height))
video.write(img)
#cv2.imshow('image', img)
#cv2.waitKey(0)
cv2.destroyAllWindows()
video.release()
我尝试用H264替换X264,但出现相同的错误。我搜索了一些答案,然后尝试将其代码改编为我的代码,什么也没有做,因此我返回了正在使用的avi代码。
我尝试安装此软件: $ sudo apt-get install ffmpeg x264 libx264-dev
不起作用。我尝试将H264替换为0X00000021,也无法正常工作。
感谢您的回答