opencv mp3 header missing - c++

Hi i'm new to the openCV library. Just really installed in today and i was trying to do some basic stuff like show a picture in a window and show a video in a window.
I got both of these to work but when i try and show the video it plays without sound and i get the following
[mp3 # 0x107808800] Header missing
in the console. How do i add the mp3 header so it plays with sound?
here is my code
int main(int argc, const char * argv[])
{
if (argc<2) {
printf("not enough arguments");
return -1;
}
//create a window
namedWindow(windowName,WINDOW_AUTOSIZE);
Mat frame;
//capture video from file
VideoCapture capture;
capture.open(argv[1]);
int run=1;
while (1) {
//make play and pause feature
if (run !=0) {
capture>>frame;
imshow(windowName, frame);
}
char c=waitKey(33);
if (c=='p') {
run=1;
}
if (c=='s') {
run=0;
}
if (c ==27 || c=='q') {
break;
}
}
return 0;
}

you can't .
audio gets discarded (that's the message you get), and there's no way to retrieve it again.

Related

OpenCV C++ RTSP Stream VideoCapture Error - "Operation now in progress"

I am attempting to write a short C++ script that can show me an RTSP stream from a camera on my local network. Currently my script is the following:
#include <iostream>
#include <opencv2/opencv.hpp>
int main()
{
std::string window_name = "RGB Camera";
setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp", 1);
const std::string rtsp_url = "rtsp://192.168.2.100:5010/video.sdp";
cv::VideoCapture cap; // Declare capture stream
cap.open(rtsp_url, cv::CAP_FFMPEG);
if (!cap.isOpened()) // Prompt an error message if no video stream is found
{
perror("Video Stream Error");
exit(EXIT_FAILURE);
}
cv::namedWindow(window_name, cv::WindowFlags::WINDOW_KEEPRATIO); // Declaring the video to show the video
cv::Mat frame; // Declaring a matrix to load the frames
while (1)
{
const bool read_success = cap.read(frame);
if (!read_success)
{
printf("End of stream\n.");
break;
}
cv::imshow(window_name, frame);
char c = (char)cv::waitKey(25); // 25 milliseconds per frame
if (c == 27) // If 'Esc' key is pressed, break the loop
{
printf("Esc key pressed, terminating loop...\n");
break;
}
}
cap.release(); // Release memory buffer
cv::destroyAllWindows(); // Close all windows
return 0;
}
However when running I am getting the following error message:
Video Stream Error: Operation now in progress
I am aware that my script is failing in the if (!cap.isOpened()) check, however I am able to open this stream in VLC and with ffplay with the rtsp url. I'm not sure why OpenCV is not working.
Also, when I remove cv::CAP_FFMPEG in the cap.open() function I get the error:
Video Stream Error: No such file or directory
Any suggestions would be greatly appreciated.

OpenCV VideoCapture works inconsistently

I have been trying to get my application using OpenCV to work for a while now and a longstanding error which I cannot seem to fix is this one:
PROBLEM:
OpenCV's VideoCapture is inconsistent in splitting video into frames for different file formats and codecs.
Specifics:
My errors are in one part of the application: splitting videos into frames. There are three current scenarios when I choose a valid directory for VideoCapture and open it. It either:
Opens and works perfectly.
Is able to open the VideoCapture (cap.isOpened() = true) but receives an empty frame or two during the frame split which causes app to throw error.
Does not open at all.
A given video will only do one of those three things. AVI File formats seem to have most of the errors, though.
Fixes tried:
Installing K-Lite Codec Pack Full
Putting OpenCV_FFMPEG.dll and OpenCV_FFMPEG_64.dll in project directory and in PATH
The only explanation I can think of is this is an error with the way I installed OpenCV and FFmpeg.
Any help would be greatly appreciated! Thanks.
By the way, I am running Qt 5.8.0 and OpenCV 3.2.0 and this is my FrameSplit code.
vector<int> mainFrame::frameSplit(string filename, string location)
{
//Extract + Save Frames
string vidDir = filename;
string locationDir = location + "/frames/";
VideoCapture cap(vidDir);
if (!cap.isOpened())
{
qDebug() << "OO";
return {};
}
else
{
Mat firstFrame;
Mat nextFrame;
Mat frame;
int count = 1;
QProgressDialog progress("Extracting files...", "Abort", 0, cap.get(CV_CAP_PROP_FRAME_COUNT));
progress.setWindowModality(Qt::WindowModal);
progress.setAttribute(Qt::WA_DeleteOnClose, true);
progress.setFixedSize(500, 100);
progress.show();
vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(100);
qDebug() << cap.get(CV_CAP_PROP_FRAME_COUNT);
bool failure = false;
for (count = 1; count < cap.get(CV_CAP_PROP_FRAME_COUNT); count++)
{
cap >> frame;
if(frame.empty()) {
QMessageBox messageBox;
messageBox.critical(this, "Error", "There was an error in analyzing the video. Please try and install the appropriate codecs and try again.");
messageBox.setFixedSize(600,400);
vector<int> empty;
return empty;
}
string filePath = locationDir + to_string(count) + ".jpg";
imwrite(filePath,frame,compression_params);
progress.setValue(count);
}
progress.setValue(count);
progress.close();
vector<int> props;
props.push_back(cap.get(CV_CAP_PROP_FRAME_COUNT));
props.push_back(round(cap.get(CV_CAP_PROP_FPS)));
props.push_back(cap.get(CV_CAP_PROP_FRAME_WIDTH));
props.push_back(cap.get(CV_CAP_PROP_FRAME_HEIGHT));
qDebug() << props[0];
return props;
}
}

A bug in CV::VideoCapture::open()?

I am using CV::VideoCapture to capture frames from an IP camera. It works most of time, however, sometimes it reports the error:
[mjpeg # 0x233aea0] overread 8
And when this error occurred, my program just stuck there. This might explain why. But how can I solve it in C++ code? Can OpenCV handle this error without terminate the program?
p.s. I found that if I didn't call CV::VideoCapture::read() immediately, but wait for a while, like 60 seconds, after CV::VideoCapture::open(), this error occurred everytime! Is it a bug of OpenCV?
#include <unistd.h>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main(int argc, char* argv[]) {
// argv[1] is a valid url, like "http://xxxx/mjpg/video.mjpg"
cv::VideoCapture cap(argv[1]);
if (!cap.isOpened()) {
std::cout << "Cannot Open Camera!" << std::endl;
return -1;
}
// The error occures if I pause for a while.
// But it is okay when I capture frames from video files intead of IP camera.
sleep(60);
while (static_cast<char>(cv::waitKey(1)) != 'q') {
cv::Mat frame;
cap >> frame;
if (frame.empty()) break;
cv::imshow("frame", frame);
}
}
I can't explain why but using the address http://xxxx/axis-cgi/mjpg/video.cgi instead of http://xxxx/mjpg/video.mjpg solved it! Can anyone provide some nice explanation here, or some links? Thanks!

Video Capture : Frame always empty - opencv

I am working with openCV Version 2.4.9, and on Mac OSX.
I have written this code for loading and displaying a video on my desktop. But it never seems to work. I always get the output as "frame empty". Thus it does not complain about reading the video using VideoCapture.It is NOT able to capture any frames, and thus 'frame' is always EMPTY. Any idea what the problem might be?
Note: I have tried both ways to capture a frame - commented as try 1 and try2.
int main(int argc, const char * argv[])
{
Mat frame;
VideoCapture capture_ir("/Users/shreyatandon/Desktop/resize_ir.avi");
if ( !capture_ir.isOpened() ) // if not success, exit program
{
cout << "Cannot open the video file" << endl;
return -1;
}
for (;;){
// capture_ir.read(frame); //try1
capture_ir>>frame; //try2
if(frame.empty()){
std::cerr<<"frame is empty"<<std::endl;
break;
}
imshow("", frame);
waitKey(10);
break;
}
return 0;
}
Just made it work.
Mat current_frame;
VideoCapture video("video.avi");
while(true)
{
video.read(current_frame);
imshow("Image",current_frame);
}
If you keep having problems using avi format have a look at your links to the ffmpeg libraries and it dependencies. I tried to install it from scratch using homebrew and it is working without problems. Cheers

doesn't save any image.. when saving frames of a video [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Cant save image using OpenCV
I have tried following code,please see this and tell me what did i wrong.but there is not compile error.after i run the program it doesn't save any image.
#include"stdafx.h"
#include<cv.h>
#include<highgui.h>
#include<cxcore.h>
int main(int argc, char* argv[]) {
int c=1;
IplImage* img=0;
char buffer[1000];
CvCapture* cv_cap=cvCaptureFromCAM(-1);
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);
while(1) {
img=cvQueryFrame(cv_cap);
cvShowImage("Video",img);
sprintf(buffer,"D:/image%u.jpg",c);
cvSaveImage(buffer,img);
c++;
if (cvWaitKey(100)== 27) break;
}
cvDestroyWindow("Video");
return 0;
}
can you tell me how to save a image .above program doesn't save any images.please give me your suggestions.thank you.
IplImage *destination = cvCreateImage(cvSize( img->width, img->height ), IPL_DEPTH_8U,1);
cvCvtColor( img, destination, CV_RGB2GRAY );
cvSaveImage( "C:/Users/SP/Desktop/sample.jpg", destination );
It converts to grey image; use it as desired.
Hope this works.
Probably a permissions problem, only admin can write to the top level folder
Try making a sub-directory and writing to eg sprintf(buffer,"D:/data/image%u.jpg",c);
I'll say this for the 100th time in these OpenCV posts: code safely by checking the return of the calls. cvSaveImage() returns 0 when it fails to save the image:
if (!(cvSaveImage(buffer,img))
{
std::cout << "!!! Failed to save image" << std::endl;
}
If you see the error message being displayed, you should check if the destination directory exists and if your user has the authorization to create files inside it.