[FFmpeg-user] H264 Sliced Decoding Access Violation?

Robert Nagy ronag89 at gmail.com
Thu Aug 11 17:10:11 CEST 2011

I'm playing around a bit with thread decoding of H264. I would like to
decode slices.

However, I get an access violation inside of "thread_execute" at the line
"int r = func(s, reinterpret_cast<uint8_t*>(arg) + n*size);".

This works just fine with mpeg2 decoding.

Any ideas as to why I'm getting an access violation? Is it a bug in the
sliced h264 decoder, or am I doing something wrong?

int thread_execute(AVCodecContext* s, int (*func)(AVCodecContext *c2, void
*arg2), void* arg, int* ret, int count, int size)
for(size_t n = 0; n < count; ++n) // will be parallel_for
int r = func(s, reinterpret_cast<uint8_t*>(arg) + n*size);
      ret[n] = r;
return 0;

void thread_init(AVCodecContext* s)
static const size_t MAX_THREADS = 16; // See mpegvideo.h
static int dummy_opaque;

    s->active_thread_type = FF_THREAD_SLICE;
s->thread_opaque  = &dummy_opaque;
    s->execute  = thread_execute;
    //s->execute2  = thread_execute2; not used
    s->thread_count  = MAX_THREADS; // We are using a task-scheduler, so use
as many "threads/tasks" as possible.

void thread_free(AVCodecContext* s)

s->thread_opaque = nullptr;

int custom_avcodec_open(AVCodecContext* avctx, AVCodec* codec)
avctx->thread_count = 1;
if((codec->id == CODEC_ID_H264) &&
  (codec->capabilities & CODEC_CAP_SLICE_THREADS) &&
  (avctx->thread_type & FF_THREAD_SLICE))
// ff_thread_init will not be executed since thread_count == 1.
return avcodec_open(avctx, codec);

int custom_avcodec_close(AVCodecContext* avctx)
// ff_thread_free will not be executed since thread_opaque == nullptr.
return avcodec_close(avctx);

More information about the ffmpeg-user mailing list