encoder: Use ffmpeg::tools::get_error_description

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2019-11-11 21:15:56 +01:00
parent d233b52e1f
commit 05d8e74088
+26 -19
View File
@@ -557,10 +557,11 @@ void obsffmpeg::encoder_factory::get_properties(obs_properties_t* props, bool hw
obs_property_set_long_description(p, TRANSLATE(DESC(ST_FFMPEG_CUSTOMSETTINGS))); obs_property_set_long_description(p, TRANSLATE(DESC(ST_FFMPEG_CUSTOMSETTINGS)));
} }
if (!hw_encode) { if (!hw_encode) {
{ {
auto p = obs_properties_add_int(grp, ST_FFMPEG_GPU, TRANSLATE(ST_FFMPEG_GPU), 0, std::numeric_limits<uint8_t>::max(), 1); auto p = obs_properties_add_int(grp, ST_FFMPEG_GPU, TRANSLATE(ST_FFMPEG_GPU), 0,
obs_property_set_long_description(p, TRANSLATE(DESC(ST_FFMPEG_GPU))); std::numeric_limits<uint8_t>::max(), 1);
} obs_property_set_long_description(p, TRANSLATE(DESC(ST_FFMPEG_GPU)));
}
if (avcodec_ptr->pix_fmts) { if (avcodec_ptr->pix_fmts) {
auto p = obs_properties_add_list(grp, ST_FFMPEG_COLORFORMAT, auto p = obs_properties_add_list(grp, ST_FFMPEG_COLORFORMAT,
TRANSLATE(ST_FFMPEG_COLORFORMAT), OBS_COMBO_TYPE_LIST, TRANSLATE(ST_FFMPEG_COLORFORMAT), OBS_COMBO_TYPE_LIST,
@@ -839,7 +840,7 @@ obsffmpeg::encoder::encoder(obs_data_t* settings, obs_encoder_t* encoder, bool i
// Initialize Encoder // Initialize Encoder
auto gctx = obsffmpeg::obs_graphics(); auto gctx = obsffmpeg::obs_graphics();
int res = avcodec_open2(_context, _codec, NULL); int res = avcodec_open2(_context, _codec, NULL);
if (res < 0) { if (res < 0) {
std::stringstream sstr; std::stringstream sstr;
sstr << "Initializing encoder '" << _codec->name sstr << "Initializing encoder '" << _codec->name
@@ -885,7 +886,6 @@ void obsffmpeg::encoder::get_properties(obs_properties_t* props, bool hw_encode)
obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_THREADS), false); obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_THREADS), false);
obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_STANDARDCOMPLIANCE), false); obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_STANDARDCOMPLIANCE), false);
obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_GPU), false); obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_GPU), false);
} }
bool obsffmpeg::encoder::update(obs_data_t* settings) bool obsffmpeg::encoder::update(obs_data_t* settings)
@@ -939,8 +939,8 @@ bool obsffmpeg::encoder::update(obs_data_t* settings)
_context->keyint_min = _context->gop_size; _context->keyint_min = _context->gop_size;
} }
if (!_hwinst) if (!_hwinst)
av_opt_set_int(_context, "gpu", (int)obs_data_get_int(settings, ST_FFMPEG_GPU), AV_OPT_SEARCH_CHILDREN); av_opt_set_int(_context, "gpu", (int)obs_data_get_int(settings, ST_FFMPEG_GPU), AV_OPT_SEARCH_CHILDREN);
{ // FFmpeg Custom Options { // FFmpeg Custom Options
const char* opts = obs_data_get_string(settings, ST_FFMPEG_CUSTOMSETTINGS); const char* opts = obs_data_get_string(settings, ST_FFMPEG_CUSTOMSETTINGS);
@@ -1011,13 +1011,13 @@ bool obsffmpeg::encoder::update(obs_data_t* settings)
} else { } else {
value = std::string(&opts[p_value], &opts[p]); value = std::string(&opts[p_value], &opts[p]);
} }
int ret = 0; int res = av_opt_set(_context, key.c_str(), value.c_str(),
if ((ret = av_opt_set(_context, key.c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN);
AV_OPT_SEARCH_CHILDREN)) if (res < 0) {
< 0) { PLOG_WARNING(
char sterror[AV_ERROR_MAX_STRING_SIZE]; "Failed setting option '%s' to '%s' due to error: %s",
av_make_error_string(sterror, AV_ERROR_MAX_STRING_SIZE, ret); key.c_str(), value.c_str(),
PLOG_WARNING("Option '%s' could not be set to '%s'. (%s)", key.c_str(), value.c_str(), sterror); ffmpeg::tools::get_error_description(res));
} }
have_param = false; have_param = false;
have_key = false; have_key = false;
@@ -1176,10 +1176,14 @@ bool obsffmpeg::encoder::video_encode_texture(uint32_t handle, int64_t pts, uint
int obsffmpeg::encoder::receive_packet(bool* received_packet, struct encoder_packet* packet) int obsffmpeg::encoder::receive_packet(bool* received_packet, struct encoder_packet* packet)
{ {
auto gctx = obsffmpeg::obs_graphics(); int res = 0;
av_packet_unref(&_current_packet); av_packet_unref(&_current_packet);
int res = avcodec_receive_packet(_context, &_current_packet); {
auto gctx = obsffmpeg::obs_graphics();
res = avcodec_receive_packet(_context, &_current_packet);
}
if (res != 0) { if (res != 0) {
return res; return res;
} }
@@ -1241,8 +1245,11 @@ int obsffmpeg::encoder::receive_packet(bool* received_packet, struct encoder_pac
int obsffmpeg::encoder::send_frame(std::shared_ptr<AVFrame> const frame) int obsffmpeg::encoder::send_frame(std::shared_ptr<AVFrame> const frame)
{ {
auto gctx = obsffmpeg::obs_graphics(); int res = 0;
int res = avcodec_send_frame(_context, frame.get()); {
auto gctx = obsffmpeg::obs_graphics();
res = avcodec_send_frame(_context, frame.get());
}
if (res == 0) { if (res == 0) {
push_used_frame(frame); push_used_frame(frame);
} }