[FFmpeg-user] Bitstream "h264_mp4toannexb" filter does not work

Andrey Mochenov andrey.mochenov at idomoo.com
Wed Dec 25 17:17:40 CET 2013


Hi all,
We are using FFmpeg libraries git-ee94362 libavformat v55.2.100. Our
purpose is to mux two streams (video and audio) into M3U8 playlist using
HLS.
We are using AV_CODEC_ID_H264 output encoder, AV_PIX_FMT_YUV420P output
video pixel format and CODEC_FLAG_GLOBAL_HEADER flag for the encoder.
The last causes us to use "h264_mp4toannexb" bit stream filter.
So, here is the code snippet:

AVPacket outpkt = {0};
int isGotVideoPacket = 0;

av_init_packet(&outpkt);

// convert time in stream time base units, so that the encoder will fill
the packet appropriately
out_video_frame->pts = (int64_t) (video_frame_count *
in_video_frame_duration / av_q2d(out_video_stream->time_base));

int ret = avcodec_encode_video2(enc_out_video_ctx, &outpkt,
out_video_frame[i], &isGotVideoPacket);

assert(0 <= ret);

// if size is zero, it means the image was buffered
if ((1 == isGotVideoPacket) && (0 < outpkt.size)) {

 AVPacket new_outpkt = outpkt;

 if ((AVBitStreamFilterContext*) 0 != vbsf_ctx) {
  AVPacket new_outpkt = outpkt;

  ret = av_bitstream_filter_filter(vbsf_ctx, enc_out_video_ctx, (const
char*)0,
   &new_outpkt.data, &new_outpkt.size, outpkt.data, outpkt.size,
   outpkt.flags & AV_PKT_FLAG_KEY);

  if (ret > 0)
  {
   outpkt = new_outpkt;
  }
  else
  {
   // We get ret = -22
   char errbuf[128] = "";

                        // Both the functions get "Error number -22
occurred" that don't explain anything
    av_strerror (ret, errbuf, 128);
   av_make_error_string (errbuf, 128, ret);

  }

  assert(0 <= ret);

 }

 outpkt->stream_index = output_video_stream->index;

 // If to comment av_bitstream_filter_filter() and "if-else", then
 // At frame #37 we get the following error from
av_interleaved_write_frame():
 // [mpegts @ 09628140] H.264 bitstream malformed, no startcode found, use
the h264_mp4toannexb bitstream filter (-bsf h264_mp4toannexb).
 ret = av_interleaved_write_frame(ofmt_ctx, &outpkt);

 assert(0 <= ret);
}


Our questions:
1. What is the meaning of the "-22" error from av_bitstream_filter_filter()?
2. Where can we get full FFMPEG error code description list?
3. If we are using av_bitstream_filter_filter() right? If no, what is the
right way?

Andrey Mochenov.

Andrey Mochenov

Software Engineer

andrey.mochenov at idomoo.com

+972 54 539 8201 (mobile)



<http://www.idomoo.com/>


More information about the ffmpeg-user mailing list