Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:21:54+00:00 2026-06-05T05:21:54+00:00

I need to parse a video stream (mpeg ts) from proprietary network protocol (which

  • 0

I need to parse a video stream (mpeg ts) from proprietary network protocol (which I already know how to do) and then I would like to use OpenCV to process the video stream into frames. I know how to use cv::VideoCapture from a file or from a standard URL, but I would like to setup OpenCV to read from a buffer(s) in memory where I can store the video stream data until it is needed. Is there a way to setup a call back method (or any other interfrace) so that I can still use the cv::VideoCapture object? Is there a better way to accomplish processing the video with out writing it out to a file and then re-reading it. I would also entertain using FFMPEG directly if that is a better choice. I think I can convert AVFrames to Mat if needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:21:56+00:00Added an answer on June 5, 2026 at 5:21 am

    I had a similar need recently. I was looking for a way in OpenCV to play a video that was already in memory, but without ever having to write the video file to disk. I found out that the FFMPEG interface already supports this through av_open_input_stream. There is just a little more prep work required compared to the av_open_input_file call used in OpenCV to open a file.

    Between the following two websites I was able to piece together a working solution using the ffmpeg calls. Please refer to the information on these websites for more details:

    http://ffmpeg.arrozcru.org/forum/viewtopic.php?f=8&t=1170

    http://cdry.wordpress.com/2009/09/09/using-custom-io-callbacks-with-ffmpeg/

    To get it working in OpenCV, I ended up adding a new function to the CvCapture_FFMPEG class:

    virtual bool openBuffer( unsigned char* pBuffer, unsigned int bufLen );
    

    I provided access to it through a new API call in the highgui DLL, similar to cvCreateFileCapture. The new openBuffer function is basically the same as the open( const char* _filename ) function with the following difference:

    err = av_open_input_file(&ic, _filename, NULL, 0, NULL);
    

    is replaced by:

    ic = avformat_alloc_context();
    ic->pb = avio_alloc_context(pBuffer, bufLen, 0, pBuffer, read_buffer, NULL, NULL);
    
    if(!ic->pb) {
        // handle error
    }
    
    // Need to probe buffer for input format unless you already know it
    AVProbeData probe_data;
    probe_data.buf_size = (bufLen < 4096) ? bufLen : 4096;
    probe_data.filename = "stream";
    probe_data.buf = (unsigned char *) malloc(probe_data.buf_size);
    memcpy(probe_data.buf, pBuffer, probe_data.buf_size);
    
    AVInputFormat *pAVInputFormat = av_probe_input_format(&probe_data, 1);
    
    if(!pAVInputFormat)
        pAVInputFormat = av_probe_input_format(&probe_data, 0);
    
    // cleanup
    free(probe_data.buf);
    probe_data.buf = NULL;
    
    if(!pAVInputFormat) {
        // handle error
    }
    
    pAVInputFormat->flags |= AVFMT_NOFILE;
    
    err = av_open_input_stream(&ic , ic->pb, "stream", pAVInputFormat, NULL);
    

    Also, make sure to call av_close_input_stream in the CvCapture_FFMPEG::close() function instead of av_close_input_file in this situation.

    Now the read_buffer callback function that is passed in to avio_alloc_context I defined as:

    static int read_buffer(void *opaque, uint8_t *buf, int buf_size)
    {
        // This function must fill the buffer with data and return number of bytes copied.
        // opaque is the pointer to private_data in the call to avio_alloc_context (4th param)
        
        memcpy(buf, opaque, buf_size);
        return buf_size;
    }
    

    This solution assumes the entire video is contained in a memory buffer and would probably have to be tweaked to work with streaming data.

    So that’s it! Btw, I’m using OpenCV version 2.1 so YMMV.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to parse MPEG stream using GStreamer..? I need to process all userdata field
I need to parse a URL string like this one: &ad_eurl=http://www.youtube.com/video/4bL4FI1Gz6s&hl=it_IT&iv_logging_level=3&ad_flags=0&endscreen_module=http://s.ytimg.com/yt/swfbin/endscreen-vfl6o3XZn.swf&cid=241&cust_gender=1&avg_rating=4.82280613104 I need to
I need to parse the bytes from a file so that I only take
I have some large files (images and video) which I need to store in
I have a project where I need to record a video using DirectShow from
I dont know on which tag i need to ask this question. I'm currently
I need to open a mp4 video from the assets folder and play it
Possible Duplicate: parse youtube video id using preg_match I'd like to extract the youtube
I need to get an info about the app/song/video by item id from iTunes
I need parse through a file and do some processing into it. The file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.