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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:11:09+00:00 2026-05-24T03:11:09+00:00

I am trying to encode a video from raw YUV to MPEG-2 using the

  • 0

I am trying to encode a video from raw YUV to MPEG-2 using the ffmpeg API.

My problem is that the API-generated file is approx. 1.7 times bigger than the equivalent files generated by ffmpeg itself.

I use the quantization parameter (via qmin and qmax) instead of the bitrate.

The API-version is basically:

//...
pCodecCtx->pix_fmt = PIX_FMT_YUV420P;
pCodecCtx->qmin = 3;
pCodecCtx->qmax = 3;
pCodecCtx->time_base.num = 1;
pCodecCtx->time_base.den = 30;
avcodec_open(pCodecCtx, avcodec_find_encoder(CODEC_ID_MPEG2VIDEO));
//...
while(/*...*/) {
  avcodec_encode_video(pCodecCtx, pOutbuf, outbufSize, pPicture);
  //..
}
//...

For ffmpeg itself, I use the command:

ffmpeg -s 352x288 -r 30 -i foreman_352x288.yuv -f mpeg2video -vcodec mpeg2video -r 30 -pix_fmt yuv420p -qmin 3 -qmax 3 foreman.m2v

Why does the API-generate file achieve a bitrate of 5212 kb/s and the file generated by ffmpeg for the same qp a bitrate of 3047 kb/s??

(Even more puzzling is that the smaller ffmpeg version has a slightly higher PSNR, 40.49 dB vs. 40.02 dB).

Are there any other relevant parameters that I missed? Does the ffmpeg actually respect the quantization parameter?

  • 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-24T03:11:10+00:00Added an answer on May 24, 2026 at 3:11 am

    When using the ffmpeg API, the picture type (I-frame, P-frame, etc.) needs to be set manually for each frame. By default, ffmpeg will make every frame an I-frame.

    The solution is to set the picture type before encoding a frame (here for a GOP size of 12):

    //...
    while(/*...*/) {
      if(pCodecCtx->frame_number % 12) 
        pPicture->pict_type = AV_PICTURE_TYPE_P;
    
      avcodec_encode_video(pCodecCtx, pOutbuf, outbufSize, pPicture);
      //...
    }
    //...
    

    Note that setting pCodecCtx->gop_size before the encoding does not help.

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

Sidebar

Related Questions

I am trying to encode series of images to one video file. I am
I am trying to encode video in h.264 that when split with Apples HTTP
I'm trying to encode a video from an IGraphBuilder, for this I would require
I am trying to create an app that sends a video file to a
I am trying to stream my webcam video using the ffmpeg to wowza media
Hi I am trying to play a video (wmv) file using MediaElement. I have
I'm trying to encode and upload two (or more) images from Flash using JPGEncoder.
I'm trying to encode a video with an mp3 and have that audio stream
I'm trying to get ffmpeg to encode several individual JPEG images into a video
I am trying to convert an avi video file to flv format via FFMPEG

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.