[Libav-user] Decoding single NALUs from x264 programmatically (no luck even with parser), works fine with concatenated NALUs

Faraz Khan faraz at screenhero.com
Mon Jun 10 23:36:18 CEST 2013


Hi all,
I'm trying to use ffmpeg as a decoder for a real-time x264 stream that I'm
generating. It works fine if I try to decode entire frames, but if I try to
decode a single NALU the decoder errors out saying 'no frame'. I've tried
using the parser (av_parser_parse2) but the h264 decoder doesnt seem to
like that output either. I'm using x264 with annex-b and repeat-headers on.

The encoder config is as follows:

x264params.b_sliced_threads = 1;
x264params.i_slice_max_size = 1350;
x264params.i_width = yuvSize.width;
x264params.i_height = yuvSize.height;
x264params.i_fps_num = 10;
x264params.i_fps_den = 1;
x264params.b_vfr_input = 0;
x264params.rc.i_bitrate = 1500;

 // Intra refres:
x264params.i_keyint_max = 50000000;
x264params.b_intra_refresh = 1;

//Rate control:

x264params.rc.i_rc_method = X264_RC_ABR;
x264params.rc.i_vbv_buffer_size = 300;
x264params.rc.i_vbv_max_bitrate = 1500;

//For streaming:
x264params.b_repeat_headers = 1;
x264params.b_annexb = 1;

x264_param_apply_profile(&x264params, "baseline");



I do the encode with:

    int frame_size = x264_encoder_encode(x264Encoder, &nals, &i_nals, &
pic_in, &pic_out);


Now, since the max slice size is 1350, each packet output is a udp packet
of size < MTU (this is true) and sent across the network.

I iterate over the nals[i].p_payload and send them over to the ffmpeg side
for decoding. I receive the correct packet on the remote side.

If I assemble ALL the NALUs that were output in this frame and feed it
directly to the decoder (even without the parser), it works fine! If I feed
one NALU at a time, it fails (event with the parse). I'm sending it to the
parser like:


int plen = av_parser_parse2(codecParser, decoderContext, &outbuf, &outside,
indata,inlength,0,0,0);


plen always reports that it consumed the entire NALU that I gave it - after
consuming a few NALUs, the outsize and outbuf are set to some value.
Feeding it into the decoder using:


 int len = avcodec_decode_video2(decoderContext,decoderOutframe,
&gotpic,&avpkt);


Results in it saying 'No frame'. Again, if avpkt.data contains the entire
frame (all NALUs concatenated) it will work!


I'm obviously doing some obviously wrong - but I really cant figure out why
it wont decode a single NALU. Or is this a limitation in ffmpeg?


Thanks Guys!




--
Faraz Khan
Simple Collaboration Screensharing
www.screenhero.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130610/e7fa792b/attachment.html>


More information about the Libav-user mailing list