我试图运行位于HERE的存储库。基本上,只是针对SimpleVideoSummarizer.cc使用 OpenCV 进行一些基本视频处理的目标。我使用的是 Ubuntu 14.04。以下是保存部分的代码:
void SimpleVideoSummarizer::playAndSaveSummaryVideo(char* videoFileSave) {
cv::VideoCapture capture(videoFile);
cv::Mat frame;
capture.set(CV_CAP_PROP_POS_FRAMES, 0);
cv::VideoWriter videoWriter;
if (videoFileSave != "") {
videoWriter = cv::VideoWriter(videoFileSave, CV_FOURCC('M', 'J', 'P', 'G'), static_cast<int>(capture.get(CV_CAP_PROP_FPS)), cv::Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT)));
}
for (std::set<int>::iterator it = summarySet.begin(); it != summarySet.end(); it++) {
capture.set(CV_CAP_PROP_POS_FRAMES, segmentStartTimes[*it] * frameRate);
for (int i = segmentStartTimes[*it]; i < segmentStartTimes[*it + 1]; i++) {
for (int j = 0; j < frameRate; j++) {
capture >> frame;
cv::putText(frame, "Time: " + …Run Code Online (Sandbox Code Playgroud) 我必须使用包含在各个目录中的大量 jpeg 图像创建低分辨率 AVI 视频。我有将近一百个目录,每个目录可能包含数千个图像。
为了自动化这个过程,我使用 OpenCV 编写了一个 python 脚本来创建一个视频对象,从给定目录加载每个图像,并将每个图像写入该目录的特定视频文件。所有这些都很好用。我的问题是如何控制视频对象的压缩质量。
VideoWriter 模块接受 5 个参数。第二个参数“fourcc”设置压缩代码。
cv2.VideoWriter.open(文件名,fourcc,fps,frameSize[,isColor])
我们可以使用“四字符代码”(即fourcc)在cv2.VideoWriter 中指定压缩代码。
Fourcc = cv2.cv.CV_FOURCC('M','S','V','C') #Microspoft Video 1
这种方法有效,只是视频对象的压缩质量始终设置为最大值。
如果我们让fourcc = -1,则会打开一个Windows 视频压缩对话框,允许用户选择视频压缩并在0 到100 之间设置压缩质量(或时间质量比)。
每个视频必须是 AVI,并且必须满足特定的文件大小要求。如果使用最大压缩质量,则视频文件太大。然而,要求用户为每个视频选择视频压缩和压缩质量会破坏脚本的自动化。
那么,如何在不使用 Windows 视频压缩对话框的情况下指定视频对象的压缩质量?
我的整个代码发布在下面
import cv2, os
Workspace = "J:\jpg to AVI test"
year = "2014"
file_extension = "avi"
Image_file_dir = Workspace + "\\12 - ECD-BONNETT CREEK Y INT (" + year + ")"
print Image_file_dir
Image_file_list = os.listdir(Image_file_dir)
print "Image_file_list: " + str(Image_file_list)
img_cnt = 0
for …Run Code Online (Sandbox Code Playgroud) 我在Mac上使用OpenCV和ffmpeg来编写视频.我已经能够使用编解码器/ fourcc代码FMP4成功编写.avi文件.不过,我想写.mp4文件.当我尝试使用fourcc FMP4编写.mp4文件时,我收到此错误:
[mp4 @ 0x100b4ec00] Tag FMP4/0x34504d46 incompatible with output codec id '13' ( [0][0][0])
Run Code Online (Sandbox Code Playgroud)
当我使用AVC1时,我收到以下错误:
[libx264 @ 0x104003000] broken ffmpeg default settings detected
[libx264 @ 0x104003000] use an encoding preset (e.g. -vpre medium)
[libx264 @ 0x104003000] preset usage: -vpre <speed> -vpre <profile>
[libx264 @ 0x104003000] speed presets are listed in x264 --help
[libx264 @ 0x104003000] profile is optional; x264 defaults to high
Could not open codec 'libx264': Unspecified error
Run Code Online (Sandbox Code Playgroud)
有没有人知道正确的编解码器与OpenCV和ffmpeg一起使用来写入Mac上的MP4容器?
如果AVC1是正确的编解码器,我该如何正确安装ffmpeg + OpenCV?我做到了
brew install gpac
brew install …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用opencv创建一个电影,我需要输出文件是H264格式.
我在opencv中使用了以下fourcc,但是我收到的错误是没有安装合适的编解码器.
fourcc=CV_FOURCC('H','2','6','4') ;
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序时,我收到以下错误消息:
Could not find encoder for codec id 28: Encoder not found
Run Code Online (Sandbox Code Playgroud)
我需要什么才能在OpenCV中使用此编解码器?
我正在尝试使用opencv编写视频.对我来说这很重要 - 因此它必须是一个无损编解码器.我在Ubuntu 12.04上使用OpenCV 2.4.1
以前,我使用的是fourcc代码0.这给了我想要的确切结果,并且我能够完美地恢复图像.
我不确定发生了什么,但截至最近的更新(2012年7月20日左右),出现了问题,我无法再使用这个4cc代码编写文件了.我真的不记得它是什么,但它可能来自更新,从我的软件中心删除一些软件,以及我在一般清洁期间做的一些其他事情......
当我使用mediainfo(http://www.fourcc.org/identifier/)检查旧文件时,我看到以下结果:
Complete name : oldsample.avi
Format : AVI
Format/Info : Audio Video Interleave
Format profile : OpenDML
File size : 1.07 GiB
Duration : 41s 467ms
Overall bit rate : 221 Mbps
Writing application : Lavf53.5.0
Video
ID : 0
Format : RGB
Codec ID : 0x00000000
Codec ID/Info : Basic Windows bitmap format. 1, 4 and 8 bpp versions are palettised. 16, 24 and 32bpp contain raw RGB samples
Duration : 41s …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 opencv 重新调整视频大小,然后将其保存回我的系统。代码有效并且不会给出任何错误,但输出视频文件已损坏。我使用的 fourcc 是 mp4v,与 .mp4 配合良好,但输出视频仍然损坏。需要帮忙。
import numpy as np
import cv2
import sys
import re
vid=""
if len(sys.argv)==3:
vid=sys.argv[1]
compress=int(sys.argv[2])
else:
print("File not mentioned or compression not given")
exit()
if re.search('.mp4',vid):
print("Loading")
else:
exit()
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
def rescale_frame(frame, percent=75):
width = int(frame.shape[1] * percent/ 100)
height = int(frame.shape[0] * percent/ 100)
dim = (width, height)
return cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
FPS= 15.0
FrameSize=(frame.shape[1], frame.shape[0])
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('Video_output.mp4', fourcc, FPS, …Run Code Online (Sandbox Code Playgroud) 我想在C++中设置一个FourCC值,即无符号4字节整数.
我想明显的方法是#define,例如
#define FOURCC(a,b,c,d) ( (uint32) (((d)<<24) | ((c)<<16) | ((b)<<8) | (a)) )
Run Code Online (Sandbox Code Playgroud)
然后:
uint32 id( FOURCC('b','l','a','h') );
Run Code Online (Sandbox Code Playgroud)
你能想到的最优雅的方式是什么?
我最近开始使用opencv-python进行编程,但是当我尝试使用cv2编写视频时遇到了麻烦。脚本的输出为空。这是我的代码:
import cv2
import numpy as np
import matplotlib.pyplot as plt
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'h263')
out = cv2.VideoWriter('cv2_camera_output.mp4',fourcc, 20.0, (800,600))
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame', frame)
cv2.imshow('gray', gray)
out.write(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
我猜想这个问题与fourcc编解码器有关。所以我用谷歌搜索是否有适用于mac的fourCC编解码器(我正在使用OS X 10.12.3(Sierra)),但所有建议均不适用于我的计算机,因此问题甚至可能不在fourCC编解码器中。这些是我访问过的链接:
OpenCV文档(我没有遵循这个文档,只是为了确保它也没有用)
有人知道真正的问题吗?任何帮助都会很棒
fourcc = cv2.VideoWriter_fourcc('X','2','6','4')
AttributeError: 'module' object has no attribute 'VideoWriter_fourcc'
Run Code Online (Sandbox Code Playgroud)
我在使用fourcc时遇到此错误.任何帮助,将不胜感激.