Note that there are some explanatory texts on larger screens.

plurals
  1. POh264 ffmpeg: How to initialize ffmpeg to decode NALs created with x264
    primarykey
    data
    text
    <p>I have encoded some frames using x264, using x264_encoder_encode and after that I have created AVPackets using a function like this:</p> <pre><code>bool PacketizeNals( uint8_t* a_pNalBuffer, int a_nNalBufferSize, AVPacket* a_pPacket ) { if ( !a_pPacket ) return false; a_pPacket-&gt;data = a_pNalBuffer; a_pPacket-&gt;size = a_nNalBufferSize; a_pPacket-&gt;stream_index = 0; a_pPacket-&gt;flags = AV_PKT_FLAG_KEY; a_pPacket-&gt;pts = int64_t(0x8000000000000000); a_pPacket-&gt;dts = int64_t(0x8000000000000000); } </code></pre> <p>I call this function like this:</p> <pre><code>x264_nal_t* nals; int num_nals = encode_frame(pic, &amp;nals); for (int i = 0; i &lt; num_nals; i++) { AVPacket* pPacket = ( AVPacket* )av_malloc( sizeof( AVPacket ) ); av_init_packet( pPacket ); if ( PacketizeNals( nals[i].p_payload, nals[i].i_payload, pPacket ) ) { packets.push_back( pPacket ); } } </code></pre> <p>Now what I want to do is to decode these AVPackets using avcodec_decode_video2. I think the problem is that I haven't initialized properly the decoder because to encode I used "ultrafast" profile and "zerolatency" tune ( x264 ) and to decode I don't know how to specify to ffmpeg these options. In some examples I have read people initialize the decoder using the file where the video is stored, but in this case I have directly the AVPackets. What I'm doing to try to decode is:</p> <pre><code>avcodec_init(); avcodec_register_all(); AVCodec* pCodec; pCodec=avcodec_find_decoder(CODEC_ID_H264); AVCodecContext* pCodecContext; pCodecContext=avcodec_alloc_context(); avcodec_open(pCodecContext,pCodec); pCodecContext-&gt;width = 320; pCodecContext-&gt;height = 200; pCodecContext-&gt;extradata = NULL; unsigned int nNumPackets = packets.size(); int frameFinished = 0; for ( auto it = packets.begin(); it != packets.end(); it++ ) { AVFrame* pFrame; pFrame = avcodec_alloc_frame(); AVPacket* pPacket = *it; int iReturn = avcodec_decode_video2( pCodecContext, pFrame, &amp;frameFinished, pPacket ); } </code></pre> <p>But in iReturn always is -1.</p> <p>Can anyone help me? Sorry if my knowledge in this area es low, I'm new.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload