I want to save video from camera to local disk. How may I do it (using some existing tool or C/C++ and SDK)? I use Buildroot Linux. Thanks!
BTW saving not video, but still images variant is also interesting.
I want to save video from camera to local disk. How may I do it (using some existing tool or C/C++ and SDK)? I use Buildroot Linux. Thanks!
BTW saving not video, but still images variant is also interesting.
很遗憾,如果您希望使用opencv-mobile进行视频保存,在milkv-duo版本的opencv-mobile中,videoIO中的视频写入模块已经不再支持。这一决定可能是基于视频编码对计算资源的高消耗所做出的。不过,您有两个替代方案:一是自行重新编译opencv,并在此过程中启用videoio模块的视频写入功能;二是将图像以序列格式保存,之后再将其上传到PC上使用FFMPEG进行视频编码。以下是一个使用图片序列保存并进行视频编码的例子:
English version (Polite and Formal):
Regrettably, if you wish to utilize opencv-mobile for video saving, the video writing functionality within the videoIO module has been deprecated in the milky-duo version of opencv-mobile. This decision may have been influenced by the significant computational resources required for video encoding. However, there are two alternatives you might consider: one option is to recompile opencv yourself, ensuring the video writing capabilities of the videoio module are enabled in the process; another is to save the images in a sequence format and then upload them to a PC for video encoding by using FFMPEG. Here is an example of saving images in sequence and encoding them into a video:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <unistd.h> // For sleep()
#include <string> // For std::string, std::to_string
int main()
{
cv::VideoCapture cap;
cap.set(cv::CAP_PROP_FRAME_WIDTH, 640);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 360);
cap.open(0);
if (!cap.isOpened()) {
fprintf(stderr, "Error: Couldn't open video capture device.\n");
return -1;
}
const int w = cap.get(cv::CAP_PROP_FRAME_WIDTH);
const int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
fprintf(stderr, "%d x %d\n", w, h);
cv::Mat frame;
int frameNumber = 0; // Counter for frame number
while (true)
{
cap >> frame; // Capture a frame from the video device
if (frame.empty()) break; // If no frame is captured, exit the loop
// Construct the filename for the frame, format: frame_<number>.jpg
std::string filename = "frame_" + std::to_string(frameNumber++) + ".jpg";
// Save the current frame to file
cv::imwrite(filename, frame);
// Break the loop if 'q' is pressed
if (cv::waitKey(1) == 'q') break;
}
cap.release(); // Release video device and resources
return 0;
}
exaples for ffmpeg:
ffmpeg -framerate 10 -i /path/to/your/images/img%03d.jpg -c:v libx264 -pix_fmt yuv420p slideshow.mp4
Hey everyone,
I’m using this code sample provided by @ericz, however the latency is way too high for my use case (avg 800ms per image). Is there a way to speed up the process?
Glad to see you could work with ffmpeg on this tiny board! Have you tried to capture video from duo’s camera using this framework? I’ve spent a lot of time to figure out how to do that, but to no avail.