fftools/ffmpeg_enc: use AVFrame.hw_frames_ctx for encoder hw setup

It should be the same as the one that can be extracted from the filter
and does not require access to outside data.
This commit is contained in:
Anton Khirnov 2023-05-19 09:46:31 +02:00
parent f15b206286
commit 2b3905254e
1 changed files with 8 additions and 12 deletions

View File

@ -103,22 +103,18 @@ fail:
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
static int hw_device_setup_for_encode(OutputStream *ost) static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref)
{ {
const AVCodecHWConfig *config; const AVCodecHWConfig *config;
HWDevice *dev = NULL; HWDevice *dev = NULL;
AVBufferRef *frames_ref = NULL;
int i; int i;
if (ost->filter) { if (frames_ref &&
frames_ref = av_buffersink_get_hw_frames_ctx(ost->filter->filter); ((AVHWFramesContext*)frames_ref->data)->format ==
if (frames_ref && ost->enc_ctx->pix_fmt) {
((AVHWFramesContext*)frames_ref->data)->format == // Matching format, will try to use hw_frames_ctx.
ost->enc_ctx->pix_fmt) { } else {
// Matching format, will try to use hw_frames_ctx. frames_ref = NULL;
} else {
frames_ref = NULL;
}
} }
for (i = 0;; i++) { for (i = 0;; i++) {
@ -388,7 +384,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
av_dict_set(&ost->encoder_opts, "flags", "+frame_duration", AV_DICT_MULTIKEY); av_dict_set(&ost->encoder_opts, "flags", "+frame_duration", AV_DICT_MULTIKEY);
ret = hw_device_setup_for_encode(ost); ret = hw_device_setup_for_encode(ost, frame ? frame->hw_frames_ctx : NULL);
if (ret < 0) { if (ret < 0) {
av_log(ost, AV_LOG_ERROR, av_log(ost, AV_LOG_ERROR,
"Encoding hardware device setup failed: %s\n", av_err2str(ret)); "Encoding hardware device setup failed: %s\n", av_err2str(ret));