UDP sample with sdk 1.1.0

303 views
Skip to first unread message

Spun

unread,
Jun 4, 2012, 10:53:29 AM6/4/12
to Application Developers, pierre....@gmail.com
Hi,
I'm starting to learn how vp8 works because i have to write a
application that takes 2 streams from 2 webcams, compress them and
sends via internet to a remote place where they are uncompressed and
shown.

I started with the udp sample provided in the web and i found that you
can not compile it with the latest version of the SDK. you must use
the 1.0.0.

Is there a way to use the latest SDK to compile that sample? Someone
has made the necessary changes to the sample in order to get it
working with the last version of the SDK? Or, there is a sample where
encoding and decoding real time frames is shown?

thanks!

James Zern

unread,
Jun 4, 2012, 7:02:23 PM6/4/12
to apps-...@webmproject.org, pierre....@gmail.com
On Mon, Jun 4, 2012 at 7:53 AM, Spun <djy...@gmail.com> wrote:
> Hi,
> I'm starting to learn how vp8 works because i have to write a
> application that takes 2 streams from 2 webcams, compress them and
> sends via internet to a remote place where they are uncompressed and
> shown.
>
> I started with the udp sample provided in the web and i found that you
> can not compile it with the latest version of the SDK. you must use
> the 1.0.0.
>
Thanks for bringing this up!
I think
https://gerrit.chromium.org/gerrit/24445
should fix the issue.

> Is there a way to use the latest SDK to compile that sample? Someone
> has made the necessary changes to the sample in order to get it
> working with the last version of the SDK? Or, there is a sample where
> encoding and decoding real time frames is shown?
>
> thanks!
>
> --
> You received this message because you are subscribed to the Google Groups "Application Developers" group.
> To post to this group, send email to apps-...@webmproject.org.
> To unsubscribe from this group, send email to apps-devel+...@webmproject.org.
> For more options, visit this group at http://groups.google.com/a/webmproject.org/group/apps-devel/?hl=en.
>

Spun

unread,
Jun 5, 2012, 4:22:28 AM6/5/12
to Application Developers
Hi, thanks for the fast reply. I tried the new version and after
changing some const values ( PLANE_Y to VPX_PLANE_Y , etc) in a few
more palces it compiled and worked fine with the vpx 1.1.0.

thanks a lot!

On 5 jun, 01:02, James Zern <jz...@google.com> wrote:
> On Mon, Jun 4, 2012 at 7:53 AM, Spun <djy2...@gmail.com> wrote:
> > Hi,
> > I'm starting to learn how vp8 works because i have to write a
> > application that takes 2 streams from 2 webcams, compress them and
> > sends via internet to a remote place where they are uncompressed and
> > shown.
>
> > I started with the udp sample provided in the web and i found that you
> > can not compile it with the latest version of the SDK. you must use
> > the 1.0.0.
>
> Thanks for bringing this up!
> I think
>  https://gerrit.chromium.org/gerrit/24445
> should fix the issue.
>
>
>
>
>
>
>
> > Is there a way to use the latest SDK to compile that sample? Someone
> > has made the necessary changes to the sample in order to get it
> > working with the last version of the SDK? Or, there is a sample where
> > encoding and decoding real time frames is shown?
>
> > thanks!
>
> > --
> > You received this message because you are subscribed to the Google Groups "Application Developers" group.
> > To post to this group, send email to apps-de...@webmproject.org.
> > To unsubscribe from this group, send email to apps-devel+unsubscr...@webmproject.org.

Spun

unread,
Jun 7, 2012, 6:35:39 AM6/7/12
to apps-...@webmproject.org
Hi again,


after dealing with the udp sample and trying to use it in my project, I have a couple of doubts. I'll post the code so we can see what are we dealing with:

Encoding step:

initialitation of the encoder ( the same as in udp sample):

vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, &cfgEncoder, 0);
    cfgEncoder.rc_target_bitrate = video_bitrate;
    cfgEncoder.g_w = _width * 2;//we want to compress the side by side frame
    cfgEncoder.g_h = _height;
    cfgEncoder.g_timebase.num = 1;
    cfgEncoder.g_timebase.den = (int) 10000000;
    cfgEncoder.rc_end_usage = VPX_CBR;
    cfgEncoder.g_pass = VPX_RC_ONE_PASS;
    cfgEncoder.g_lag_in_frames = 0;
    cfgEncoder.rc_min_quantizer = 20;
    cfgEncoder.rc_max_quantizer = 50;
    cfgEncoder.rc_dropframe_thresh = 1;
    cfgEncoder.rc_buf_optimal_sz = 1000;
    cfgEncoder.rc_buf_initial_sz = 1000;
    cfgEncoder.rc_buf_sz = 1000;
    cfgEncoder.g_error_resilient = 1;
    cfgEncoder.kf_mode = VPX_KF_DISABLED;
    cfgEncoder.kf_max_dist = 999999;
    cfgEncoder.g_threads = 1;

    vpx_img_alloc(&raw, VPX_IMG_FMT_I420, _width * 2, _height, 1);
   
    cfgEncoder.rc_target_bitrate = video_bitrate;

    vpx_codec_enc_init(&encoder, &vpx_codec_vp8_cx_algo, &cfgEncoder, 0);
    //vpx_codec_control_(&encoder, VP8E_SET_CPUUSED, cpu_used);
    int static_threshold = 1200;
    vpx_codec_control_(&encoder, VP8E_SET_STATIC_THRESHOLD, static_threshold);
    vpx_codec_control_(&encoder, VP8E_SET_ENABLEAUTOALTREF, 0);

NOTE: the image i want to encode comes from two webcams capturing at 1280 * 720 each. after it i concatenate the two separate images into one large image of 2560 * 720 ( see attached one)


encode the frame:

    RGBtoYUV420PSameSize((unsigned char*)img->imageData,raw.img_data,3,0,cfgEncoder.g_w,cfgEncoder.g_h);
    //note: copied from: http://comserver.googlecode.com/svn/trunk/demo/comDemo/coder/vp8.cpp

    buffer_time = get_time() / 1000.000;
    long long time_in_nano_seconds = (long long)(buffer_time * 10000000.000 + .5);
    const vpx_codec_cx_pkt_t *pkt;
    vpx_codec_iter_t iter = NULL;
    flags = 0;
    vpx_codec_err_t error = vpx_codec_encode(&encoder, &raw, time_in_nano_seconds, 30000000, flags, VPX_DL_REALTIME);

    pkt = vpx_codec_get_cx_data(&encoder, &iter);

    memcpy(_cpCompressedData,pkt->data.frame.buf,pkt->data.frame.sz);

Decoding step:

init of the decoder:

vp8_postproc_cfg_t      ppcfg;

    vpx_codec_dec_init(&decoder, &vpx_codec_vp8_dx_algo, &cfgDecoder, 0);

    /* Config post processing settings for decoder */
    ppcfg.post_proc_flag = VP8_DEMACROBLOCK | VP8_DEBLOCK | VP8_ADDNOISE;
    ppcfg.deblocking_level = 5     ;
    ppcfg.noise_level = 1  ;
    vpx_codec_control(&decoder, VP8_SET_POSTPROC, &ppcfg);


decoding the frame:

    vpx_codec_iter_t  iter = NULL;
    vpx_image_t    *img;

    if (vpx_codec_decode(&decoder, _cpCompressedData, packetSize, 0, 0))
    {

        return -1;
    }

    //img = vpx_codec_get_frame(&decoder, &iter);

    FILE * outfile = fopen("E:\\testImage.yuv", "wb");
     while((img = vpx_codec_get_frame(&decoder, &iter))) {                  
            unsigned int plane, y;

            for(plane=0; plane < 3; plane++) {                               
                unsigned char *buf =img->planes[plane];                      
                                                                             
                for(y=0; y < (plane ? (img->d_h + 1) >> 1 : img->d_h); y++) {
                    if(fwrite(buf, 1, (plane ? (img->d_w + 1) >> 1 : img->d_w),outfile));
                    buf += img->stride[plane];                               
                }                                                            
            }                                                                
        }

    fclose (outfile);

    //note: the saved file is the .yuv attached.


So, what I need is after the decoding step, show this image in the screen, like with opencv. I tried several ways to convert from I420 ( when i check the image format is this one ) to rgb but i can't find the good way to do it. Is there any function or method to convert the decoded frame to a rgb image as it was the original one? Did i make any mistake in the configuration of the encoder/decoder? is there a better way to do this? Is there a sample that decodes a frame and writes it as rgb image?

thanks for the help,





El dimarts 5 de juny de 2012 10:22:28 UTC+2, Spun va escriure:
testImage.yuv
frameToEncode.jpg

James Zern

unread,
Jun 7, 2012, 2:15:04 PM6/7/12
to apps-...@webmproject.org
Hi,
This looks good and converts to png, bmp, etc. just fine with ffmpeg:
$ ffmpeg -s 2560x720 -i testImage.yuv testImage.png

