• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
rgaule

VP8 Video Encoding Glitch (RGB->YUV) Picture Included

1 post in this topic

0bdLq4l.png

 

Hello. I'm trying to implement a VP8 Encoder, I'm working with the libvpx codec.

I'm taking a RGB 24bit bitmap, converting the bytes into YV12 format and then passing those along to the VP8 Encoder. My output file plays, but the image is quite distorted. To me it obviously looks like a one-off error, or something with the stride length being incorrect.

Here's the conversion code. I have two functions, both found easily online for RGB->YUV and both produce the same results...

#define rgbtoy(b, g, r, y)   \
y = (unsigned char)(((int)(30 * r) + (int)(59 * g) + (int)(11 * b)) / 100)

#define rgbtoyuv(b, g, r, y, u, v)   \
rgbtoy(b, g, r, y);  \
u = (unsigned char)(((int)(-17 * r) - (int)(33 * g) + (int)(50 * b) + 12800) / 100); \
v = (unsigned char)(((int)(50 * r) - (int)(42 * g) - (int)(8 * b) + 12800) / 100)

namespace VP8 
{
   public ref class Converter
   {
   public:
    static void RGBtoYUV420PSameSize(const unsigned char *rgb, vpx_image_t* yuvImage,unsigned int rgbIncrement, unsigned int srcFrameWidth, unsigned int srcFrameHeight)
    {
            unsigned int planeSize = srcFrameWidth * srcFrameHeight;
            unsigned int halfWidth = srcFrameWidth >> 1;

            // get pointers to the data
            unsigned char* yplane = yuvImage->planes[VPX_PLANE_Y];
            unsigned char* uplane = yuvImage->planes[VPX_PLANE_U];
            unsigned char* vplane = yuvImage->planes[VPX_PLANE_V];

            for (unsigned int y = 0; y < srcFrameHeight; y++)
            {
                    unsigned char* yline = yplane + (y * srcFrameWidth);
                    unsigned char* uline = uplane + ((y >> 1) * halfWidth);
                    unsigned char* vline = vplane + ((y >> 1) * halfWidth);

                    for (unsigned  int x = 0; x < srcFrameWidth; x += 2)
                    {
                            rgbtoyuv(rgb[2], rgb[1], rgb[0], *yline, *uline, *vline);
                            rgb += rgbIncrement;
                            yline++;

                            rgbtoyuv(rgb[2], rgb[1], rgb[0], *yline, *uline, *vline);
                            rgb += rgbIncrement;
                            yline++;
                            uline++;
                            vline++;
                    }
                }

    static void ConvertRGB24ToI420(unsigned char *rgbData, vpx_image_t *yuvImage, int srcFrameWidth, int srcFrameHeight)
    {
       int rgb24Stride = srcFrameWidth * 3;

       int rgb1 = 0;
       int yi1 = 0;
       int uvi = 0;

        for (int ypos = 0; ypos < srcFrameHeight; ypos += 2)
        {
            for (int xpos = 0; xpos < srcFrameWidth; xpos += 2)
            {
                    int rgb2 = rgb1 + 3;
                    int rgb3 = rgb1 + rgb24Stride;
                    int rgb4 = rgb2 + rgb24Stride;

                    int ro = 0;
                    int go = 1;
                    int bo = 2;

                    int r1 = rgbData[rgb1+ro];
                    int g1 = rgbData[rgb1+go];
                    int b1 = rgbData[rgb1+bo];

                    int r2 = rgbData[rgb2+ro];
                    int g2 = rgbData[rgb2+go];
                    int b2 = rgbData[rgb2+bo];

                    int r3 = rgbData[rgb3+ro];
                    int g3 = rgbData[rgb3+go];
                    int b3 = rgbData[rgb3+bo];

                    int r4 = rgbData[rgb4+ro];
                    int g4 = rgbData[rgb4+go];
                    int b4 = rgbData[rgb4+bo];

                    int yi2 = yi1 + 1;
                    int yi3 = yi1 + srcFrameWidth;
                    int yi4 = yi3 + 1;

                    int Y1 = getY(r1, g1, b1);
                    int Y2 = getY(r2, g2, b2);
                    int Y3 = getY(r3, g3, b3);
                    int Y4 = getY(r4, g4, b4);

                    yuvImage->planes[VPX_PLANE_Y][yi1] = (unsigned char)Y1;
                    yuvImage->planes[VPX_PLANE_Y][yi2] = (unsigned char)Y2;
                    yuvImage->planes[VPX_PLANE_Y][yi3] = (unsigned char)Y3;
                    yuvImage->planes[VPX_PLANE_Y][yi4] = (unsigned char)Y4;

                    int u1 = getU(r1, g1, b1, Y1);
                    int u2 = getU(r2, g2, b2, Y2);
                    int u3 = getU(r3, g3, b3, Y3);
                    int u4 = getU(r4, g4, b4, Y4);

                    int v1 = getV(r1, g1, b1, Y1);
                    int v2 = getV(r2, g2, b2, Y2);
                    int v3 = getV(r3, g3, b3, Y3);
                    int v4 = getV(r4, g4, b4, Y4);

                    yuvImage->planes[VPX_PLANE_U][uvi] = (unsigned char)((u1 + u2 + u3 + u4) / 4.0f);
                    yuvImage->planes[VPX_PLANE_V][uvi] = (unsigned char)((v1 + v2 + v3 + v4) / 4.0f);

                    rgb1 += 6;
                    yi1 += 2;
                    uvi += 1;
            }
            rgb1 += rgb24Stride;
            yi1 += srcFrameWidth;
       }
   }
private:
   static inline  int getR(int y, int u, int v)
   {
       return clamp(y + (int) (1.402f * (v - 128)));
   }    
   static inline int getG(int y, int u, int v)
   {
       return clamp(y - (int) (0.344f * (u - 128) + 0.714f * (v - 128)));
   }    
   static inline int getB(int y, int u, int v)
   {
       return clamp(y + (int) (1.772f * (u - 128)));
   }        
   static inline int getY(int r, int g, int b)
   {
       return (int) (0.299f * r + 0.587f * g + 0.114f * b);
   }
   static inline int getU(int r, int g, int b, int y)
   {
    //return (int)((b - y)*0.565f);
       return (int) (-0.169f * r - 0.331f * g + 0.499f * b + 128);
   }    
    static inline int getV(int r, int g, int b, int y)
   {
    //return (int)((r - y)*0.713f);
       return (int) (0.499f * r - 0.418f * g - 0.0813f * b + 128);
   }    
   static inline int clamp(int value)
   {
       return Math::Min(Math::Max(value, 0), 255);
   }
}
Edited by rgaule
0

Share this post


Link to post
Share on other sites

Try changing these lines to use the YUV image stride:

unsigned char* yline = yplane + (y * yuvImage->stride[VPX_PLANE_Y]);
unsigned char* uline = uplane + (y * yuvImage->stride[VPX_PLANE_U]);
unsigned char* vline = vplane + (y * yuvImage->stride[VPX_PLANE_V]);

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0