AVPacket *pkt = NULL;
while (!atomic_load(&c->exit)) {
- int got_packet, ret;
+ int got_packet = 0, ret;
AVFrame *frame;
Task task;
pthread_mutex_unlock(&c->task_fifo_mutex);
frame = task.indata;
- ret = avcodec_encode_video2(avctx, pkt, frame, &got_packet);
- pthread_mutex_lock(&c->buffer_mutex);
- av_frame_unref(frame);
- pthread_mutex_unlock(&c->buffer_mutex);
- av_frame_free(&frame);
+ ret = avctx->codec->encode2(avctx, pkt, frame, &got_packet);
if(got_packet) {
int ret2 = av_packet_make_refcounted(pkt);
if (ret >= 0 && ret2 < 0)
ret = ret2;
+ pkt->pts = pkt->dts = frame->pts;
} else {
pkt->data = NULL;
pkt->size = 0;
}
+ pthread_mutex_lock(&c->buffer_mutex);
+ av_frame_unref(frame);
+ pthread_mutex_unlock(&c->buffer_mutex);
+ av_frame_free(&frame);
pthread_mutex_lock(&c->finished_task_mutex);
c->finished_tasks[task.index].outdata = pkt; pkt = NULL;
c->finished_tasks[task.index].return_code = ret;
if( !(avctx->thread_type & FF_THREAD_FRAME)
- || !(avctx->codec->capabilities & AV_CODEC_CAP_INTRA_ONLY))
+ || !(avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
return 0;
if( !avctx->thread_count
int ret = av_opt_copy(thread_avctx->priv_data, avctx->priv_data);
if (ret < 0)
goto fail;
- } else
+ } else if (avctx->codec->priv_data_size) {
memcpy(thread_avctx->priv_data, avctx->priv_data, avctx->codec->priv_data_size);
+ }
thread_avctx->thread_count = 1;
thread_avctx->active_thread_type &= ~FF_THREAD_FRAME;