Closed dwffls closed 8 months ago
It's obviously hard for me to debug without being on your system so I have to enlist you for debugging help. The error messages you post could come from libffmpeg not finding a good pixel format, so it would help to sprinkle some debug statements into the code section below.
Also, does vaapi encoding with straight ffmpeg work, i.e. can you do something like this (taken from here) on the command line?
ffmpeg -y -vaapi_device /dev/dri/renderD128 -i file_in.avi -vf 'format=nv12,hwupload' -c:v h264_vaapi file_out.mp4
Here the snippet of code (ffmpeg_encoder.cpp) that you need to modify for debugging:
if (usesHardwareFrames_) {
const auto fmts = utils::get_hwframe_transfer_formats(hw_frames_ref);
// new:
std::cout << "formats found: " << fmts.size() << std::endl;
frames_ctx->sw_format = utils::get_preferred_pixel_format("h264_vaapi", fmts);
std::cout << "format used: " << static_cast<int>(frames_ctx->sw_format) << std::endl;
if (pixFormat_ != AV_PIX_FMT_NONE) {
RCLCPP_INFO_STREAM(
logger_, "user overriding software pix fmt " << utils::pix(frames_ctx->sw_format));
RCLCPP_INFO_STREAM(logger_, "with " << utils::pix(pixFormat_));
frames_ctx->sw_format = pixFormat_; // override default at your own risk!
} else {
RCLCPP_INFO_STREAM(
logger_, "using software pixel format: " << utils::pix(frames_ctx->sw_format));
}
if (frames_ctx->sw_format == AV_PIX_FMT_NONE) {
av_buffer_unref(&hw_frames_ref);
throw(std::runtime_error("cannot find valid sw pixel format!"));
}
}
The ffmpeg example runs without any problem. Next to this, ive already tried to looking at/ changing the code snippet you provided. However without any luck. It appears as though net usesHardwareFrames_ bool is never set correctly.
I'll let you know if i find out anything more
@dwffls have you made any progress on this issue? If usesHardwareFrames_ is false, then that means something is going wrong in find_hw_config(). Can you put some debug printing in there to find out why usesHWFrames is not set correctly? It could be that either the device type does not match or config->methods does not have the right flags set.
closing for lack of activity. Not clear what the problem is.
When using the h264_vaapi encoder AVHWFrameContext gives the following error:
When using the default libx264 encoder everything works as expected.
VAAPI is correlty installed on my machine with the following vainfo output: