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 8869849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:34:42+00:00 2026-06-14T17:34:42+00:00

I am having an issue again with ffmpeg, I’m a newbie with ffmpeg, and

  • 0

I am having an issue again with ffmpeg, I’m a newbie with ffmpeg, and I can’t find a good tutorial up to date…

This time, when I play a video with ffmpeg, it plays too fast, ffmpeg is ignoring the FPS, I don’t want to handle that with a thread sleep, because the videos have differents FPS’s.

I created a thread, there you can find the loop:

AVPacket framepacket;

while(av_read_frame(formatContext,&framepacket)>= 0){
    pausecontrol.lock();

    // Is it a video or audio frame¿?
    if(framepacket.stream_index==gotVideoCodec){
        int framereaded;
        // Video? Ok
        avcodec_decode_video2(videoCodecContext,videoFrame,&framereaded,&framepacket);
        // Yeah, did we get it?
        if(framereaded && doit){
            AVRational millisecondbase = {1,1000};
            int f_number = framepacket.dts;
            int f_time = av_rescale_q(framepacket.dts,formatContext->streams[gotVideoCodec]->time_base,millisecondbase);
            currentTime=f_time;
            currentFrameNumber=f_number;

            int stWidth = videoCodecContext->width;
            int stHeight = videoCodecContext->height;
            SwsContext *ctx = sws_getContext(stWidth, stHeight, videoCodecContext->pix_fmt, stWidth,
            stHeight, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
            if(ctx!=0){
            sws_scale(ctx,videoFrame->data,videoFrame->linesize,0,videoCodecContext->height,videoFrameRGB->data,videoFrameRGB->linesize);
            QImage framecapsule=QImage(stWidth,stHeight,QImage::Format_RGB888);

            for(int y=0;y<stHeight;y++){
                memcpy(framecapsule.scanLine(y),videoFrameRGB->data[0]+y*videoFrameRGB->linesize[0],stWidth*3);
            }
            emit newFrameReady(framecapsule);
            sws_freeContext(ctx);
            }

        }
    }
    if(framepacket.stream_index==gotAudioCodec){
        // Audio? Ok
    }
    pausecontrol.unlock();
    av_free_packet(&framepacket);
}

Any Idea?

  • 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-14T17:34:43+00:00Added an answer on June 14, 2026 at 5:34 pm

    The simplest solution is to use a delay based on the FPS value

    firstFrame = true;
    for(;;)
    {
      //  decoding, color conversion, etc.
    
      if (!firstFrame)
      {
        const double frameDuration = 1000.0 / frameRate;
        duration_t actualDelay = get_local_time() - lastTime;
        if (frameDuration > actualDelay)
          sleep(frameDuration - actualDelay); 
      }
      else
        firstFrame = false;
    
      emit newFrameReady(framecapsule);
    
      lastTime = get_local_time();
    }
    

    get_local_time() and duration_t is abstract.

    A more accurate method is to use a time stamp for each frame, but the idea is the same

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

Sidebar

Related Questions

first time post for me :) I'm having this issue with the width of
It appears someone else is having this issue: Validation.HasError does not trigger again if
Hi guys I am having issue I have this query: SELECT * FROM useraccount
Having an issue here that I have tried everything I can think of but
I'm having an issue using jQuery autocomplete with dynamically created inputs (again created with
I am having an issue with IE (9 in this case) where I have
I have been having this issue for a while now and I cannot seem
I'm having this issue when I hit Run on the simulator/device, the project compiles
This is my first time using EOF and/or files, and I am having an
I'm having an issue with some server side validation and I can't tell if

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.