mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-13 16:44:47 +08:00
feat(encoder): added auto selection of the most suitable output pix_fmt
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
@@ -5,19 +5,15 @@
|
||||
#include <string.h>
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/pixdesc.h>
|
||||
}
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "avutils.h"
|
||||
#include "conversions.h"
|
||||
|
||||
static enum AVPixelFormat get_encoder_default_pix_fmt(const AVCodec *encoder) {
|
||||
const enum AVPixelFormat *p = encoder->pix_fmts;
|
||||
if (!p) {
|
||||
spdlog::error("No pixel formats supported by encoder");
|
||||
return AV_PIX_FMT_NONE;
|
||||
}
|
||||
return *p;
|
||||
}
|
||||
|
||||
int init_encoder(
|
||||
AVBufferRef *hw_ctx,
|
||||
std::filesystem::path out_fpath,
|
||||
@@ -86,12 +82,12 @@ int init_encoder(
|
||||
// Use the specified pixel format
|
||||
codec_ctx->pix_fmt = encoder_config->pix_fmt;
|
||||
} else {
|
||||
// Fall back to the default pixel format
|
||||
codec_ctx->pix_fmt = get_encoder_default_pix_fmt(encoder);
|
||||
codec_ctx->pix_fmt = get_encoder_default_pix_fmt(encoder, dec_ctx->pix_fmt);
|
||||
if (codec_ctx->pix_fmt == AV_PIX_FMT_NONE) {
|
||||
spdlog::error("Could not get the default pixel format for the encoder");
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
spdlog::debug("Auto-selected pixel format: {}", av_get_pix_fmt_name(codec_ctx->pix_fmt));
|
||||
}
|
||||
|
||||
// Set the output video's time base
|
||||
|
||||
Reference in New Issue
Block a user