mirror of https://github.com/mpv-player/mpv
encode_lavc: replace deprecated av_init_packet()
This commit is contained in:
parent
b1bf4393a8
commit
39bed5c7fc
|
@ -731,6 +731,7 @@ static void encoder_destroy(void *ptr)
|
||||||
{
|
{
|
||||||
struct encoder_context *p = ptr;
|
struct encoder_context *p = ptr;
|
||||||
|
|
||||||
|
av_packet_free(&p->pkt);
|
||||||
avcodec_free_context(&p->encoder);
|
avcodec_free_context(&p->encoder);
|
||||||
free_stream(p->twopass_bytebuffer);
|
free_stream(p->twopass_bytebuffer);
|
||||||
}
|
}
|
||||||
|
@ -910,6 +911,9 @@ bool encoder_init_codec_and_muxer(struct encoder_context *p,
|
||||||
if (avcodec_parameters_from_context(p->info.codecpar, p->encoder) < 0)
|
if (avcodec_parameters_from_context(p->info.codecpar, p->encoder) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
p->pkt = av_packet_alloc();
|
||||||
|
MP_HANDLE_OOM(p->pkt);
|
||||||
|
|
||||||
encode_lavc_add_stream(p, p->encode_lavc_ctx, &p->info, on_ready, ctx);
|
encode_lavc_add_stream(p, p->encode_lavc_ctx, &p->info, on_ready, ctx);
|
||||||
if (!p->mux_stream)
|
if (!p->mux_stream)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -930,11 +934,9 @@ bool encoder_encode(struct encoder_context *p, AVFrame *frame)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AVPacket *packet = p->pkt;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
AVPacket packet = {0};
|
status = avcodec_receive_packet(p->encoder, packet);
|
||||||
av_init_packet(&packet);
|
|
||||||
|
|
||||||
status = avcodec_receive_packet(p->encoder, &packet);
|
|
||||||
if (status == AVERROR(EAGAIN))
|
if (status == AVERROR(EAGAIN))
|
||||||
break;
|
break;
|
||||||
if (status < 0 && status != AVERROR_EOF)
|
if (status < 0 && status != AVERROR_EOF)
|
||||||
|
@ -948,7 +950,7 @@ bool encoder_encode(struct encoder_context *p, AVFrame *frame)
|
||||||
if (status == AVERROR_EOF)
|
if (status == AVERROR_EOF)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
encode_lavc_add_packet(p->mux_stream, &packet);
|
encode_lavc_add_packet(p->mux_stream, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -83,7 +83,9 @@ struct encoder_context {
|
||||||
AVCodecContext *encoder;
|
AVCodecContext *encoder;
|
||||||
struct mux_stream *mux_stream;
|
struct mux_stream *mux_stream;
|
||||||
|
|
||||||
|
// (essentially private)
|
||||||
struct stream *twopass_bytebuffer;
|
struct stream *twopass_bytebuffer;
|
||||||
|
AVPacket *pkt;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Free with talloc_free(). (Keep in mind actual deinitialization requires
|
// Free with talloc_free(). (Keep in mind actual deinitialization requires
|
||||||
|
|
Loading…
Reference in New Issue