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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:46:34+00:00 2026-06-12T06:46:34+00:00

I have a webcam video recorder program built with python, opencv and ffmpeg It

  • 0

I have a webcam video recorder program built with python, opencv and ffmpeg

It works ok except that the color of the video is more blue than the reality. The problem seems to come from color format of images.

It seems that OpenCv is giving BGR images and ffmpeg+libx264 is expecting YUV420p. I’ve read that YUV420p correspond to YCbCr.

opencv has no conversion from BGR to YCbCr. It only has a conversion to YCrCb.

I have made some searchs and tried different alternatives to try converting opencv image to something that could be ok for ffmpeg+libx264. None is working. At this point, I am a bit lost and I would appreciate any pointer that could help me to fix this color issue.

  • 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-12T06:46:35+00:00Added an answer on June 12, 2026 at 6:46 am

    You are right, the default pixel format of OpenCV is BGR.

    The equivalent format on the ffmpeg side would be BGR24, so you don’t need to convert it to YUV420p if you don’t want to.

    This post shows how to use a python application to capture frames from the webcam and write the frames to stdout. The purpose is to invoke this app on the cmd-line and pipe the result directly to the ffmpeg application, which stores the frames on the disk. Quite clever indeed!

    capture.py:

    import cv, sys
    
    cap = cv.CaptureFromCAM(0)
    if not cap:
        sys.stdout.write("failed CaptureFromCAM")
    
    while True :
        if not cv.GrabFrame(cap) : 
            break
    
        frame = cv.RetrieveFrame(cap)
        sys.stdout.write( frame.tostring() )
    

    And the command to be executed on the shell is:

    python capture.py | ffmpeg -f rawvideo -pix_fmt bgr24 -s 640x480 -r 30 -i - -an -f avi -r 30 foo.avi
    

    Where:

    • -r gives the frame rate coming off the camera
    • -an says “don’t encode audio”

    I tested this solution on my Mac OS X with OpenCV 2.4.2.

    EDIT:

    In case you haven’t tried to record from the camera and use OpenCV to write the video to an mp4 file on the disk, here we go:

    import cv, sys
    
    cap = cv.CaptureFromCAM(0)   # 0 is for /dev/video0
    if not cap:
        sys.stdout.write("!!! Failed CaptureFromCAM")
        sys.exit(1)
    
    frame = cv.RetrieveFrame(cap)
    if not frame: 
        sys.stdout.write("!!! Failed to retrieve first frame")
        sys.exit(1)
    
    # Unfortunately, the following instruction returns 0
    #fps = cv.GetCaptureProperty(cap, cv.CV_CAP_PROP_FPS)
    fps = 25.0      # so we need to hardcode the FPS
    print "Recording at: ", fps, " fps"  
    
    frame_size = cv.GetSize(frame)
    print "Video size: ", frame_size  
    
    writer = cv.CreateVideoWriter("out.mp4", cv.CV_FOURCC('F', 'M', 'P', '4'), fps, frame_size, True)
    if not writer:
        sys.stdout.write("!!! Error in creating video writer")
        sys.exit(1)
    
    
    while True :
        if not cv.GrabFrame(cap) : 
            break
        frame = cv.RetrieveFrame(cap)
        cv.WriteFrame(writer, frame)
    
    cv.ReleaseVideoWriter(writer)
    cv.ReleaseCapture(cap)
    

    I’ve tested this with Python 2.7 on Mac OS X and OpenCV 2.4.2.

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

Sidebar

Related Questions

I have a program that receives webcam video and displays it on a C#
I have a webcam that works by re-uploading the same file and overwriting itself
I have written a program using Python and OpenCV where I perform operations on
I have a Directshow application that needs to preview a webcam video, and when
I have a script, wacaw ( http://webcam-tools.sourceforge.net/ ) that outputs video from my webcam
I have a server that's taking video clips with a webcam and placing them
I want to write a program that can capture video through my webcam by
I have a huge list of video files from a webcam that have that
I have a webcam (actually 3) and java program to capture the frames. However,
My partner and I have a webcam site that basically runs the old-school method....Every

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.