- int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
- AVPacket *avpkt,
- const AVFrame *frame,
- int *got_packet_ptr)
{
}
X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
{
do {
if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
return AVERROR_EXTERNAL;
ret = encode_nals(ctx, pkt, nal, nnal);
if (ret < 0)
return ret;
} while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));
if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
return AVERROR_EXTERNAL;
ret = encode_nals(ctx, pkt, nal, nnal);
if (ret < 0)
return ret;
} while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));
}
static int encode_nals(AVCodecContext *ctx, AVPacket *pkt,
const x264_nal_t *nals, int nnal)
{
X264Context *x4 = ctx->priv_data;
uint8_t *p;
int i, size = x4->sei_size, ret;
if (!nnal)
return 0;
for (i = 0; i < nnal; i++)
size += nals[i].i_payload;
if ((ret = ff_alloc_packet2(ctx, pkt, size, 0)) < 0)
return ret;
p = pkt->data;
/* Write the SEI as part of the first frame. */
if (x4->sei_size > 0 && nnal > 0) {
if (x4->sei_size > size) {
av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n");
return -1;
}
memcpy(p, x4->sei, x4->sei_size);
p += x4->sei_size;
x4->sei_size = 0;
av_freep(&x4->sei);
}
for (i = 0; i < nnal; i++){
memcpy(p, nals[i].p_payload, nals[i].i_payload);
p += nals[i].i_payload;
}
return 1;
}
const x264_nal_t *nals, int nnal)
{
X264Context *x4 = ctx->priv_data;
uint8_t *p;
int i, size = x4->sei_size, ret;
if (!nnal)
return 0;
for (i = 0; i < nnal; i++)
size += nals[i].i_payload;
if ((ret = ff_alloc_packet2(ctx, pkt, size, 0)) < 0)
return ret;
p = pkt->data;
/* Write the SEI as part of the first frame. */
if (x4->sei_size > 0 && nnal > 0) {
if (x4->sei_size > size) {
av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n");
return -1;
}
memcpy(p, x4->sei, x4->sei_size);
p += x4->sei_size;
x4->sei_size = 0;
av_freep(&x4->sei);
}
for (i = 0; i < nnal; i++){
memcpy(p, nals[i].p_payload, nals[i].i_payload);
p += nals[i].i_payload;
}
return 1;
}