diff --git a/src/renderer.cpp b/src/renderer.cpp index 21c45cf..429f0a1 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -172,9 +172,7 @@ int Renderer::open() { av_codec_ctx_audio->sample_rate = 44100; } } - AVChannelLayout l_chlayout = AV_CHANNEL_LAYOUT_STEREO; - av_channel_layout_copy(&av_codec_ctx_audio->ch_layout, &(l_chlayout)); //&(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); - + av_channel_layout_copy(&av_codec_ctx_audio->ch_layout, &(chlayout_stereo)); } // Some formats want stream headers separated @@ -191,7 +189,7 @@ int Renderer::open() { // Opening the video encoder codec response = avcodec_open2(av_codec_ctx_video, av_codec_video, NULL); if (response < 0) { - UtilityFunctions::printerr("Couldn't open video codec!", av_err2str(response)); + UtilityFunctions::printerr("Couldn't open video codec!", get_av_error()); return -3; } @@ -232,7 +230,7 @@ int Renderer::open() { // Opening the audio encoder codec response = avcodec_open2(av_codec_ctx_audio, av_codec_audio, NULL); if (response < 0) { - UtilityFunctions::printerr("Couldn't open audio codec!", av_err2str(response)); + UtilityFunctions::printerr("Couldn't open audio codec!", get_av_error()); return -4; } @@ -270,7 +268,7 @@ int Renderer::open() { if (!(av_out_format->flags & AVFMT_NOFILE)) { response = avio_open(&av_format_ctx->pb, file_path.utf8(), AVIO_FLAG_WRITE); if (response < 0) { - UtilityFunctions::printerr("Couldn't open output file!", av_err2str(response)); + UtilityFunctions::printerr("Couldn't open output file!", get_av_error()); return -5; } } @@ -278,7 +276,7 @@ int Renderer::open() { // Write stream header - if any response = avformat_write_header(av_format_ctx, NULL); if (response < 0) { - UtilityFunctions::printerr("Error when writing header!", av_err2str(response)); + UtilityFunctions::printerr("Error when writing header!", get_av_error()); return -6; } @@ -309,7 +307,7 @@ int Renderer::send_frame(Ref a_frame_image) { // Adding frame response = avcodec_send_frame(av_codec_ctx_video, av_frame_video); if (response < 0) { - UtilityFunctions::printerr("Error sending video frame!", av_err2str(response)); + UtilityFunctions::printerr("Error sending video frame!", get_av_error()); return -1; } @@ -318,7 +316,7 @@ int Renderer::send_frame(Ref a_frame_image) { if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) break; else if (response < 0) { - UtilityFunctions::printerr("Error encoding video frame", av_err2str(response)); + UtilityFunctions::printerr("Error encoding video frame!", get_av_error()); return -1; } @@ -331,7 +329,7 @@ int Renderer::send_frame(Ref a_frame_image) { // Packet is now blank as function above takes ownership of it, so no unreferencing is necessary. // When using av_write_frame this would be needed. if (response < 0) { - UtilityFunctions::printerr("Error whilst writing output packet!", av_err2str(response)); + UtilityFunctions::printerr("Error whilst writing output packet!", get_av_error()); return -1; } } diff --git a/src/renderer.hpp b/src/renderer.hpp index e5079ce..15cff47 100644 --- a/src/renderer.hpp +++ b/src/renderer.hpp @@ -1,8 +1,8 @@ #pragma once +#include #include #include -#include #include extern "C" { @@ -35,6 +35,7 @@ class Renderer : public Resource { private: static const int byte_per_pixel = 4; + static constexpr AVChannelLayout chlayout_stereo = AV_CHANNEL_LAYOUT_STEREO; AVFormatContext *av_format_ctx = nullptr; const AVOutputFormat *av_out_format = nullptr; struct SwsContext *sws_ctx = nullptr; @@ -45,6 +46,7 @@ class Renderer : public Resource { AVStream *av_stream_video, *av_stream_audio; AVPacket *av_packet_video = nullptr, *av_packet_audio = nullptr; AVFrame *av_frame_video = nullptr, *av_frame_audio = nullptr; + char error_str[AV_ERROR_MAX_STRING_SIZE]; int i = 0, x = 0, y = 0, response = 0; /* Render requirements */ @@ -106,6 +108,8 @@ class Renderer : public Resource { inline void set_render_audio(bool a_value) { render_audio = a_value; } inline bool get_render_audio() { return render_audio; } + inline char *get_av_error() { return av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, response); } + bool ready_check(); int open();