- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
试图解决 http://wiki.bitplan.com/index.php/OpenCV#OpenCV_VideoWriter 上的问题我找到了以下相关链接:
然后想出了 the code below尝试扩展名和 FOURCC 代码的组合。
环境是使用 Java 8 和 Macports 2.6.2 的 Mac Os 10.13.6。使用 OpenCV 3.4.8我还在 Ubuntu 18.04 LTS 上使用 OpenJDK 1.8.0_232 和 libopencv_java343.so 进行了测试
消息和文件显示我尝试的 21 种组合均无效。
视频录制工作可能出现的问题和解决方案是什么?
生成的消息是:
recording: 640x480 mov video with MJPG
OpenCV: FFMPEG: tag 0x47504a4d/'MJPG' is not supported with codec id 7 and format 'mov / QuickTime / MOV'
OpenCV: FFMPEG: fallback to use tag 0x6765706a/'jpeg'
recording: 640x480 mov video with X264
OpenCV: FFMPEG: tag 0x34363258/'X264' is not supported with codec id 27 and format 'mov / QuickTime / MOV'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
recording: 640x480 mov video with H264
OpenCV: FFMPEG: tag 0x34363248/'H264' is not supported with codec id 27 and format 'mov / QuickTime / MOV'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
recording: 640x480 mov video with MP4V
OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'mov / QuickTime / MOV'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'
recording: 640x480 mov video with AVC1
OpenCV: FFMPEG: tag 0x31435641/'AVC1' is not supported with codec id 27 and format 'mov / QuickTime / MOV'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
recording: 640x480 mov video with FMP4
OpenCV: FFMPEG: tag 0x34504d46/'FMP4' is not supported with codec id 12 and format 'mov / QuickTime / MOV'
OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'
recording: 640x480 mov video with JPEG
OpenCV: FFMPEG: tag 0x4745504a/'JPEG' is not supported with codec id 7 and format 'mov / QuickTime / MOV'
OpenCV: FFMPEG: fallback to use tag 0x6765706a/'jpeg'
recording: 640x480 avi video with MJPG
recording: 640x480 avi video with X264
recording: 640x480 avi video with H264
recording: 640x480 avi video with MP4V
OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'avi / AVI (Audio Video Interleaved)'
OpenCV: FFMPEG: fallback to use tag 0x34504d46/'FMP4'
recording: 640x480 avi video with AVC1
OpenCV: FFMPEG: tag 0x31435641/'AVC1' is not supported with codec id 27 and format 'avi / AVI (Audio Video Interleaved)'
OpenCV: FFMPEG: fallback to use tag 0x34363248/'H264'
recording: 640x480 avi video with FMP4
recording: 640x480 avi video with JPEG
OpenCV: FFMPEG: tag 0x4745504a/'JPEG' is not supported with codec id 7 and format 'avi / AVI (Audio Video Interleaved)'
OpenCV: FFMPEG: fallback to use tag 0x47504a4d/'MJPG'
recording: 640x480 mpg video with MJPG
OpenCV: FFMPEG: tag 0x47504a4d/'MJPG' is not supported with codec id 7 and format 'mpeg / MPEG-1 Systems / MPEG program stream'
recording: 640x480 mpg video with X264
OpenCV: FFMPEG: tag 0x34363258/'X264' is not supported with codec id 27 and format 'mpeg / MPEG-1 Systems / MPEG program stream'
recording: 640x480 mpg video with H264
OpenCV: FFMPEG: tag 0x34363248/'H264' is not supported with codec id 27 and format 'mpeg / MPEG-1 Systems / MPEG program stream'
recording: 640x480 mpg video with MP4V
OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'mpeg / MPEG-1 Systems / MPEG program stream'
recording: 640x480 mpg video with AVC1
OpenCV: FFMPEG: tag 0x31435641/'AVC1' is not supported with codec id 27 and format 'mpeg / MPEG-1 Systems / MPEG program stream'
recording: 640x480 mpg video with FMP4
OpenCV: FFMPEG: tag 0x34504d46/'FMP4' is not supported with codec id 12 and format 'mpeg / MPEG-1 Systems / MPEG program stream'
recording: 640x480 mpg video with JPEG
OpenCV: FFMPEG: tag 0x4745504a/'JPEG' is not supported with codec id 7 and format 'mpeg / MPEG-1 Systems / MPEG program stream'
生成的文件是:
-rw-r--r-- 1 wf 5686 9. Jan 10:19 test_AVC1_2020-01-09101907.avi
-rw-r--r-- 1 wf 185 9. Jan 10:19 test_AVC1_2020-01-09101907.mov
-rw-r--r-- 1 wf 0 9. Jan 10:19 test_AVC1_2020-01-09101907.mpg
-rw-r--r-- 1 wf 5686 9. Jan 10:19 test_FMP4_2020-01-09101907.avi
-rw-r--r-- 1 wf 185 9. Jan 10:19 test_FMP4_2020-01-09101907.mov
-rw-r--r-- 1 wf 0 9. Jan 10:19 test_FMP4_2020-01-09101907.mpg
-rw-r--r-- 1 wf 5686 9. Jan 10:19 test_H264_2020-01-09101907.avi
-rw-r--r-- 1 wf 185 9. Jan 10:19 test_H264_2020-01-09101907.mov
-rw-r--r-- 1 wf 0 9. Jan 10:19 test_H264_2020-01-09101907.mpg
-rw-r--r-- 1 wf 5686 9. Jan 10:19 test_JPEG_2020-01-09101907.avi
-rw-r--r-- 1 wf 185 9. Jan 10:19 test_JPEG_2020-01-09101907.mov
-rw-r--r-- 1 wf 0 9. Jan 10:19 test_JPEG_2020-01-09101907.mpg
-rw-r--r-- 1 wf 5686 9. Jan 10:19 test_MJPG_2020-01-09101907.avi
-rw-r--r-- 1 wf 185 9. Jan 10:19 test_MJPG_2020-01-09101907.mov
-rw-r--r-- 1 wf 0 9. Jan 10:19 test_MJPG_2020-01-09101907.mpg
-rw-r--r-- 1 wf 5686 9. Jan 10:19 test_MP4V_2020-01-09101907.avi
-rw-r--r-- 1 wf 185 9. Jan 10:19 test_MP4V_2020-01-09101907.mov
-rw-r--r-- 1 wf 0 9. Jan 10:19 test_MP4V_2020-01-09101907.mpg
-rw-r--r-- 1 wf 5686 9. Jan 10:19 test_X264_2020-01-09101907.avi
-rw-r--r-- 1 wf 185 9. Jan 10:19 test_X264_2020-01-09101907.mov
-rw-r--r-- 1 wf 0 9. Jan 10:19 test_X264_2020-01-09101907.mpg
Junit 测试用例
package nl.vaneijndhoven.dukes.imageview;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import com.bitplan.opencv.NativeLibrary;
import nl.vaneijndhoven.opencv.video.ImageUtils;
/**
* test the video recording functionality
*
* @author wf
*
*/
public class TestVideoRecorder {
@BeforeClass
public static void setup() throws Exception {
NativeLibrary.load();
}
@Test
public void testVideoRecorder() {
byte[] testImage = DebugImageServer.testImage();
Mat testMat = ImageUtils.imageBytes2Mat(testImage);
boolean isColor = true;
for (String ext : VideoRecorder.exts) {
for (String FOURCC : VideoRecorder.FOURCCs) {
Size frameSize = new Size(testMat.width(), testMat.height());
VideoRecorder recorder = new VideoRecorder("test", isColor);
recorder.ext=ext;
recorder.FOURCC=FOURCC;
String msg = String.format("recording: %dx%d %s video with %s",
testMat.width(), testMat.height(), ext, FOURCC);
System.out.println(msg);
recorder.start(25.0, frameSize);
for (int i = 1; i <= 50; i++) {
recorder.recordMat(testMat);
}
recorder.stop();
File videoFile = new File(recorder.path);
assertTrue(videoFile.exists());
}
}
}
}
录像机
package nl.vaneijndhoven.dukes.imageview;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.videoio.VideoWriter;
/**
* record videos
* @author wf
*
*/
public class VideoRecorder {
public static transient final String DATE_FORMAT="yyyy-MM-ddHHmmss";
public static transient final DateFormat dateFormat=new SimpleDateFormat(DATE_FORMAT);
String name;
private VideoWriter save;
private Size frameSize;
private double fps;
String path;
boolean started;
boolean isColor;
public static String exts[]= {"mov","avi","mpg"};
String ext="mov";
public static String FOURCCs[]= { "MJPG", "X264", "H264", "MP4V", "AVC1", "FMP4", "JPEG"};
String FOURCC="mp4v";
/**
* construct me
* @param name - the name of the video - a timestamp will be added
* @param isColor - true if the video is a color video
*/
public VideoRecorder(String name, boolean isColor) {
this.name=name;
this.isColor=isColor;
started=false;
}
// https://stackoverflow.com/questions/53158765/record-and-save-video-stream-use-opencv-in-java
public void start(double fps, Size frameSize) {
this.fps=fps;
this.frameSize=frameSize;
int fourcc = VideoWriter.fourcc(FOURCC.charAt(0), FOURCC.charAt(1), FOURCC.charAt(2), FOURCC.charAt(3));
Date now = new Date();
String timestamp=dateFormat.format(now);
path=String.format("/tmp/%s_%s_%s.%s", name,FOURCC,timestamp,ext);
save = new VideoWriter(path,fourcc, this.fps, this.frameSize, isColor);
started=true;
}
/**
* stop the recording
*/
public void stop() {
save.release();
started=false;
}
/**
* record a single frame
* @param mat - open cv frame to be recorded
*/
public void recordMat(Mat mat) {
save.write(mat);
}
}
最佳答案
问题在于测试图像是具有 4 个 channel 的 PNG 图像。
following changes修复了这种情况:
确保我们使用 jpg:
DebugImageServer.ext=".jpg";
显示使用的 channel 数:
String msg = String.format("recording: %dx%d %d channel %s video with %s",
testMat.width(), testMat.height(),testMat.channels(), ext, FOURCC);
System.out.println(msg);
现在有很多组合可以工作:
-rw-r--r-- 1 wf 81845 9. Jan 11:05 test_avc1_2020-01-09110505.mov
-rw-r--r-- 1 wf 87402 9. Jan 11:05 test_avc1_2020-01-09110506.avi
-rw-r--r-- 1 wf 81920 9. Jan 11:05 test_avc1_2020-01-09110507.mpg
-rw-r--r-- 1 wf 389053 9. Jan 11:05 test_fmp4_2020-01-09110505.mov
-rw-r--r-- 1 wf 395162 9. Jan 11:05 test_fmp4_2020-01-09110506.avi
-rw-r--r-- 1 wf 391168 9. Jan 11:05 test_fmp4_2020-01-09110507.mpg
-rw-r--r-- 1 wf 81845 9. Jan 11:05 test_h264_2020-01-09110506.mov
-rw-r--r-- 1 wf 87402 9. Jan 11:05 test_h264_2020-01-09110507.avi
-rw-r--r-- 1 wf 81920 9. Jan 11:05 test_h264_2020-01-09110508.mpg
-rw-r--r-- 1 wf 3618564 9. Jan 11:05 test_jpeg_2020-01-09110506.mov
-rw-r--r-- 1 wf 3624510 9. Jan 11:05 test_jpeg_2020-01-09110507.avi
-rw-r--r-- 1 wf 3631104 9. Jan 11:05 test_jpeg_2020-01-09110508.mpg
-rw-r--r-- 1 wf 3618564 9. Jan 11:05 test_mjpg_2020-01-09110506.mov
-rw-r--r-- 1 wf 3624510 9. Jan 11:05 test_mjpg_2020-01-09110507.avi
-rw-r--r-- 1 wf 3631104 9. Jan 11:05 test_mjpg_2020-01-09110508.mpg
-rw-r--r-- 1 wf 389053 9. Jan 11:05 test_mp4v_2020-01-09110506.mov
-rw-r--r-- 1 wf 395162 9. Jan 11:05 test_mp4v_2020-01-09110507.avi
-rw-r--r-- 1 wf 391168 9. Jan 11:05 test_mp4v_2020-01-09110508.mpg
-rw-r--r-- 1 wf 81845 9. Jan 11:05 test_x264_2020-01-09110506.mov
-rw-r--r-- 1 wf 87402 9. Jan 11:05 test_x264_2020-01-09110507.avi
-rw-r--r-- 1 wf 81920 9. Jan 11:05 test_x264_2020-01-09110508.mpg
-rw-r--r-- 1 wf 389053 9. Jan 11:05 test_xvid_2020-01-09110506.mov
-rw-r--r-- 1 wf 395162 9. Jan 11:05 test_xvid_2020-01-09110507.avi
-rw-r--r-- 1 wf 391168 9. Jan 11:05 test_xvid_2020-01-09110508.mpg
关于java - OpenCV VideoWriter for Java 在 MacOS 上无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59660923/
第一次保存视频后,应用程序需要添加更多的帧。但是,如果视频文件存在,VideoWriter 对象将覆盖现有视频。我使用下面的代码编写视频(它是一个函数调用): videoWriter = Video
当我尝试使用 VideoWriter 编写帧时,它不起作用。我已经尝试了很多 FOURCC 代码,例如 defaul、h264、mjpg、divx、xvid 等。是的,我已经安装了具有所有必要配置的
这是我保存 web_cam 流的代码。它正在工作,但输出视频文件的问题。 import numpy as np import cv2 cap = cv2.VideoCapture(0) # Defin
我正在尝试使用如下所示的 Python 脚本从我的网络摄像头流式传输和保存视频,但出于某种原因,“myvideo.mp4”文件非常小,无法使用 QuickTime(或其他播放器)打开 -它似乎是空的。
我正在尝试测量输入视频文件中的某些事件:“test.mp4”。这是通过分几个步骤处理视频来完成的,其中每个步骤对视频数据执行一些操作并将中间结果写入新的视频文件。 输入视频的fps为:29.42346
我正在使用OpenCV 2.4.9和Visual C++2017。我正在编写视频,出于测试目的,尝试在完整的磁盘上编写框架。 我做了 try { video_writer << frame;
我正在构建一个脚本,以通过CSV文件将边框叠加到我的视频上。每个框架都有n个边界框,因此我只是遍历每个框架中的边界框并在该框架上绘制cv2.rectangle。结果,对于所有框架,我都会多次写入一个框
import numpy import cv2 import random image=cv2.imread(r"C:\Users\Sriram\Desktop/img.png") print(ima
我正在尝试使用 opencv videowriter api 从视频卡设备流式传输连续图像,下面是执行该操作的 opencv 代码片段,我的问题是我正在获取帧但没有在/var/中生成任何 index.
问题:我在正确渲染/播放由OpenCV的视频编写器创建的视频时遇到问题。 详细信息:Python不会吐出任何错误,而是可以成功播放/创建视频。当我尝试使用VLC播放视频时,似乎VLC尝试播放空视频(时
我是新手,开始在 ubuntu 10.4 上使用 OpenCV。我正在尝试从相机捕获视频并将该视频写入 avi 文件,代码如下: #include "opencv2/opencv.hpp" #incl
我要从视频采集卡中捕捉帧。这些帧被处理并写入硬盘。整个设置处于多线程环境中,因此抓取器将图像写入队列,在另一个线程中处理图像,另一个线程写入硬盘。如果图像符合处理器的定义,则图像将写入硬盘。如果连续
我正在尝试将网络摄像头的记录写入文件。为此,我使用以下代码。我一直得到 2 的退出代码。有人可以帮我找出问题所在吗?我以前使用过类似的函数调用,将一个视频文件的帧写入一个新文件,并且有效。无法理解这种
我是一名数学本科生,几乎没有编程经验。不过,我对计算机视觉很感兴趣。试图遵循 Learning OpenCV 这本书,但它有点过时了。如何将生成的视频文件保存在我的 linux 主目录中?例如“/ho
我正在研究视频的深度学习算法。给定一个视频片段,我想将我的结果保存在另一个视频中。为此,我在 Windows 上使用 OpenCV 和 Python。OpenCV 对我的视频预处理工作正常,可以训练我
以下代码无法打开 VideoWriter 对象: #include #include #include #include using namespace cv; using namespace
我正在编写一个程序来读取多个网络摄像头,将图片拼接在一起并将它们保存到视频文件中。 我应该使用线程来捕获图像并将生成的大图像写入文件吗? 如果是,我应该使用 c+11 还是 boost? 您是否有一些
我正在尝试从两张图片创建 1fps webm,代码: // path to output string outputVideoPath = "/home/gio/Desktop/gif
我对 OpenCV VideoWriter 有疑问。 目前我有 2 个项目:一个在 C# 中,一个在 C++ 中。 C# 项目会读取*.bmp 文件,创建位图列表,然后在C++ 项目中调用writeV
使用 OpenCV 2.4.8(预构建的二进制文件)运行 Windows 7、x64。 尝试以下基本代码: VideoWriter wrt; wrt.open("video.mp4", -1, 29
我是一名优秀的程序员,十分优秀!