[Libav-user] H.264 nal decode

srikanta mondal srkntmondal at gmail.com
Mon Apr 9 12:56:04 CEST 2012


Dear all, Thank you for reply. I have used x264 library. And I have the
following code ....


AVCodecContext* m_pContext;
void Encoding()
{
        IplImage *image;
        av_register_all() ;
   avcodec_init();


    codec = avcodec_find_encoder(CODEC_ID_H264);
    m_pContext = avcodec_alloc_context();
    picture = avcodec_alloc_frame();
    avcodec_get_context_defaults(m_pContext);
    m_pContext->flags    |= CODEC_FLAG_4MV;
    m_pContext->flags     |= CODEC_FLAG_PART;
    m_pContext->flags     |=CODEC_FLAG_TRUNCATED;
    m_pContext->flags2  |=  CODEC_FLAG2_CHUNKS;
    m_pContext->pix_fmt   =   PIX_FMT_YUV420P  /*It can be RGB also*/;
    m_pContext->skip_frame = AVDISCARD_DEFAULT;
    m_pContext->error_concealment = 3;
    m_pContext->error_recognition = 1;
    m_pContext->skip_loop_filter = AVDISCARD_DEFAULT;
    m_pContext->workaround_bugs = 1;
    m_pContext->codec_type = AVMEDIA_TYPE_VIDEO;
    m_pContext->codec_id = CODEC_ID_H264;


       x264_param_t param;
        x264_t *encoder;

        x264_param_default(&param);
        if(x264_param_default_preset(&param, "veryfast", "zerolatency") < 0)
        {
            cout<<"Error on preset";
        }
        param.i_threads = 1;
        param.i_width = col;
        param.i_height = row;
        param.i_fps_num = fps;
        param.i_fps_den = 1;

        // Intra refres:
        param.i_keyint_max = fps;
        param.b_intra_refresh = 1;
        //Rate control:
        param.rc.i_rc_method = X264_RC_CRF;        //X264_RC_CRF
X264_ANALYSE_BSUB16x16        X264_ANALYSE_BSUB16x16
        param.i_csp = X264_CSP_I420;            //X264_CSP_I420
X264_CSP_YV16
        param.rc.f_rf_constant = 25;//25
        param.rc.f_rf_constant_max = 25;//35
        //For streaming:
        param.b_repeat_headers =1;
        param.b_annexb = 1;                //1

        x264_param_apply_profile(&param, "baseline");

        encoder = x264_encoder_open(&param);
        x264_encoder_parameters(encoder, &param );
        int row = 480, col = 640;
        CvCapture *capt = cvCaptureFromCAM(0);

        while(true)
        {
               image = cvQueryFrame(capt);
               convertCtx =  sws_getContext (col, row , PIX_FMT_RGB24, col,
row , PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);

              sws_scale ( convertCtx , (uint8_t**)&image->imageData, &
srcstride, 0, col, pic_in.img.plane, pic_in.img.i_stride);
              i_frame_size = x264_encoder_encode( encoder, &headers,
&i_nal, &pic_in, &pic_out );
              decoding(heders[0].p_payload, i_frame_size);
      }
}

void decoding(uint8_t *data, int size)
{
    AVPacket *pkt;
    pkt = new AVPacket();
    int gotpicture;

    av_init_packet(pkt);
    avcodec_get_frame_defaults(picture);

    pkt->data = data;
    pkt->size = size;
    int outSize = avcodec_decode_video2(m_pContext, picture, &gotpicture,
pkt);
}

This is my brief code sniff.Please guide me how could I able to decode
directly without using file.

Thanks and regards
Srikanta Mondal


On Mon, Apr 9, 2012 at 3:27 PM, NITIN GOYAL <nitinkumgoyal at gmail.com> wrote:

> Read the dranger docs on how to decode the NALs or see the example program
> from libav source to start with.
>
> And if you have already done that, please share the issue you are finding.
>
>
> On Mon, Apr 9, 2012 at 3:21 PM, Kalileo <kalileo at universalx.net> wrote:
>
>>
>> On Apr 9, 2012, at 16:13 , srikanta mondal wrote:
>>
>> > Hi all,
>> > I am Srikanta Mondal from India. I am working on video compression and
>> sending each compressed frame to network.  I have done H.264 compression by
>> using libx264 and the function x264_encoder_encode() and I have got the
>> x264_nal_t for each frame. Now I have sent each compressed x264_nal_t  in
>> the network and in the receiver side that that x264_nal_t  are dumping in a
>> file. And another program just play the video using Opencv lib. But I want
>> to just decode the x264_nal_t  structure in the receiver side without using
>> the file. I have found there are some guidance with using ffmpeg library
>> but unfortunately I have failed to use the decoder. Anybody please help me.
>>
>> Sorry, I don't understand what you are trying to do.
>>
>> Please explain, and show also what you have done so far, and where
>> exactly you have a problem.
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120409/6b797331/attachment.html>


More information about the Libav-user mailing list