From dc947546076a148b1760244be8737c2aeca41dac Mon Sep 17 00:00:00 2001 From: pfeatherstone <45853521+pfeatherstone@users.noreply.github.com> Date: Tue, 21 Feb 2023 01:01:13 +0000 Subject: [PATCH] Fix for #2729 (#2731) * fixes #2729 * don't commit vscode stuff * Update ffmpeg_utils.h typo --------- Co-authored-by: pf --- .gitignore | 1 + dlib/media/ffmpeg_utils.h | 11 +++++++++-- examples/ffmpeg_video_decoding_ex.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 118d33efc..5ad181a5e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ docs/docs/git-logs.xml docs/docs/python/classes.txt docs/docs/python/functions.txt docs/docs/python/constants.txt +**/.vscode diff --git a/dlib/media/ffmpeg_utils.h b/dlib/media/ffmpeg_utils.h index 060729596..0c4f39f0a 100644 --- a/dlib/media/ffmpeg_utils.h +++ b/dlib/media/ffmpeg_utils.h @@ -802,7 +802,14 @@ namespace dlib f->format = h > 0 && w > 0 ? (int)pixfmt : (int)samplefmt; timestamp = timestamp_; - int ret = av_frame_get_buffer(f.get(), 0); //use default alignment, which is likely 32 + // The ffmpeg documentation recommends you always use align==0. + // However, in ffmpeg 3.2, there is a bug where if you do that, data buffers don't get allocated. + // So workaround is to manually set align==32 + // Not ideal, but i've checked the source code in ffmpeg 3.3, 4.4 and 5.0 libavutil/frame.c + // and in every case, if align==0, then align=32 + const int align = 32; + + const int ret = av_frame_get_buffer(f.get(), align); if (ret < 0) { f = nullptr; @@ -1135,7 +1142,7 @@ namespace dlib f.height(), 1); - DLIB_ASSERT(ret == expsize, "av_image_copy_to_buffer() error : " << details::get_av_error(ret)); + DLIB_ASSERT(ret == (int)expsize, "av_image_copy_to_buffer() error : " << details::get_av_error(ret)); (void)ret; } diff --git a/examples/ffmpeg_video_decoding_ex.cpp b/examples/ffmpeg_video_decoding_ex.cpp index dd5246232..9ba720e92 100644 --- a/examples/ffmpeg_video_decoding_ex.cpp +++ b/examples/ffmpeg_video_decoding_ex.cpp @@ -63,7 +63,7 @@ try } const std::string filepath = get_option(parser, "i", ""); - const std::string codec = get_option(parser, "codec", ""); + const std::string codec = get_option(parser, "codec", "h264"); image_window win;