>
> So, what I need is after the decoding step, show this image in the screen,
> like with opencv. I tried several ways to convert from I420 ( when i check
> the image format is this one ) to rgb but i can't find the good way to do
> it. Is there any function or method to convert the decoded frame to a rgb
> image as it was the original one? Did i make any mistake in the
> configuration of the encoder/decoder? is there a better way to do this? Is
> there a sample that decodes a frame and writes it as rgb image?
>

There isn't any color conversion code in libvpx.
There's a dated snapshot in the libvpx tree, but I believe upstream
libyuv [1] has support for this. If libyuv will serve the purpose I'd
like to update our snapshot at some point and work that into an
example. Another option would be to use the libraries from ffmpeg
(libswscale [2]) as they handle the color convert in the example
above.

[1] http://code.google.com/p/libyuv/
[2] http://ffmpeg.org/doxygen/trunk/swscale_8h-source.html
> To view this discussion on the web visit
> https://groups.google.com/a/webmproject.org/d/msg/apps-devel/-/aHJxSYAKr-QJ.
>
> To post to this group, send email to apps-...@webmproject.org.
> To unsubscribe from this group, send email to
> apps-devel+...@webmproject.org.

Spun

unread,
Jun 8, 2012, 8:42:16 AM6/8/12
to apps-...@webmproject.org, pierre....@gmail.com
Hi, thanks for the fast reply. I'm working on it, as soon as I get somethng working i'll let you know.

El dilluns 4 de juny de 2012 16:53:29 UTC+2, Spun va escriure:

Spun

unread,
Jun 8, 2012, 9:23:21 AM6/8/12
to apps-...@webmproject.org, pierre....@gmail.com
Hi again,

i finally have it working, so now i can decode and convert to rgb using libyuv and the funcion

libyuv::I420ToRGB24(img->planes[VPX_PLANE_Y],img->stride[VPX_PLANE_Y],
                        img->planes[VPX_PLANE_U],img->stride[VPX_PLANE_U],
                        img->planes[VPX_PLANE_V],img->stride[VPX_PLANE_V],
                        _pDestFrame,2560 * 3,2560,720);

just build the lib, include it in my project and use it. Now i have to deal with other things to see finally the results and valorate the frame rate and the latency of the system.

Thanks for your help!


El dilluns 4 de juny de 2012 16:53:29 UTC+2, Spun va escriure:
Hi,

James Zern

unread,
Jun 8, 2012, 1:22:16 PM6/8/12
to apps-...@webmproject.org, pierre....@gmail.com
On Fri, Jun 8, 2012 at 6:23 AM, Spun <djy...@gmail.com> wrote:
> Hi again,
>
> i finally have it working, so now i can decode and convert to rgb using
> libyuv and the funcion
>
Great I'm glad you got something that works for you.

> libyuv::I420ToRGB24(img->planes[VPX_PLANE_Y],img->stride[VPX_PLANE_Y],
>                         img->planes[VPX_PLANE_U],img->stride[VPX_PLANE_U],
>                         img->planes[VPX_PLANE_V],img->stride[VPX_PLANE_V],
>                         _pDestFrame,2560 * 3,2560,720);
>
Thanks for this, it seems simple enough so maybe we can update our
snapshot and work this into an example.

> just build the lib, include it in my project and use it. Now i have to deal
> with other things to see finally the results and valorate the frame rate and
> the latency of the system.
>
OK let us know if you run into any further issues.

> Thanks for your help!
>
>
> El dilluns 4 de juny de 2012 16:53:29 UTC+2, Spun va escriure:
>>
>> Hi,
>> I'm starting to learn how vp8 works because i have to write a
>> application that takes 2 streams from 2 webcams, compress them and
>> sends via internet to a remote place where they are uncompressed and
>> shown.
>>
>> I started with the udp sample provided in the web and i found that you
>> can not compile it with the latest version of the SDK. you must use
>> the 1.0.0.
>>
>> Is there a way to use the latest SDK to compile that sample? Someone
>> has made the necessary changes to the sample in order to get it
>> working with the last version of the SDK? Or, there is a sample where
>> encoding and decoding real time frames is shown?
>>
>> thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Application Developers" group.
> To view this discussion on the web visit
> https://groups.google.com/a/webmproject.org/d/msg/apps-devel/-/byoF553spCsJ.
Reply all
Reply to author
Forward
0 new messages