USB camera encoded data stream









up vote
2
down vote

favorite












Currently, I am working on a streaming project. I need to grab frames from USB camera and send them over TCP.



To open USB camera video stream I'm using cv::VideoCapture. This allows me to read already decoded frames. According to this question I understood that there is no way to get encoded frame data using cv::VideoCapture and I need to encode each frame again and send it whatever I need using cv::imencode. The problem is that I can encode frames to some specific format listed here, and, in case, I use either .jpg or .png the file size still quite big and on receiving side frame rate very poor.



My question is: Is there any way to get mjpeg or h264 encoded data directly
or maybe you can suggest a better way to encode frames.



OpenCV 3.4.3, camera RICOH THETA V, language C++.



My code:



void Streamer::start()

cv::Mat img;
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));

if (!cap.isOpened())
throw std::invalid_argument("No device found.");

std::vector<int> format_params;
format_params.push_back(CV_LOAD_IMAGE_COLOR);
format_params.push_back(CV_IMWRITE_PNG_STRATEGY);

for (;;)

cap.read(img);
cv::imencode(".png", img, buffer_, format_params);

std::string strbuf(buffer_.begin(), buffer_.end());
server_->sendString(socket, strbuf);


cap.release();










share|improve this question



















  • 1




    I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
    – api55
    Nov 7 at 8:48










  • @api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
    – Yevhenii Veretennikov
    Nov 9 at 6:41














up vote
2
down vote

favorite












Currently, I am working on a streaming project. I need to grab frames from USB camera and send them over TCP.



To open USB camera video stream I'm using cv::VideoCapture. This allows me to read already decoded frames. According to this question I understood that there is no way to get encoded frame data using cv::VideoCapture and I need to encode each frame again and send it whatever I need using cv::imencode. The problem is that I can encode frames to some specific format listed here, and, in case, I use either .jpg or .png the file size still quite big and on receiving side frame rate very poor.



My question is: Is there any way to get mjpeg or h264 encoded data directly
or maybe you can suggest a better way to encode frames.



OpenCV 3.4.3, camera RICOH THETA V, language C++.



My code:



void Streamer::start()

cv::Mat img;
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));

if (!cap.isOpened())
throw std::invalid_argument("No device found.");

std::vector<int> format_params;
format_params.push_back(CV_LOAD_IMAGE_COLOR);
format_params.push_back(CV_IMWRITE_PNG_STRATEGY);

for (;;)

cap.read(img);
cv::imencode(".png", img, buffer_, format_params);

std::string strbuf(buffer_.begin(), buffer_.end());
server_->sendString(socket, strbuf);


cap.release();










share|improve this question



















  • 1




    I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
    – api55
    Nov 7 at 8:48










  • @api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
    – Yevhenii Veretennikov
    Nov 9 at 6:41












up vote
2
down vote

favorite









up vote
2
down vote

favorite











Currently, I am working on a streaming project. I need to grab frames from USB camera and send them over TCP.



To open USB camera video stream I'm using cv::VideoCapture. This allows me to read already decoded frames. According to this question I understood that there is no way to get encoded frame data using cv::VideoCapture and I need to encode each frame again and send it whatever I need using cv::imencode. The problem is that I can encode frames to some specific format listed here, and, in case, I use either .jpg or .png the file size still quite big and on receiving side frame rate very poor.



My question is: Is there any way to get mjpeg or h264 encoded data directly
or maybe you can suggest a better way to encode frames.



OpenCV 3.4.3, camera RICOH THETA V, language C++.



My code:



void Streamer::start()

cv::Mat img;
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));

if (!cap.isOpened())
throw std::invalid_argument("No device found.");

std::vector<int> format_params;
format_params.push_back(CV_LOAD_IMAGE_COLOR);
format_params.push_back(CV_IMWRITE_PNG_STRATEGY);

for (;;)

cap.read(img);
cv::imencode(".png", img, buffer_, format_params);

std::string strbuf(buffer_.begin(), buffer_.end());
server_->sendString(socket, strbuf);


cap.release();










share|improve this question















Currently, I am working on a streaming project. I need to grab frames from USB camera and send them over TCP.



To open USB camera video stream I'm using cv::VideoCapture. This allows me to read already decoded frames. According to this question I understood that there is no way to get encoded frame data using cv::VideoCapture and I need to encode each frame again and send it whatever I need using cv::imencode. The problem is that I can encode frames to some specific format listed here, and, in case, I use either .jpg or .png the file size still quite big and on receiving side frame rate very poor.



My question is: Is there any way to get mjpeg or h264 encoded data directly
or maybe you can suggest a better way to encode frames.



OpenCV 3.4.3, camera RICOH THETA V, language C++.



My code:



void Streamer::start()

cv::Mat img;
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));

if (!cap.isOpened())
throw std::invalid_argument("No device found.");

std::vector<int> format_params;
format_params.push_back(CV_LOAD_IMAGE_COLOR);
format_params.push_back(CV_IMWRITE_PNG_STRATEGY);

for (;;)

cap.read(img);
cv::imencode(".png", img, buffer_, format_params);

std::string strbuf(buffer_.begin(), buffer_.end());
server_->sendString(socket, strbuf);


cap.release();







c++ opencv stream encode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:34









Zoe

10.7k73575




10.7k73575










asked Nov 7 at 6:31









Yevhenii Veretennikov

1113




1113







  • 1




    I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
    – api55
    Nov 7 at 8:48










  • @api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
    – Yevhenii Veretennikov
    Nov 9 at 6:41












  • 1




    I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
    – api55
    Nov 7 at 8:48










  • @api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
    – Yevhenii Veretennikov
    Nov 9 at 6:41







1




1




I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
– api55
Nov 7 at 8:48




I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
– api55
Nov 7 at 8:48












@api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
– Yevhenii Veretennikov
Nov 9 at 6:41




@api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
– Yevhenii Veretennikov
Nov 9 at 6:41

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184564%2fusb-camera-encoded-data-stream%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184564%2fusb-camera-encoded-data-stream%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3