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

  • SEARCH
  • Home
  • 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 6932927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:46:01+00:00 2026-05-27T11:46:01+00:00

I’m using a c++ library to write images captured from a webcam to an

  • 0

I’m using a c++ library to write images captured from a webcam to an libx264 encoded mp4 file.
The encoding is working properly but when it starts it writes 40 frames to the buffer. When I close the file these frames aren’t flushed so about 6 seconds of video are left unwritten (cam is about 6fps).

So i’m calling:

out_size = libffmpeg::avcodec_encode_video( codecContext, data->VideoOutputBuffer,data->VideoOutputBufferSize, data->VideoFrame );

// if zero size, it means the image was buffered
if ( out_size > 0 )
{
//... write to file
}

I can’t see a way of accessing the images that are left in the buffer. Any ideas?

  • 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-05-27T11:46:02+00:00Added an answer on May 27, 2026 at 11:46 am

    I’ve got this working using the following code to flush the buffer. Seems that I was searching for the wrong term – should have been “delayed frames”…

    void VideoFileWriter::Flush(void)
    {
    if ( data != nullptr )
    {
        int out_size = 0;
        int ret = 0;
    
        libffmpeg::AVCodecContext* c = data->VideoStream->codec;
        /* get the delayed frames */
        while (1) {
            libffmpeg::AVPacket packet;
            libffmpeg::av_init_packet(&packet);
    
            out_size = libffmpeg::avcodec_encode_video(c, data->VideoOutputBuffer, data->VideoOutputBufferSize, NULL);
            if (out_size < 0) {
                //fprintf(stderr, "Error encoding delayed frame %d\n", out_size);
                break;
            }
            if (out_size == 0) {
                break;
            }
            if (c->coded_frame->pts != AV_NOPTS_VALUE) {
                packet.pts = av_rescale_q(c->coded_frame->pts,
                              c->time_base,
                              data->VideoStream->time_base);
                //fprintf(stderr, "Video Frame PTS: %d\n", (int)packet.pts);
            } else {
                //fprintf(stderr, "Video Frame PTS: not set\n");
            }
            if (c->coded_frame->key_frame) {
                packet.flags |= AV_PKT_FLAG_KEY;
            }
            packet.stream_index = data->VideoStream->index;
            packet.data = data->VideoOutputBuffer;
            packet.size = out_size;
    
            ret = libffmpeg::av_interleaved_write_frame( data->FormatContext, &packet );
            if (ret != 0) {
                //fprintf(stderr, "Error writing delayed frame %d\n", ret);
                break;
            }
        }
        libffmpeg::avcodec_flush_buffers(data->VideoStream->codec);
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported

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.