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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:05:20+00:00 2026-05-23T05:05:20+00:00

So, for my final year project, I’m using Video4Linux2 to pull YUV420 images from

  • 0

So, for my final year project, I’m using Video4Linux2 to pull YUV420 images from a camera, parse them through to x264 (which uses these images natively), and then send the encoded stream via Live555 to an RTP/RTCP compliant video player on a client over a wireless network. All of this I’m trying to do in real-time, so there’ll be a control algorithm, but that’s not the scope of this question. All of this – except Live555 – is being written in C. Currently, I’m near the end of encoding the video, but want to improve performance.

To say the least, I’ve hit a snag… I’m trying to avoid User Space Pointers for V4L2 and use mmap(). I’m encoding video, but since it’s YUV420, I’ve been malloc’ing new memory to hold the Y’, U and V planes in three different variables for x264 to read upon. I would like to keep these variables as pointers to an mmap’ed piece of memory.

However, the V4L2 device has one single file descriptor for the buffered stream, and I need to split the stream into three mmap’ed variables adhering to the YUV420 standard, like so…

buffers[n_buffers].y_plane = mmap(NULL, (2 * width * height) / 3,
                                    PROT_READ | PROT_WRITE, MAP_SHARED,
                                    fd, buf.m.offset);
buffers[n_buffers].u_plane = mmap(NULL, width * height / 6,
                                    PROT_READ | PROT_WRITE, MAP_SHARED,
                                    fd, buf.m.offset +
                                    ((2 * width * height) / 3 + 1) /
                                    sysconf(_SC_PAGE_SIZE));
buffers[n_buffers].v_plane = mmap(NULL, width * height / 6,
                                    PROT_READ | PROT_WRITE, MAP_SHARED,
                                    fd, buf.m.offset +
                                    ((2 * width * height) / 3 + 
                                    width * height / 6 + 1) / 
                                    sysconf(_SC_PAGE_SIZE));

Where “width” and “height” is the resolution of the video (eg. 640×480).

From what I understand… MMAP seeks through a file, kind of like this (pseudoish-code):

fd = v4l2_open(...);
lseek(fd, buf.m.offset + (2 * width * height) / 3);
read(fd, buffers[n_buffers].u_plane, width * height / 6);

My code is located in a Launchpad Repo here (for more background):
http://bazaar.launchpad.net/~alex-stevens/+junk/spyPanda/files (Revision 11)

And the YUV420 format can be seen clearly from this Wiki illustration: http://en.wikipedia.org/wiki/File:Yuv420.svg (I essentially want to split up the Y, U, and V bytes into each mmap’ed memory)

Anyone care to explain a way to mmap three variables to memory from the one file descriptor, or why I went wrong? Or even hint at a better idea to parse the YUV420 buffer to x264? 😛

Cheers! ^^

  • 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-23T05:05:21+00:00Added an answer on May 23, 2026 at 5:05 am

    There is no need for three separate mmaps. Simply mmap once, then compute the base pointer for each plane relative to the base pointer of the whole map.

    Edit: You need something like this:

    unsigned char *y = mmap(...); /* map total size of all 3 planes */
    unsigned char *u = y + y_height*y_bytes_per_line;
    unsigned char *v = u + u_height*u_bytes_per_line;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on my final year project using java swings and jasper reports for
My final year project topic is Web-services using SOA. In this we were planning
For my final year project i'l be taking the photographs from the mobile phone
I have 2 weeks to finish my final year project.I need a GUI IDE
As a part of my final year university project I am designing a social
I am doing a Final Year Project to track an object(human) by drawing a
As part of my Final Year Project I've developed a desktop application, which fits
Currently i'm working on my final year project. In a webpage which loads data
I am currently writing a genre classification application as my final year project in
I'm looking into building a group work app for my final year project next

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.