From e3fef8c990492d2d4c132b12a4a79392be5f1c2c Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 15 Jun 2014 05:29:05 +0200 Subject: [PATCH 1/6] AVIDump: cleanup --- Source/Core/VideoCommon/AVIDump.cpp | 160 ++++++++++++++-------------- Source/Core/VideoCommon/AVIDump.h | 22 ++-- 2 files changed, 92 insertions(+), 90 deletions(-) diff --git a/Source/Core/VideoCommon/AVIDump.cpp b/Source/Core/VideoCommon/AVIDump.cpp index 7cadd77f40..b53340f07d 100644 --- a/Source/Core/VideoCommon/AVIDump.cpp +++ b/Source/Core/VideoCommon/AVIDump.cpp @@ -215,14 +215,15 @@ extern "C" { #include } -AVFormatContext *s_FormatContext = nullptr; -AVStream *s_Stream = nullptr; -AVFrame *s_BGRFrame = nullptr, *s_YUVFrame = nullptr; -uint8_t *s_YUVBuffer = nullptr; -uint8_t *s_OutBuffer = nullptr; -int s_width; -int s_height; -int s_size; +static AVFormatContext* s_format_context = nullptr; +static AVStream* s_stream = nullptr; +static AVFrame* s_bgr_frame = nullptr; +static AVFrame* s_yuv_frame = nullptr; +static uint8_t* s_yuv_buffer = nullptr; +static uint8_t* s_out_buffer = nullptr; +static int s_width; +static int s_height; +static int s_size; static void InitAVCodec() { @@ -240,143 +241,144 @@ bool AVIDump::Start(int w, int h) s_height = h; InitAVCodec(); - return CreateFile(); + bool success = CreateFile(); + if (!success) + CloseFile(); + return success; } bool AVIDump::CreateFile() { - AVCodec *codec = nullptr; + AVCodec* codec = nullptr; - s_FormatContext = avformat_alloc_context(); - snprintf(s_FormatContext->filename, sizeof(s_FormatContext->filename), "%s", - (File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump0.avi").c_str()); - File::CreateFullPath(s_FormatContext->filename); + s_format_context = avformat_alloc_context(); + snprintf(s_format_context->filename, sizeof(s_format_context->filename), "%s", + (File::GetUserPath(D_DUMPFRAMES_IDX) + "framedump0.avi").c_str()); + File::CreateFullPath(s_format_context->filename); - if (!(s_FormatContext->oformat = av_guess_format("avi", nullptr, nullptr)) || - !(s_Stream = avformat_new_stream(s_FormatContext, codec))) + if (!(s_format_context->oformat = av_guess_format("avi", nullptr, nullptr)) || + !(s_stream = avformat_new_stream(s_format_context, codec))) { - CloseFile(); return false; } - s_Stream->codec->codec_id = - g_Config.bUseFFV1 ? CODEC_ID_FFV1 : s_FormatContext->oformat->video_codec; - s_Stream->codec->codec_type = AVMEDIA_TYPE_VIDEO; - s_Stream->codec->bit_rate = 400000; - s_Stream->codec->width = s_width; - s_Stream->codec->height = s_height; - s_Stream->codec->time_base = (AVRational){1, static_cast(VideoInterface::TargetRefreshRate)}; - s_Stream->codec->gop_size = 12; - s_Stream->codec->pix_fmt = g_Config.bUseFFV1 ? PIX_FMT_BGRA : PIX_FMT_YUV420P; + s_stream->codec->codec_id = g_Config.bUseFFV1 ? CODEC_ID_FFV1 : s_format_context->oformat->video_codec; + s_stream->codec->codec_type = AVMEDIA_TYPE_VIDEO; + s_stream->codec->bit_rate = 400000; + s_stream->codec->width = s_width; + s_stream->codec->height = s_height; + s_stream->codec->time_base = (AVRational){1, static_cast(VideoInterface::TargetRefreshRate)}; + s_stream->codec->gop_size = 12; + s_stream->codec->pix_fmt = g_Config.bUseFFV1 ? PIX_FMT_BGRA : PIX_FMT_YUV420P; - if (!(codec = avcodec_find_encoder(s_Stream->codec->codec_id)) || - (avcodec_open2(s_Stream->codec, codec, nullptr) < 0)) + if (!(codec = avcodec_find_encoder(s_stream->codec->codec_id)) || + (avcodec_open2(s_stream->codec, codec, nullptr) < 0)) { - CloseFile(); return false; } - s_BGRFrame = avcodec_alloc_frame(); - s_YUVFrame = avcodec_alloc_frame(); + s_bgr_frame = avcodec_alloc_frame(); + s_yuv_frame = avcodec_alloc_frame(); - s_size = avpicture_get_size(s_Stream->codec->pix_fmt, s_width, s_height); + s_size = avpicture_get_size(s_stream->codec->pix_fmt, s_width, s_height); - s_YUVBuffer = new uint8_t[s_size]; - avpicture_fill((AVPicture *)s_YUVFrame, s_YUVBuffer, s_Stream->codec->pix_fmt, s_width, s_height); + s_yuv_buffer = new uint8_t[s_size]; + avpicture_fill((AVPicture*)s_yuv_frame, s_yuv_buffer, s_stream->codec->pix_fmt, s_width, s_height); - s_OutBuffer = new uint8_t[s_size]; + s_out_buffer = new uint8_t[s_size]; - NOTICE_LOG(VIDEO, "Opening file %s for dumping", s_FormatContext->filename); - if (avio_open(&s_FormatContext->pb, s_FormatContext->filename, AVIO_FLAG_WRITE) < 0) + NOTICE_LOG(VIDEO, "Opening file %s for dumping", s_format_context->filename); + if (avio_open(&s_format_context->pb, s_format_context->filename, AVIO_FLAG_WRITE) < 0) { - WARN_LOG(VIDEO, "Could not open %s", s_FormatContext->filename); - CloseFile(); + WARN_LOG(VIDEO, "Could not open %s", s_format_context->filename); return false; } - avformat_write_header(s_FormatContext, nullptr); + avformat_write_header(s_format_context, nullptr); return true; } void AVIDump::AddFrame(const u8* data, int width, int height) { - avpicture_fill((AVPicture *)s_BGRFrame, const_cast(data), PIX_FMT_BGR24, width, height); + avpicture_fill((AVPicture*)s_bgr_frame, const_cast(data), PIX_FMT_BGR24, width, height); // Convert image from BGR24 to desired pixel format, and scale to initial // width and height - struct SwsContext *s_SwsContext; - if ((s_SwsContext = sws_getContext(width, height, PIX_FMT_BGR24, s_width, s_height, - s_Stream->codec->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr))) + struct SwsContext* s_sws_context; + if ((s_sws_context = sws_getContext(width, height, PIX_FMT_BGR24, s_width, s_height, + s_stream->codec->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr))) { - sws_scale(s_SwsContext, s_BGRFrame->data, s_BGRFrame->linesize, 0, - height, s_YUVFrame->data, s_YUVFrame->linesize); - sws_freeContext(s_SwsContext); + sws_scale(s_sws_context, s_bgr_frame->data, s_bgr_frame->linesize, 0, + height, s_yuv_frame->data, s_yuv_frame->linesize); + sws_freeContext(s_sws_context); } // Encode and write the image - int outsize = avcodec_encode_video(s_Stream->codec, s_OutBuffer, s_size, s_YUVFrame); + int outsize = avcodec_encode_video(s_stream->codec, s_out_buffer, s_size, s_yuv_frame); while (outsize > 0) { AVPacket pkt; av_init_packet(&pkt); - if (s_Stream->codec->coded_frame->pts != (unsigned int)AV_NOPTS_VALUE) - pkt.pts = av_rescale_q(s_Stream->codec->coded_frame->pts, - s_Stream->codec->time_base, s_Stream->time_base); - if (s_Stream->codec->coded_frame->key_frame) + if (s_stream->codec->coded_frame->pts != (unsigned int)AV_NOPTS_VALUE) + { + pkt.pts = av_rescale_q(s_stream->codec->coded_frame->pts, + s_stream->codec->time_base, s_stream->time_base); + } + if (s_stream->codec->coded_frame->key_frame) pkt.flags |= AV_PKT_FLAG_KEY; - pkt.stream_index = s_Stream->index; - pkt.data = s_OutBuffer; + pkt.stream_index = s_stream->index; + pkt.data = s_out_buffer; pkt.size = outsize; // Write the compressed frame in the media file - av_interleaved_write_frame(s_FormatContext, &pkt); + av_interleaved_write_frame(s_format_context, &pkt); // Encode delayed frames - outsize = avcodec_encode_video(s_Stream->codec, s_OutBuffer, s_size, nullptr); + outsize = avcodec_encode_video(s_stream->codec, s_out_buffer, s_size, nullptr); } } void AVIDump::Stop() { - av_write_trailer(s_FormatContext); + av_write_trailer(s_format_context); CloseFile(); NOTICE_LOG(VIDEO, "Stopping frame dump"); } void AVIDump::CloseFile() { - if (s_Stream) + if (s_stream) { - if (s_Stream->codec) - avcodec_close(s_Stream->codec); - av_free(s_Stream); - s_Stream = nullptr; + if (s_stream->codec) + avcodec_close(s_stream->codec); + av_free(s_stream); + s_stream = nullptr; } - if (s_YUVBuffer) - delete[] s_YUVBuffer; - s_YUVBuffer = nullptr; + if (s_yuv_buffer) + delete[] s_yuv_buffer; + s_yuv_buffer = nullptr; - if (s_OutBuffer) - delete[] s_OutBuffer; - s_OutBuffer = nullptr; + if (s_out_buffer) + delete[] s_out_buffer; + s_out_buffer = nullptr; - if (s_BGRFrame) - av_free(s_BGRFrame); - s_BGRFrame = nullptr; + if (s_bgr_frame) + av_free(s_bgr_frame); + s_bgr_frame = nullptr; - if (s_YUVFrame) - av_free(s_YUVFrame); - s_YUVFrame = nullptr; + if (s_yuv_frame) + av_free(s_yuv_frame); + s_yuv_frame = nullptr; - if (s_FormatContext) + if (s_format_context) { - if (s_FormatContext->pb) - avio_close(s_FormatContext->pb); - av_free(s_FormatContext); - s_FormatContext = nullptr; + if (s_format_context->pb) + avio_close(s_format_context->pb); + av_free(s_format_context); + s_format_context = nullptr; } } diff --git a/Source/Core/VideoCommon/AVIDump.h b/Source/Core/VideoCommon/AVIDump.h index c9aa2a4778..df17ae409f 100644 --- a/Source/Core/VideoCommon/AVIDump.h +++ b/Source/Core/VideoCommon/AVIDump.h @@ -14,20 +14,20 @@ class AVIDump { - private: - static bool CreateFile(); - static void CloseFile(); - static void SetBitmapFormat(); - static bool SetCompressionOptions(); - static bool SetVideoFormat(); +private: + static bool CreateFile(); + static void CloseFile(); + static void SetBitmapFormat(); + static bool SetCompressionOptions(); + static bool SetVideoFormat(); - public: +public: #ifdef _WIN32 - static bool Start(HWND hWnd, int w, int h); + static bool Start(HWND hWnd, int w, int h); #else - static bool Start(int w, int h); + static bool Start(int w, int h); #endif - static void AddFrame(const u8* data, int width, int height); + static void AddFrame(const u8* data, int width, int height); - static void Stop(); + static void Stop(); }; From c2c46d75738624b7afa4a522db8d2b029a95acb5 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 15 Jun 2014 05:16:58 +0200 Subject: [PATCH 2/6] AVIDump: update ffmpeg/libav API usage libav 10 was released on May 10th, 2014 and it drops support for some long-deprecated stuff like avcodec_encode_video(). --- Source/Core/VideoCommon/AVIDump.cpp | 93 +++++++++++++++-------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/Source/Core/VideoCommon/AVIDump.cpp b/Source/Core/VideoCommon/AVIDump.cpp index b53340f07d..a287056034 100644 --- a/Source/Core/VideoCommon/AVIDump.cpp +++ b/Source/Core/VideoCommon/AVIDump.cpp @@ -220,7 +220,7 @@ static AVStream* s_stream = nullptr; static AVFrame* s_bgr_frame = nullptr; static AVFrame* s_yuv_frame = nullptr; static uint8_t* s_yuv_buffer = nullptr; -static uint8_t* s_out_buffer = nullptr; +static SwsContext* s_sws_context = nullptr; static int s_width; static int s_height; static int s_size; @@ -262,14 +262,15 @@ bool AVIDump::CreateFile() return false; } - s_stream->codec->codec_id = g_Config.bUseFFV1 ? CODEC_ID_FFV1 : s_format_context->oformat->video_codec; + s_stream->codec->codec_id = g_Config.bUseFFV1 ? AV_CODEC_ID_FFV1 + : s_format_context->oformat->video_codec; s_stream->codec->codec_type = AVMEDIA_TYPE_VIDEO; s_stream->codec->bit_rate = 400000; s_stream->codec->width = s_width; s_stream->codec->height = s_height; s_stream->codec->time_base = (AVRational){1, static_cast(VideoInterface::TargetRefreshRate)}; s_stream->codec->gop_size = 12; - s_stream->codec->pix_fmt = g_Config.bUseFFV1 ? PIX_FMT_BGRA : PIX_FMT_YUV420P; + s_stream->codec->pix_fmt = g_Config.bUseFFV1 ? AV_PIX_FMT_BGRA : AV_PIX_FMT_YUV420P; if (!(codec = avcodec_find_encoder(s_stream->codec->codec_id)) || (avcodec_open2(s_stream->codec, codec, nullptr) < 0)) @@ -277,16 +278,14 @@ bool AVIDump::CreateFile() return false; } - s_bgr_frame = avcodec_alloc_frame(); - s_yuv_frame = avcodec_alloc_frame(); + s_bgr_frame = av_frame_alloc(); + s_yuv_frame = av_frame_alloc(); s_size = avpicture_get_size(s_stream->codec->pix_fmt, s_width, s_height); s_yuv_buffer = new uint8_t[s_size]; avpicture_fill((AVPicture*)s_yuv_frame, s_yuv_buffer, s_stream->codec->pix_fmt, s_width, s_height); - s_out_buffer = new uint8_t[s_size]; - NOTICE_LOG(VIDEO, "Opening file %s for dumping", s_format_context->filename); if (avio_open(&s_format_context->pb, s_format_context->filename, AVIO_FLAG_WRITE) < 0) { @@ -299,45 +298,52 @@ bool AVIDump::CreateFile() return true; } +static void PreparePacket(AVPacket* pkt) +{ + av_init_packet(pkt); + pkt->data = nullptr; + pkt->size = 0; + if (s_stream->codec->coded_frame->pts != AV_NOPTS_VALUE) + { + pkt->pts = av_rescale_q(s_stream->codec->coded_frame->pts, + s_stream->codec->time_base, s_stream->time_base); + } + if (s_stream->codec->coded_frame->key_frame) + pkt->flags |= AV_PKT_FLAG_KEY; + pkt->stream_index = s_stream->index; +} + void AVIDump::AddFrame(const u8* data, int width, int height) { - avpicture_fill((AVPicture*)s_bgr_frame, const_cast(data), PIX_FMT_BGR24, width, height); + avpicture_fill((AVPicture*)s_bgr_frame, const_cast(data), AV_PIX_FMT_BGR24, width, height); // Convert image from BGR24 to desired pixel format, and scale to initial // width and height - struct SwsContext* s_sws_context; - if ((s_sws_context = sws_getContext(width, height, PIX_FMT_BGR24, s_width, s_height, - s_stream->codec->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr))) + if ((s_sws_context = sws_getCachedContext(s_sws_context, + width, height, AV_PIX_FMT_BGR24, + s_width, s_height, s_stream->codec->pix_fmt, + SWS_BICUBIC, nullptr, nullptr, nullptr))) { sws_scale(s_sws_context, s_bgr_frame->data, s_bgr_frame->linesize, 0, height, s_yuv_frame->data, s_yuv_frame->linesize); - sws_freeContext(s_sws_context); } - // Encode and write the image - int outsize = avcodec_encode_video(s_stream->codec, s_out_buffer, s_size, s_yuv_frame); - while (outsize > 0) + // Encode and write the image. + AVPacket pkt; + PreparePacket(&pkt); + int got_packet; + int error = avcodec_encode_video2(s_stream->codec, &pkt, s_yuv_frame, &got_packet); + while (!error && got_packet) { - AVPacket pkt; - av_init_packet(&pkt); - - if (s_stream->codec->coded_frame->pts != (unsigned int)AV_NOPTS_VALUE) - { - pkt.pts = av_rescale_q(s_stream->codec->coded_frame->pts, - s_stream->codec->time_base, s_stream->time_base); - } - if (s_stream->codec->coded_frame->key_frame) - pkt.flags |= AV_PKT_FLAG_KEY; - pkt.stream_index = s_stream->index; - pkt.data = s_out_buffer; - pkt.size = outsize; - - // Write the compressed frame in the media file + // Write the compressed frame in the media file. av_interleaved_write_frame(s_format_context, &pkt); - // Encode delayed frames - outsize = avcodec_encode_video(s_stream->codec, s_out_buffer, s_size, nullptr); + // Handle delayed frames. + PreparePacket(&pkt); + error = avcodec_encode_video2(s_stream->codec, &pkt, nullptr, &got_packet); } + if (error) + ERROR_LOG(VIDEO, "Error while encoding video: %d", error); } void AVIDump::Stop() @@ -358,20 +364,13 @@ void AVIDump::CloseFile() } if (s_yuv_buffer) + { delete[] s_yuv_buffer; - s_yuv_buffer = nullptr; + s_yuv_buffer = nullptr; + } - if (s_out_buffer) - delete[] s_out_buffer; - s_out_buffer = nullptr; - - if (s_bgr_frame) - av_free(s_bgr_frame); - s_bgr_frame = nullptr; - - if (s_yuv_frame) - av_free(s_yuv_frame); - s_yuv_frame = nullptr; + av_frame_free(&s_bgr_frame); + av_frame_free(&s_yuv_frame); if (s_format_context) { @@ -380,6 +379,12 @@ void AVIDump::CloseFile() av_free(s_format_context); s_format_context = nullptr; } + + if (s_sws_context) + { + sws_freeContext(s_sws_context); + s_sws_context = nullptr; + } } #endif From 95eade2a47cfb186e6e5ede35965f1c271d8f1a2 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 15 Jun 2014 08:51:42 +0200 Subject: [PATCH 3/6] CMake: remove unused/duplicate definitions --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da36636395..072ad64f5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,10 +267,6 @@ if(APPLE) # page on x86_64 is 4GB in size. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-pagezero_size,0x1000") - if(NOT DISABLE_WX) - add_definitions(-DUSE_WX -DHAVE_WX) - set(USE_WX TRUE) - endif() find_library(APPKIT_LIBRARY AppKit) find_library(APPSERV_LIBRARY ApplicationServices) find_library(ATB_LIBRARY AudioToolbox) From 7e010023724ca4fad46b213faa818041a249af8d Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 15 Jun 2014 09:20:13 +0200 Subject: [PATCH 4/6] CMake: mention ffmpeg in libav messages We support both. --- CMakeTests/CheckLib.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeTests/CheckLib.cmake b/CMakeTests/CheckLib.cmake index 7b2525adae..5f02ffd721 100644 --- a/CMakeTests/CheckLib.cmake +++ b/CMakeTests/CheckLib.cmake @@ -58,14 +58,14 @@ macro(check_libav) pkg_check_modules(LIBAV libavcodec>=53.35.0 libavformat>=53.21.0 libswscale>=2.1.0 libavutil>=51.22.1) else() - message("pkg-config is required to check for libav") + message("pkg-config is required to check for libav/ffmpeg") endif() if(LIBAV_FOUND) - message("libav found, enabling AVI frame dumps") + message("libav/ffmpeg found, enabling AVI frame dumps") add_definitions(-DHAVE_LIBAV) include_directories(${LIBAV_INCLUDE_DIRS}) else() - message("libav not found, disabling AVI frame dumps") + message("libav/ffmpeg not found, disabling AVI frame dumps") endif() endmacro() From 02f470c7eb104605dd0bfcf743c75e4d9c81f097 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 15 Jun 2014 09:19:06 +0200 Subject: [PATCH 5/6] CMake: update min. libav/ffmpeg library versions --- CMakeTests/CheckLib.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeTests/CheckLib.cmake b/CMakeTests/CheckLib.cmake index 5f02ffd721..7d2a88ccd2 100644 --- a/CMakeTests/CheckLib.cmake +++ b/CMakeTests/CheckLib.cmake @@ -55,8 +55,8 @@ endmacro() macro(check_libav) if(PKG_CONFIG_FOUND) - pkg_check_modules(LIBAV libavcodec>=53.35.0 libavformat>=53.21.0 - libswscale>=2.1.0 libavutil>=51.22.1) + pkg_check_modules(LIBAV libavcodec>=55.52.102 libavformat>=55.33.100 + libswscale>=2.5.102 libavutil>=52.66.100) else() message("pkg-config is required to check for libav/ffmpeg") endif() From 6b3e6e6ffb1cb2af1fa5e7c5c9872faa37e81242 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Tue, 24 Jun 2014 04:12:15 +0200 Subject: [PATCH 6/6] AVIDump: rename frame variables --- Source/Core/VideoCommon/AVIDump.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/Core/VideoCommon/AVIDump.cpp b/Source/Core/VideoCommon/AVIDump.cpp index a287056034..c0e69fc6ab 100644 --- a/Source/Core/VideoCommon/AVIDump.cpp +++ b/Source/Core/VideoCommon/AVIDump.cpp @@ -217,8 +217,8 @@ extern "C" { static AVFormatContext* s_format_context = nullptr; static AVStream* s_stream = nullptr; -static AVFrame* s_bgr_frame = nullptr; -static AVFrame* s_yuv_frame = nullptr; +static AVFrame* s_src_frame = nullptr; +static AVFrame* s_scaled_frame = nullptr; static uint8_t* s_yuv_buffer = nullptr; static SwsContext* s_sws_context = nullptr; static int s_width; @@ -278,13 +278,13 @@ bool AVIDump::CreateFile() return false; } - s_bgr_frame = av_frame_alloc(); - s_yuv_frame = av_frame_alloc(); + s_src_frame = av_frame_alloc(); + s_scaled_frame = av_frame_alloc(); s_size = avpicture_get_size(s_stream->codec->pix_fmt, s_width, s_height); s_yuv_buffer = new uint8_t[s_size]; - avpicture_fill((AVPicture*)s_yuv_frame, s_yuv_buffer, s_stream->codec->pix_fmt, s_width, s_height); + avpicture_fill((AVPicture*)s_scaled_frame, s_yuv_buffer, s_stream->codec->pix_fmt, s_width, s_height); NOTICE_LOG(VIDEO, "Opening file %s for dumping", s_format_context->filename); if (avio_open(&s_format_context->pb, s_format_context->filename, AVIO_FLAG_WRITE) < 0) @@ -315,7 +315,7 @@ static void PreparePacket(AVPacket* pkt) void AVIDump::AddFrame(const u8* data, int width, int height) { - avpicture_fill((AVPicture*)s_bgr_frame, const_cast(data), AV_PIX_FMT_BGR24, width, height); + avpicture_fill((AVPicture*)s_src_frame, const_cast(data), AV_PIX_FMT_BGR24, width, height); // Convert image from BGR24 to desired pixel format, and scale to initial // width and height @@ -324,15 +324,15 @@ void AVIDump::AddFrame(const u8* data, int width, int height) s_width, s_height, s_stream->codec->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr))) { - sws_scale(s_sws_context, s_bgr_frame->data, s_bgr_frame->linesize, 0, - height, s_yuv_frame->data, s_yuv_frame->linesize); + sws_scale(s_sws_context, s_src_frame->data, s_src_frame->linesize, 0, + height, s_scaled_frame->data, s_scaled_frame->linesize); } // Encode and write the image. AVPacket pkt; PreparePacket(&pkt); int got_packet; - int error = avcodec_encode_video2(s_stream->codec, &pkt, s_yuv_frame, &got_packet); + int error = avcodec_encode_video2(s_stream->codec, &pkt, s_scaled_frame, &got_packet); while (!error && got_packet) { // Write the compressed frame in the media file. @@ -369,8 +369,8 @@ void AVIDump::CloseFile() s_yuv_buffer = nullptr; } - av_frame_free(&s_bgr_frame); - av_frame_free(&s_yuv_frame); + av_frame_free(&s_src_frame); + av_frame_free(&s_scaled_frame); if (s_format_context) {