improve hwaccel support
This commit is contained in:
parent
272fdcec68
commit
f729034e9f
|
@ -91,7 +91,6 @@ static enum AVPixelFormat find_fmt_by_hw_type(const enum AVHWDeviceType type) {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
FfmpegCamera::FfmpegCamera(
|
FfmpegCamera::FfmpegCamera(
|
||||||
int p_id,
|
int p_id,
|
||||||
const std::string &p_path,
|
const std::string &p_path,
|
||||||
|
@ -425,17 +424,19 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
for ( int i = 0;; i++ ) {
|
for ( int i = 0;; i++ ) {
|
||||||
const AVCodecHWConfig *config = avcodec_get_hw_config(mVideoCodec, i);
|
const AVCodecHWConfig *config = avcodec_get_hw_config(mVideoCodec, i);
|
||||||
if ( !config ) {
|
if ( !config ) {
|
||||||
Debug(1, "Decoder %s does not support device type %s.",
|
Debug(1, "Decoder %s does not support config %d.",
|
||||||
mVideoCodec->name, av_hwdevice_get_type_name(type));
|
mVideoCodec->name, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)
|
if ( (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)
|
||||||
&& (config->device_type == type)
|
&& (config->device_type == type)
|
||||||
) {
|
) {
|
||||||
hw_pix_fmt = config->pix_fmt;
|
hw_pix_fmt = config->pix_fmt;
|
||||||
break;
|
Debug(1, "Decoder %s does support our type %s.",
|
||||||
|
mVideoCodec->name, av_hwdevice_get_type_name(type));
|
||||||
|
//break;
|
||||||
} else {
|
} else {
|
||||||
Debug(1, "decoder %s hwConfig doesn't match our type: %s != %s, pix_fmt %s.",
|
Debug(1, "Decoder %s hwConfig doesn't match our type: %s != %s, pix_fmt %s.",
|
||||||
mVideoCodec->name,
|
mVideoCodec->name,
|
||||||
av_hwdevice_get_type_name(type),
|
av_hwdevice_get_type_name(type),
|
||||||
av_hwdevice_get_type_name(config->device_type),
|
av_hwdevice_get_type_name(config->device_type),
|
||||||
|
@ -451,10 +452,18 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
hw_pix_fmt, av_get_pix_fmt_name(hw_pix_fmt));
|
hw_pix_fmt, av_get_pix_fmt_name(hw_pix_fmt));
|
||||||
|
|
||||||
ret = av_hwdevice_ctx_create(&hw_device_ctx, type,
|
ret = av_hwdevice_ctx_create(&hw_device_ctx, type,
|
||||||
(hwaccel_device != "" ? hwaccel_device.c_str(): nullptr), nullptr, 0);
|
(hwaccel_device != "" ? hwaccel_device.c_str() : nullptr), nullptr, 0);
|
||||||
if ( ret < 0 ) {
|
if ( ret < 0 ) {
|
||||||
Error("Failed to create hwaccel device. %s",av_make_error_string(ret).c_str());
|
Error("Failed to create hwaccel device. %s", av_make_error_string(ret).c_str());
|
||||||
hw_pix_fmt = AV_PIX_FMT_NONE;
|
if ( hwaccel_device != "" ) {
|
||||||
|
ret = av_hwdevice_ctx_create(&hw_device_ctx, type, nullptr, nullptr, 0);
|
||||||
|
if ( ret < 0 ) {
|
||||||
|
Error("Failed to create hwaccel device. %s", av_make_error_string(ret).c_str());
|
||||||
|
hw_pix_fmt = AV_PIX_FMT_NONE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hw_pix_fmt = AV_PIX_FMT_NONE;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Debug(1, "Created hwdevice for %s", hwaccel_device.c_str());
|
Debug(1, "Created hwdevice for %s", hwaccel_device.c_str());
|
||||||
mVideoCodecContext->get_format = get_hw_format;
|
mVideoCodecContext->get_format = get_hw_format;
|
||||||
|
|
Loading…
Reference in New Issue