
Recherche avancée
Médias (91)
-
#3 The Safest Place
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#4 Emo Creates
15 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#2 Typewriter Dance
15 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#1 The Wires
11 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
ED-ME-5 1-DVD
11 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Audio
-
Revolution of Open-source and film making towards open film making
6 octobre 2011, par
Mis à jour : Juillet 2013
Langue : English
Type : Texte
Autres articles (83)
-
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Encodage et transformation en formats lisibles sur Internet
10 avril 2011MediaSPIP transforme et ré-encode les documents mis en ligne afin de les rendre lisibles sur Internet et automatiquement utilisables sans intervention du créateur de contenu.
Les vidéos sont automatiquement encodées dans les formats supportés par HTML5 : MP4, Ogv et WebM. La version "MP4" est également utilisée pour le lecteur flash de secours nécessaire aux anciens navigateurs.
Les documents audios sont également ré-encodés dans les deux formats utilisables par HTML5 :MP3 et Ogg. La version "MP3" (...) -
Contribute to a better visual interface
13 avril 2011MediaSPIP is based on a system of themes and templates. Templates define the placement of information on the page, and can be adapted to a wide range of uses. Themes define the overall graphic appearance of the site.
Anyone can submit a new graphic theme or template and make it available to the MediaSPIP community.
Sur d’autres sites (11149)
-
swscale/range_convert : fix mpeg ranges in yuv range conversion for non-8-bit pixel...
18 septembre 2024, par Ramiro Pollaswscale/range_convert : fix mpeg ranges in yuv range conversion for non-8-bit pixel formats
There is an issue with the constants used in YUV to YUV range conversion,
where the upper bound is not respected when converting to mpeg range.With this commit, the constants are calculated at runtime, depending on
the bit depth. This approach also allows us to more easily understand how
the constants are derived.For bit depths <= 14, the number of fixed point bits has been set to 14
for all conversions, to simplify the code.
For bit depths > 14, the number of fixed points bits has been raised and
set to 18, to allow for the conversion to be accurate enough for the mpeg
range to be respected.The convert functions now take the conversion constants (coeff and offset)
as function arguments.
For bit depths <= 14, coeff is unsigned 16-bit and offset is 32-bit.
For bit depths > 14, coeff is unsigned 32-bit and offset is 64-bit.x86_64 :
chrRangeFromJpeg8_1920_c : 2127.4 2125.0 (1.00x)
chrRangeFromJpeg16_1920_c : 2325.2 2127.2 (1.09x)
chrRangeToJpeg8_1920_c : 3166.9 3168.7 (1.00x)
chrRangeToJpeg16_1920_c : 2152.4 3164.8 (0.68x)
lumRangeFromJpeg8_1920_c : 1263.0 1302.5 (0.97x)
lumRangeFromJpeg16_1920_c : 1080.5 1299.2 (0.83x)
lumRangeToJpeg8_1920_c : 1886.8 2112.2 (0.89x)
lumRangeToJpeg16_1920_c : 1077.0 1906.5 (0.56x)aarch64 A55 :
chrRangeFromJpeg8_1920_c : 28835.2 28835.6 (1.00x)
chrRangeFromJpeg16_1920_c : 28839.8 32680.8 (0.88x)
chrRangeToJpeg8_1920_c : 23074.7 23075.4 (1.00x)
chrRangeToJpeg16_1920_c : 17318.9 24996.0 (0.69x)
lumRangeFromJpeg8_1920_c : 15389.7 15384.5 (1.00x)
lumRangeFromJpeg16_1920_c : 15388.2 17306.7 (0.89x)
lumRangeToJpeg8_1920_c : 19227.8 19226.6 (1.00x)
lumRangeToJpeg16_1920_c : 15387.0 21146.3 (0.73x)aarch64 A76 :
chrRangeFromJpeg8_1920_c : 6324.4 6268.1 (1.01x)
chrRangeFromJpeg16_1920_c : 6339.9 11521.5 (0.55x)
chrRangeToJpeg8_1920_c : 9656.0 9612.8 (1.00x)
chrRangeToJpeg16_1920_c : 6340.4 11651.8 (0.54x)
lumRangeFromJpeg8_1920_c : 4422.0 4420.8 (1.00x)
lumRangeFromJpeg16_1920_c : 4420.9 5762.0 (0.77x)
lumRangeToJpeg8_1920_c : 5949.1 5977.5 (1.00x)
lumRangeToJpeg16_1920_c : 4446.8 5946.2 (0.75x)NOTE : all simd optimizations for range_convert have been disabled.
they will be re-enabled when they are fixed for each architecture.NOTE2 : the same issue still exists in rgb2yuv conversions, which is not
addressed in this commit.- [DH] libswscale/aarch64/swscale.c
- [DH] libswscale/hscale.c
- [DH] libswscale/swscale.c
- [DH] libswscale/swscale_internal.h
- [DH] libswscale/x86/swscale.c
- [DH] tests/checkasm/sw_range_convert.c
- [DH] tests/ref/fate/filter-alphaextract_alphamerge_rgb
- [DH] tests/ref/fate/filter-pixdesc-gray10be
- [DH] tests/ref/fate/filter-pixdesc-gray10le
- [DH] tests/ref/fate/filter-pixdesc-gray12be
- [DH] tests/ref/fate/filter-pixdesc-gray12le
- [DH] tests/ref/fate/filter-pixdesc-gray14be
- [DH] tests/ref/fate/filter-pixdesc-gray14le
- [DH] tests/ref/fate/filter-pixdesc-gray16be
- [DH] tests/ref/fate/filter-pixdesc-gray16le
- [DH] tests/ref/fate/filter-pixdesc-gray9be
- [DH] tests/ref/fate/filter-pixdesc-gray9le
- [DH] tests/ref/fate/filter-pixdesc-ya16be
- [DH] tests/ref/fate/filter-pixdesc-ya16le
- [DH] tests/ref/fate/filter-pixdesc-yuvj411p
- [DH] tests/ref/fate/filter-pixdesc-yuvj420p
- [DH] tests/ref/fate/filter-pixdesc-yuvj422p
- [DH] tests/ref/fate/filter-pixdesc-yuvj440p
- [DH] tests/ref/fate/filter-pixdesc-yuvj444p
- [DH] tests/ref/fate/filter-pixfmts-copy
- [DH] tests/ref/fate/filter-pixfmts-crop
- [DH] tests/ref/fate/filter-pixfmts-field
- [DH] tests/ref/fate/filter-pixfmts-fieldorder
- [DH] tests/ref/fate/filter-pixfmts-hflip
- [DH] tests/ref/fate/filter-pixfmts-il
- [DH] tests/ref/fate/filter-pixfmts-lut
- [DH] tests/ref/fate/filter-pixfmts-null
- [DH] tests/ref/fate/filter-pixfmts-pad
- [DH] tests/ref/fate/filter-pixfmts-pullup
- [DH] tests/ref/fate/filter-pixfmts-rotate
- [DH] tests/ref/fate/filter-pixfmts-scale
- [DH] tests/ref/fate/filter-pixfmts-swapuv
- [DH] tests/ref/fate/filter-pixfmts-tinterlace_cvlpf
- [DH] tests/ref/fate/filter-pixfmts-tinterlace_merge
- [DH] tests/ref/fate/filter-pixfmts-tinterlace_pad
- [DH] tests/ref/fate/filter-pixfmts-tinterlace_vlpf
- [DH] tests/ref/fate/filter-pixfmts-transpose
- [DH] tests/ref/fate/filter-pixfmts-vflip
- [DH] tests/ref/fate/fitsenc-gray
- [DH] tests/ref/fate/fitsenc-gray16be
- [DH] tests/ref/fate/gifenc-gray
- [DH] tests/ref/fate/idroq-video-encode
- [DH] tests/ref/fate/jpg-icc
- [DH] tests/ref/fate/sws-yuv-colorspace
- [DH] tests/ref/fate/sws-yuv-range
- [DH] tests/ref/fate/vvc-conformance-SCALING_A_1
- [DH] tests/ref/lavf/gray16be.fits
- [DH] tests/ref/lavf/gray16be.pam
- [DH] tests/ref/lavf/gray16be.png
- [DH] tests/ref/lavf/jpg
- [DH] tests/ref/lavf/smjpeg
- [DH] tests/ref/pixfmt/gbrp-gray
- [DH] tests/ref/pixfmt/gbrp-gray10be
- [DH] tests/ref/pixfmt/gbrp-gray10le
- [DH] tests/ref/pixfmt/gbrp-gray12be
- [DH] tests/ref/pixfmt/gbrp-gray12le
- [DH] tests/ref/pixfmt/gbrp-gray16be
- [DH] tests/ref/pixfmt/gbrp-gray16le
- [DH] tests/ref/pixfmt/gbrp-yuvj420p
- [DH] tests/ref/pixfmt/gbrp-yuvj422p
- [DH] tests/ref/pixfmt/gbrp-yuvj440p
- [DH] tests/ref/pixfmt/gbrp-yuvj444p
- [DH] tests/ref/pixfmt/gbrp10-gray
- [DH] tests/ref/pixfmt/gbrp10-gray10be
- [DH] tests/ref/pixfmt/gbrp10-gray10le
- [DH] tests/ref/pixfmt/gbrp10-gray12be
- [DH] tests/ref/pixfmt/gbrp10-gray12le
- [DH] tests/ref/pixfmt/gbrp10-gray16be
- [DH] tests/ref/pixfmt/gbrp10-gray16le
- [DH] tests/ref/pixfmt/gbrp10-yuvj420p
- [DH] tests/ref/pixfmt/gbrp10-yuvj422p
- [DH] tests/ref/pixfmt/gbrp10-yuvj440p
- [DH] tests/ref/pixfmt/gbrp10-yuvj444p
- [DH] tests/ref/pixfmt/gbrp12-gray
- [DH] tests/ref/pixfmt/gbrp12-gray10be
- [DH] tests/ref/pixfmt/gbrp12-gray10le
- [DH] tests/ref/pixfmt/gbrp12-gray12be
- [DH] tests/ref/pixfmt/gbrp12-gray12le
- [DH] tests/ref/pixfmt/gbrp12-gray16be
- [DH] tests/ref/pixfmt/gbrp12-gray16le
- [DH] tests/ref/pixfmt/gbrp12-yuvj420p
- [DH] tests/ref/pixfmt/gbrp12-yuvj422p
- [DH] tests/ref/pixfmt/gbrp12-yuvj440p
- [DH] tests/ref/pixfmt/gbrp12-yuvj444p
- [DH] tests/ref/pixfmt/gbrp16-gray16be
- [DH] tests/ref/pixfmt/gbrp16-gray16le
- [DH] tests/ref/pixfmt/rgb24-gray
- [DH] tests/ref/pixfmt/rgb24-gray10be
- [DH] tests/ref/pixfmt/rgb24-gray10le
- [DH] tests/ref/pixfmt/rgb24-gray12be
- [DH] tests/ref/pixfmt/rgb24-gray12le
- [DH] tests/ref/pixfmt/rgb24-gray16be
- [DH] tests/ref/pixfmt/rgb24-gray16le
- [DH] tests/ref/pixfmt/rgb24-yuvj420p
- [DH] tests/ref/pixfmt/rgb24-yuvj422p
- [DH] tests/ref/pixfmt/rgb24-yuvj440p
- [DH] tests/ref/pixfmt/rgb24-yuvj444p
- [DH] tests/ref/pixfmt/rgb48-gray
- [DH] tests/ref/pixfmt/rgb48-gray10be
- [DH] tests/ref/pixfmt/rgb48-gray10le
- [DH] tests/ref/pixfmt/rgb48-gray12be
- [DH] tests/ref/pixfmt/rgb48-gray12le
- [DH] tests/ref/pixfmt/rgb48-gray16be
- [DH] tests/ref/pixfmt/rgb48-gray16le
- [DH] tests/ref/pixfmt/rgb48-yuvj420p
- [DH] tests/ref/pixfmt/rgb48-yuvj422p
- [DH] tests/ref/pixfmt/rgb48-yuvj440p
- [DH] tests/ref/pixfmt/rgb48-yuvj444p
- [DH] tests/ref/pixfmt/yuv444p-gray10be
- [DH] tests/ref/pixfmt/yuv444p-gray10le
- [DH] tests/ref/pixfmt/yuv444p-gray12be
- [DH] tests/ref/pixfmt/yuv444p-gray12le
- [DH] tests/ref/pixfmt/yuv444p-gray16be
- [DH] tests/ref/pixfmt/yuv444p-gray16le
- [
-
Problems using FFmpeg / libavfilter for adding overlay to grabbed frames
21 novembre 2024, par MichaelOn Windows with latest FFmpeg / libav (full build, non-free) a C/C++ app reads YUV420P frames from a frame grabber card.


A bitmap (BGR24) overlay image from file should be drawn on every frame for the first 20 seconds via libavfilter. First, the BGR24 overlay image becomes converted via format filter to YUV420P. Then the YUV420P frame from frame grabber and the YUV420P overlay frame are pushed into the overlay filter.


FFmpeg / libavfilter does not report any errors or warnings in console / log. Trying to get the filtered frame out of the graph via
av_buffersink_get_frame
results in an EAGAIN return code.

The frames from the frame grabber card are fine, they could become encoded or written to a .yuv file. The overlay frame itself is fine too.


This is the complete private code (prototype - no style, memory leaks, ...) :


#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS

#include <cstdio>
#include <cstdint>
#include 

#include "../fgproto/include/SDL/SDL_video.h"
#include 

using namespace _DSHOWLIB_NAMESPACE;

#ifdef _WIN32
//Windows
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
#include "libavfilter/avfilter.h"
#include <libavutil></libavutil>log.h>
#include <libavutil></libavutil>mem.h>
#include "libavfilter/buffersink.h"
#include "libavfilter/buffersrc.h"
#include "libavutil/opt.h"
#include "libavutil/hwcontext_qsv.h"
#include "SDL/SDL.h"
};
#endif
#include <iostream>
#include <fstream>

void uSleep(double waitTimeInUs, LARGE_INTEGER frequency)
{
 LARGE_INTEGER startTime, currentTime;

 QueryPerformanceCounter(&startTime);

 if (waitTimeInUs > 16500.0)
 Sleep(1);

 do
 {
 YieldProcessor();
 //Sleep(0);
 QueryPerformanceCounter(&currentTime);
 }
 while (waitTimeInUs > (currentTime.QuadPart - startTime.QuadPart) * 1000000.0 / frequency.QuadPart);
}

void check_error(int ret)
{
 if (ret < 0)
 {
 char errbuf[128];
 int tmp = errno;
 av_strerror(ret, errbuf, sizeof(errbuf));
 std::cerr << "Error: " << errbuf << '\n';
 //exit(1);
 }
}

bool _isRunning = true;

void swap_uv_planes(AVFrame* frame)
{
 uint8_t* temp_plane = frame->data[1]; 
 frame->data[1] = frame->data[2]; 
 frame->data[2] = temp_plane; 
}

typedef struct
{
 const AVClass* avclass;
} MyFilterGraphContext;

static constexpr AVClass my_filter_graph_class = 
{
 .class_name = "MyFilterGraphContext",
 .item_name = av_default_item_name,
 .option = NULL,
 .version = LIBAVUTIL_VERSION_INT,
};

MyFilterGraphContext* init_log_context()
{
 MyFilterGraphContext* ctx = static_cast(av_mallocz(sizeof(*ctx)));

 if (!ctx)
 {
 av_log(nullptr, AV_LOG_ERROR, "Unable to allocate MyFilterGraphContext\n");
 return nullptr;
 }

 ctx->avclass = &my_filter_graph_class;
 return ctx;
}

int init_overlay_filter(AVFilterGraph** graph, AVFilterContext** src_ctx, AVFilterContext** overlay_src_ctx,
 AVFilterContext** sink_ctx)
{
 AVFilterGraph* filter_graph;
 AVFilterContext* buffersrc_ctx;
 AVFilterContext* overlay_buffersrc_ctx;
 AVFilterContext* buffersink_ctx;
 AVFilterContext* overlay_ctx;
 AVFilterContext* format_ctx;

 const AVFilter* buffersrc, * buffersink, * overlay_buffersrc, * overlay_filter, * format_filter;
 int ret;

 // Create the filter graph
 filter_graph = avfilter_graph_alloc();
 if (!filter_graph)
 {
 fprintf(stderr, "Unable to create filter graph.\n");
 return AVERROR(ENOMEM);
 }

 // Create buffer source filter for main video
 buffersrc = avfilter_get_by_name("buffer");
 if (!buffersrc)
 {
 fprintf(stderr, "Unable to find buffer filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Create buffer source filter for overlay image
 overlay_buffersrc = avfilter_get_by_name("buffer");
 if (!overlay_buffersrc)
 {
 fprintf(stderr, "Unable to find buffer filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Create buffer sink filter
 buffersink = avfilter_get_by_name("buffersink");
 if (!buffersink)
 {
 fprintf(stderr, "Unable to find buffersink filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Create overlay filter
 overlay_filter = avfilter_get_by_name("overlay");
 if (!overlay_filter)
 {
 fprintf(stderr, "Unable to find overlay filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Create format filter
 format_filter = avfilter_get_by_name("format");
 if (!format_filter)
 {
 fprintf(stderr, "Unable to find format filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Initialize the main video buffer source
 char args[512];

 // Initialize the overlay buffer source
 snprintf(args, sizeof(args), "video_size=165x165:pix_fmt=bgr24:time_base=1/25:pixel_aspect=1/1"); 

 ret = avfilter_graph_create_filter(&overlay_buffersrc_ctx, overlay_buffersrc, nullptr, args, nullptr,
 filter_graph);

 if (ret < 0)
 {
 fprintf(stderr, "Unable to create buffer source filter for overlay.\n");
 return ret;
 }

 snprintf(args, sizeof(args), "video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25:pixel_aspect=1/1");

 ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, nullptr, args, nullptr, filter_graph);

 if (ret < 0)
 {
 fprintf(stderr, "Unable to create buffer source filter for main video.\n");
 return ret;
 }

 // Initialize the format filter to convert overlay image to yuv420p
 snprintf(args, sizeof(args), "pix_fmts=yuv420p");

 ret = avfilter_graph_create_filter(&format_ctx, format_filter, nullptr, args, nullptr, filter_graph);

 if (ret < 0)
 {
 fprintf(stderr, "Unable to create format filter.\n");
 return ret;
 }

 // Initialize the overlay filter
 ret = avfilter_graph_create_filter(&overlay_ctx, overlay_filter, nullptr, "W-w:H-h:enable='between(t,0,20)':format=yuv420", nullptr, filter_graph);
 if (ret < 0)
 {
 fprintf(stderr, "Unable to create overlay filter.\n");
 return ret;
 }

 // Initialize the buffer sink
 ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, nullptr, nullptr, nullptr, filter_graph);
 if (ret < 0)
 {
 fprintf(stderr, "Unable to create buffer sink filter.\n");
 return ret;
 }

 // Connect the filters
 ret = avfilter_link(overlay_buffersrc_ctx, 0, format_ctx, 0);

 if (ret >= 0)
 {
 ret = avfilter_link(buffersrc_ctx, 0, overlay_ctx, 0);
 }
 else
 {
 fprintf(stderr, "Unable to configure filter graph.\n");
 return ret;
 }


 if (ret >= 0)
 {
 ret = avfilter_link(format_ctx, 0, overlay_ctx, 1);
 }
 else
 {
 fprintf(stderr, "Unable to configure filter graph.\n");
 return ret;
 }

 if (ret >= 0)
 {
 if ((ret = avfilter_link(overlay_ctx, 0, buffersink_ctx, 0)) < 0)
 {
 fprintf(stderr, "Unable to link filter graph.\n");
 return ret;
 }
 }
 else
 {
 fprintf(stderr, "Unable to configure filter graph.\n");
 return ret;
 }

 MyFilterGraphContext* log_ctx = init_log_context();

 // Configure the filter graph
 if ((ret = avfilter_graph_config(filter_graph, log_ctx)) < 0)
 {
 fprintf(stderr, "Unable to configure filter graph.\n");
 return ret;
 }

 *graph = filter_graph;
 *src_ctx = buffersrc_ctx;
 *overlay_src_ctx = overlay_buffersrc_ctx;
 *sink_ctx = buffersink_ctx;

 return 0;
}

int main(int argc, char* argv[])
{
 unsigned int videoIndex = 0;

 avdevice_register_all();

 av_log_set_level(AV_LOG_TRACE);

 const AVInputFormat* pFrameGrabberInputFormat = av_find_input_format("dshow");

 constexpr int frameGrabberPixelWidth = 1920;
 constexpr int frameGrabberPixelHeight = 1080;
 constexpr int frameGrabberFrameRate = 25;
 constexpr AVPixelFormat frameGrabberPixelFormat = AV_PIX_FMT_YUV420P;

 char shortStringBuffer[32];

 AVDictionary* pFrameGrabberOptions = nullptr;

 _snprintf_s(shortStringBuffer, sizeof(shortStringBuffer), "%dx%d", frameGrabberPixelWidth, frameGrabberPixelHeight);
 av_dict_set(&pFrameGrabberOptions, "video_size", shortStringBuffer, 0);

 _snprintf_s(shortStringBuffer, sizeof(shortStringBuffer), "%d", frameGrabberFrameRate);

 av_dict_set(&pFrameGrabberOptions, "framerate", shortStringBuffer, 0);
 av_dict_set(&pFrameGrabberOptions, "pixel_format", "yuv420p", 0);
 av_dict_set(&pFrameGrabberOptions, "rtbufsize", "128M", 0);

 AVFormatContext* pFrameGrabberFormatContext = avformat_alloc_context();

 pFrameGrabberFormatContext->flags = AVFMT_FLAG_NOBUFFER | AVFMT_FLAG_FLUSH_PACKETS;

 if (avformat_open_input(&pFrameGrabberFormatContext, "video=MZ0380 PCI, Analog 01 Capture",
 pFrameGrabberInputFormat, &pFrameGrabberOptions) != 0)
 {
 std::cerr << "Couldn't open input stream." << '\n';
 return -1;
 }

 if (avformat_find_stream_info(pFrameGrabberFormatContext, nullptr) < 0)
 {
 std::cerr << "Couldn't find stream information." << '\n';
 return -1;
 }

 bool foundVideoStream = false;

 for (unsigned int loop_videoIndex = 0; loop_videoIndex < pFrameGrabberFormatContext->nb_streams; loop_videoIndex++)
 {
 if (pFrameGrabberFormatContext->streams[loop_videoIndex]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 {
 videoIndex = loop_videoIndex;
 foundVideoStream = true;
 break;
 }
 }

 if (!foundVideoStream)
 {
 std::cerr << "Couldn't find a video stream." << '\n';
 return -1;
 }

 const AVCodec* pFrameGrabberCodec = avcodec_find_decoder(
 pFrameGrabberFormatContext->streams[videoIndex]->codecpar->codec_id);

 AVCodecContext* pFrameGrabberCodecContext = avcodec_alloc_context3(pFrameGrabberCodec);

 if (pFrameGrabberCodec == nullptr)
 {
 std::cerr << "Codec not found." << '\n';
 return -1;
 }

 pFrameGrabberCodecContext->pix_fmt = frameGrabberPixelFormat;
 pFrameGrabberCodecContext->width = frameGrabberPixelWidth;
 pFrameGrabberCodecContext->height = frameGrabberPixelHeight;

 int ret = avcodec_open2(pFrameGrabberCodecContext, pFrameGrabberCodec, nullptr);

 if (ret < 0)
 {
 std::cerr << "Could not open pVideoCodec." << '\n';
 return -1;
 }

 const char* outputFilePath = "c:\\temp\\output.mp4";
 constexpr int outputWidth = frameGrabberPixelWidth;
 constexpr int outputHeight = frameGrabberPixelHeight;
 constexpr int outputFrameRate = frameGrabberFrameRate;

 SwsContext* img_convert_ctx = sws_getContext(frameGrabberPixelWidth, frameGrabberPixelHeight,
 frameGrabberPixelFormat, outputWidth, outputHeight, AV_PIX_FMT_NV12,
 SWS_BICUBIC, nullptr, nullptr, nullptr);

 constexpr double frameTimeinUs = 1000000.0 / frameGrabberFrameRate;

 LARGE_INTEGER frequency;
 LARGE_INTEGER lastTime, currentTime;

 QueryPerformanceFrequency(&frequency);
 QueryPerformanceCounter(&lastTime);

 //SDL----------------------------

 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS))
 {
 printf("Could not initialize SDL - %s\n", SDL_GetError());
 return -1;
 }

 SDL_Window* screen = SDL_CreateWindow("3P FrameGrabber SuperApp", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
 frameGrabberPixelWidth, frameGrabberPixelHeight,
 SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);

 if (!screen)
 {
 printf("SDL: could not set video mode - exiting:%s\n", SDL_GetError());
 return -1;
 }

 SDL_Renderer* renderer = SDL_CreateRenderer(screen, -1, 0);

 if (!renderer)
 {
 printf("SDL: could not create renderer - exiting:%s\n", SDL_GetError());
 return -1;
 }

 SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
 frameGrabberPixelWidth, frameGrabberPixelHeight);

 if (!texture)
 {
 printf("SDL: could not create texture - exiting:%s\n", SDL_GetError());
 return -1;
 }

 SDL_Event event;

 //SDL End------------------------

 const AVCodec* pVideoCodec = avcodec_find_encoder_by_name("h264_qsv");

 if (!pVideoCodec)
 {
 std::cerr << "Codec not found" << '\n';
 return 1;
 }

 AVCodecContext* pVideoCodecContext = avcodec_alloc_context3(pVideoCodec);

 if (!pVideoCodecContext)
 {
 std::cerr << "Could not allocate video pVideoCodec context" << '\n';
 return 1;
 }

 AVBufferRef* pHardwareDeviceContextRef = nullptr;

 ret = av_hwdevice_ctx_create(&pHardwareDeviceContextRef, AV_HWDEVICE_TYPE_QSV,
 "PCI\\VEN_8086&DEV_5912&SUBSYS_310217AA&REV_04\\3&11583659&0&10", nullptr, 0);
 check_error(ret);

 pVideoCodecContext->bit_rate = static_cast(outputWidth * outputHeight) * 2;
 pVideoCodecContext->width = outputWidth;
 pVideoCodecContext->height = outputHeight;
 pVideoCodecContext->framerate = {outputFrameRate, 1};
 pVideoCodecContext->time_base = {1, outputFrameRate};
 pVideoCodecContext->pix_fmt = AV_PIX_FMT_QSV;
 pVideoCodecContext->max_b_frames = 0;

 AVBufferRef* pHardwareFramesContextRef = av_hwframe_ctx_alloc(pHardwareDeviceContextRef);

 AVHWFramesContext* pHardwareFramesContext = reinterpret_cast(pHardwareFramesContextRef->data);

 pHardwareFramesContext->format = AV_PIX_FMT_QSV;
 pHardwareFramesContext->sw_format = AV_PIX_FMT_NV12;
 pHardwareFramesContext->width = outputWidth;
 pHardwareFramesContext->height = outputHeight;
 pHardwareFramesContext->initial_pool_size = 20;

 ret = av_hwframe_ctx_init(pHardwareFramesContextRef);
 check_error(ret);

 pVideoCodecContext->hw_device_ctx = nullptr;
 pVideoCodecContext->hw_frames_ctx = av_buffer_ref(pHardwareFramesContextRef);

 ret = avcodec_open2(pVideoCodecContext, pVideoCodec, nullptr); //&pVideoOptionsDict);
 check_error(ret);

 AVFormatContext* pVideoFormatContext = nullptr;

 avformat_alloc_output_context2(&pVideoFormatContext, nullptr, nullptr, outputFilePath);

 if (!pVideoFormatContext)
 {
 std::cerr << "Could not create output context" << '\n';
 return 1;
 }

 const AVOutputFormat* pVideoOutputFormat = pVideoFormatContext->oformat;

 if (pVideoFormatContext->oformat->flags & AVFMT_GLOBALHEADER)
 {
 pVideoCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 }

 const AVStream* pVideoStream = avformat_new_stream(pVideoFormatContext, pVideoCodec);

 if (!pVideoStream)
 {
 std::cerr << "Could not allocate stream" << '\n';
 return 1;
 }

 ret = avcodec_parameters_from_context(pVideoStream->codecpar, pVideoCodecContext);

 check_error(ret);

 if (!(pVideoOutputFormat->flags & AVFMT_NOFILE))
 {
 ret = avio_open(&pVideoFormatContext->pb, outputFilePath, AVIO_FLAG_WRITE);
 check_error(ret);
 }

 ret = avformat_write_header(pVideoFormatContext, nullptr);

 check_error(ret);

 AVFrame* pHardwareFrame = av_frame_alloc();

 if (av_hwframe_get_buffer(pVideoCodecContext->hw_frames_ctx, pHardwareFrame, 0) < 0)
 {
 std::cerr << "Error allocating a hw frame" << '\n';
 return -1;
 }

 AVFrame* pFrameGrabberFrame = av_frame_alloc();
 AVPacket* pFrameGrabberPacket = av_packet_alloc();

 AVPacket* pVideoPacket = av_packet_alloc();
 AVFrame* pVideoFrame = av_frame_alloc();

 AVFrame* pSwappedFrame = av_frame_alloc();
 av_frame_get_buffer(pSwappedFrame, 32);

 INT64 frameCount = 0;

 pFrameGrabberCodecContext->time_base = {1, frameGrabberFrameRate};

 AVFilterContext* buffersrc_ctx = nullptr;
 AVFilterContext* buffersink_ctx = nullptr;
 AVFilterContext* overlay_src_ctx = nullptr;
 AVFilterGraph* filter_graph = nullptr;

 if ((ret = init_overlay_filter(&filter_graph, &buffersrc_ctx, &overlay_src_ctx, &buffersink_ctx)) < 0)
 {
 return ret;
 }

 // Load overlay image
 AVFormatContext* overlay_fmt_ctx = nullptr;
 AVCodecContext* overlay_codec_ctx = nullptr;
 const AVCodec* overlay_codec = nullptr;
 AVFrame* overlay_frame = nullptr;
 AVDictionary* overlay_options = nullptr;

 const char* overlay_image_filename = "c:\\temp\\overlay.bmp";

 av_dict_set(&overlay_options, "video_size", "165x165", 0);
 av_dict_set(&overlay_options, "pixel_format", "bgr24", 0);

 if ((ret = avformat_open_input(&overlay_fmt_ctx, overlay_image_filename, nullptr, &overlay_options)) < 0)
 {
 return ret;
 }

 if ((ret = avformat_find_stream_info(overlay_fmt_ctx, nullptr)) < 0)
 {
 return ret;
 }

 int overlay_video_stream_index = -1;

 for (int i = 0; i < overlay_fmt_ctx->nb_streams; i++)
 {
 if (overlay_fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 {
 overlay_video_stream_index = i;
 break;
 }
 }

 if (overlay_video_stream_index == -1)
 {
 return -1;
 }

 overlay_codec = avcodec_find_decoder(overlay_fmt_ctx->streams[overlay_video_stream_index]->codecpar->codec_id);

 if (!overlay_codec)
 {
 fprintf(stderr, "Overlay codec not found.\n");
 return -1;
 }

 overlay_codec_ctx = avcodec_alloc_context3(overlay_codec);

 if (!overlay_codec_ctx)
 {
 fprintf(stderr, "Could not allocate overlay codec context.\n");
 return AVERROR(ENOMEM);
 }

 avcodec_parameters_to_context(overlay_codec_ctx, overlay_fmt_ctx->streams[overlay_video_stream_index]->codecpar);

 if ((ret = avcodec_open2(overlay_codec_ctx, overlay_codec, nullptr)) < 0)
 {
 return ret;
 }

 overlay_frame = av_frame_alloc();

 if (!overlay_frame)
 {
 fprintf(stderr, "Could not allocate overlay frame.\n");
 return AVERROR(ENOMEM);
 }

 AVPacket* overlay_packet = av_packet_alloc();

 // Read frames from the file
 while (av_read_frame(overlay_fmt_ctx, overlay_packet) >= 0)
 {
 if (overlay_packet->stream_index == overlay_video_stream_index)
 {
 ret = avcodec_send_packet(overlay_codec_ctx, overlay_packet);

 if (ret < 0)
 {
 break;
 }

 ret = avcodec_receive_frame(overlay_codec_ctx, overlay_frame);
 if (ret >= 0)
 {
 
 break; // We only need the first frame for the overlay
 }

 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 {
 continue;
 }

 break;
 }

 av_packet_unref(overlay_packet);
 }

 av_packet_unref(overlay_packet);

 while (_isRunning)
 {
 while (SDL_PollEvent(&event) != 0)
 {
 switch (event.type)
 {
 case SDL_QUIT:
 _isRunning = false;
 break;
 case SDL_KEYDOWN:
 if (event.key.keysym.sym == SDLK_ESCAPE)
 _isRunning = false;
 break;
 default: ;
 }
 }

 if (av_read_frame(pFrameGrabberFormatContext, pFrameGrabberPacket) == 0)
 {
 if (pFrameGrabberPacket->stream_index == videoIndex)
 {
 ret = avcodec_send_packet(pFrameGrabberCodecContext, pFrameGrabberPacket);

 if (ret < 0)
 {
 std::cerr << "Error sending a packet for decoding!" << '\n';
 return -1;
 }

 ret = avcodec_receive_frame(pFrameGrabberCodecContext, pFrameGrabberFrame);

 if (ret != 0)
 {
 std::cerr << "Receiving frame failed!" << '\n';
 return -1;
 }

 if (ret == AVERROR(EAGAIN) || ret == AVERROR(AVERROR_EOF))
 {
 std::cout << "End of stream detected. Exiting now." << '\n';
 return 0;
 }

 if (ret != 0)
 {
 std::cerr << "Decode Error!" << '\n';
 return -1;
 }

 // Feed the frame into the filter graph
 if (av_buffersrc_add_frame_flags(buffersrc_ctx, pFrameGrabberFrame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0)
 {
 fprintf(stderr, "Error while feeding the filtergraph\n");
 break;
 }

 // Push the overlay frame to the overlay_src_ctx
 ret = av_buffersrc_add_frame_flags(overlay_src_ctx, overlay_frame, AV_BUFFERSRC_FLAG_KEEP_REF);
 if (ret < 0)
 {
 fprintf(stderr, "Error while feeding the filtergraph\n");
 break;
 } 

 // Pull filtered frame from the filter graph
 AVFrame* filtered_frame = av_frame_alloc();

 ret = av_buffersink_get_frame(buffersink_ctx, filtered_frame);

 if (ret < 0)
 {
 check_error(ret);
 }

 QueryPerformanceCounter(&currentTime);

 double elapsedTime = (currentTime.QuadPart - lastTime.QuadPart) * 1000000.0 / frequency.QuadPart;

 if (elapsedTime > 0.0 && elapsedTime < frameTimeinUs)
 {
 uSleep(frameTimeinUs - elapsedTime, frequency);
 }

 SDL_UpdateTexture(texture, nullptr, filtered_frame->data[0], filtered_frame->linesize[0]);
 SDL_RenderClear(renderer);
 SDL_RenderCopy(renderer, texture, nullptr, nullptr);
 SDL_RenderPresent(renderer);

 QueryPerformanceCounter(&lastTime);

 swap_uv_planes(filtered_frame);

 ret = sws_scale_frame(img_convert_ctx, pVideoFrame, filtered_frame);

 if (ret < 0)
 {
 std::cerr << "Scaling frame for Intel QS Encoder did fail!" << '\n';
 return -1;
 }

 if (av_hwframe_transfer_data(pHardwareFrame, pVideoFrame, 0) < 0)
 {
 std::cerr << "Error transferring frame data to hw frame!" << '\n';
 return -1;
 }

 pHardwareFrame->pts = frameCount++;

 ret = avcodec_send_frame(pVideoCodecContext, pHardwareFrame);

 if (ret < 0)
 {
 std::cerr << "Error sending a frame for encoding" << '\n';
 check_error(ret);
 }

 av_packet_unref(pVideoPacket);

 while (ret >= 0)
 {
 ret = avcodec_receive_packet(pVideoCodecContext, pVideoPacket);

 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 {
 break;
 }

 if (ret < 0)
 {
 std::cerr << "Error during encoding" << '\n';
 return 1;
 }

 av_packet_rescale_ts(pVideoPacket, pVideoCodecContext->time_base, pVideoStream->time_base);

 pVideoPacket->stream_index = pVideoStream->index;

 ret = av_interleaved_write_frame(pVideoFormatContext, pVideoPacket);

 check_error(ret);

 av_packet_unref(pVideoPacket);
 }

 av_packet_unref(pFrameGrabberPacket);
 av_frame_free(&filtered_frame);
 }
 }
 }

 av_write_trailer(pVideoFormatContext);
 av_buffer_unref(&pHardwareDeviceContextRef);
 avcodec_free_context(&pVideoCodecContext);
 avio_closep(&pVideoFormatContext->pb);
 avformat_free_context(pVideoFormatContext);
 av_packet_free(&pVideoPacket);

 avcodec_free_context(&pFrameGrabberCodecContext);
 av_frame_free(&pFrameGrabberFrame);
 av_packet_free(&pFrameGrabberPacket);
 avformat_close_input(&pFrameGrabberFormatContext);

 return 0;
}

</fstream></iostream></cstdint></cstdio>


The console / log output running the code :


[in @ 00000288ee494f40] Setting 'video_size' to value '1920x1080'
[in @ 00000288ee494f40] Setting 'pix_fmt' to value 'yuv420p'
[in @ 00000288ee494f40] Setting 'time_base' to value '1/25'
[in @ 00000288ee494f40] Setting 'pixel_aspect' to value '1/1'
[in @ 00000288ee494f40] w:1920 h:1080 pixfmt:yuv420p tb:1/25 fr:0/1 sar:1/1 csp:unknown range:unknown
[overlay_in @ 00000288ff1013c0] Setting 'video_size' to value '165x165'
[overlay_in @ 00000288ff1013c0] Setting 'pix_fmt' to value 'bgr24'
[overlay_in @ 00000288ff1013c0] Setting 'time_base' to value '1/25'
[overlay_in @ 00000288ff1013c0] Setting 'pixel_aspect' to value '1/1'
[overlay_in @ 00000288ff1013c0] w:165 h:165 pixfmt:bgr24 tb:1/25 fr:0/1 sar:1/1 csp:unknown range:unknown
[format @ 00000288ff1015c0] Setting 'pix_fmts' to value 'yuv420p'
[overlay @ 00000288ff101880] Setting 'x' to value 'W-w'
[overlay @ 00000288ff101880] Setting 'y' to value 'H-h'
[overlay @ 00000288ff101880] Setting 'enable' to value 'between(t,0,20)'
[overlay @ 00000288ff101880] Setting 'format' to value 'yuv420'
[auto_scale_0 @ 00000288ff101ec0] w:iw h:ih flags:'' interl:0
[format @ 00000288ff1015c0] auto-inserting filter 'auto_scale_0' between the filter 'overlay_in' and the filter 'format'
[auto_scale_1 @ 00000288ee4a4cc0] w:iw h:ih flags:'' interl:0
[overlay @ 00000288ff101880] auto-inserting filter 'auto_scale_1' between the filter 'format' and the filter 'overlay'
[AVFilterGraph @ 00000288ee495c80] query_formats: 5 queried, 6 merged, 6 already done, 0 delayed
[auto_scale_0 @ 00000288ff101ec0] w:165 h:165 fmt:bgr24 csp:gbr range:pc sar:1/1 -> w:165 h:165 fmt:yuv420p csp:unknown range:unknown sar:1/1 flags:0x00000004
[auto_scale_1 @ 00000288ee4a4cc0] w:165 h:165 fmt:yuv420p csp:unknown range:unknown sar:1/1 -> w:165 h:165 fmt:yuva420p csp:unknown range:unknown sar:1/1 flags:0x00000004
[overlay @ 00000288ff101880] main w:1920 h:1080 fmt:yuv420p overlay w:165 h:165 fmt:yuva420p
[overlay @ 00000288ff101880] [framesync @ 00000288ff1019a8] Selected 1/25 time base
[overlay @ 00000288ff101880] [framesync @ 00000288ff1019a8] Sync level 2



I tried to change the index / order of how the two different frames become pushed into the filter graph. Once I got a frame out of the graph but with the dimensions of the overlay image, not with the dimensions of the grabbed frame from the grabber card. So I suppose I am doing something wrong building up the filter graph.


To verify that the FFmpeg build contains all necessary modules I ran that procedure via FFmpeg executable in console and it worked and the result was as expected.


The command-line producing the expected output is following :


ffmpeg -f dshow -i video="MZ0380 PCI, Analog 01 Capture" -video_size 1920x1080 -framerate 25 -pixel_format yuv420p -loglevel debug -i "C:\temp\overlay.bmp" -filter_complex "[0:v][1:v] overlay=W-w:H-h:enable='between(t,0,20)'" -pix_fmt yuv420p -c:a copy output.mp4



-
Problems using libavfilter for adding overlay to frames
12 novembre 2024, par Michael WernerOn Windows 11 OS with latest libav (full build) a C/C++ app reads YUV420P frames from a frame grabber card.


I want to draw a bitmap (BGR24) overlay image from file on every frame via libavfilter. First I convert the BGR24 overlay image via format filter to YUV420P. Then I feed the YUV420P frame from frame grabber and the YUV420P overlay into the overlay filter.


Everything seems to be fine but when I try to get the frame out of the filter graph I always get an "Resource is temporary not available" (EAGAIN) return code, independent on how many frames I put into the graph.


The frames from the frame grabber card are fine, I could encode them or write them to a .yuv file. The overlay frame looks fine too.


My current initialization code looks like below. It does not report any errors or warnings but when I try to get the filtered frame out of the graph via
av_buffersink_get_frame
I always get anEAGAIN
return code.

Here is my current initialization code :


int init_overlay_filter(AVFilterGraph** graph, AVFilterContext** src_ctx, AVFilterContext** overlay_src_ctx,
 AVFilterContext** sink_ctx)
{
 AVFilterGraph* filter_graph;
 AVFilterContext* buffersrc_ctx;
 AVFilterContext* overlay_buffersrc_ctx;
 AVFilterContext* buffersink_ctx;
 AVFilterContext* overlay_ctx;
 AVFilterContext* format_ctx;
 const AVFilter *buffersrc, *buffersink, *overlay_buffersrc, *overlay_filter, *format_filter;
 int ret;

 // Create the filter graph
 filter_graph = avfilter_graph_alloc();
 if (!filter_graph)
 {
 fprintf(stderr, "Unable to create filter graph.\n");
 return AVERROR(ENOMEM);
 }

 // Create buffer source filter for main video
 buffersrc = avfilter_get_by_name("buffer");
 if (!buffersrc)
 {
 fprintf(stderr, "Unable to find buffer filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Create buffer source filter for overlay image
 overlay_buffersrc = avfilter_get_by_name("buffer");
 if (!overlay_buffersrc)
 {
 fprintf(stderr, "Unable to find buffer filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Create buffer sink filter
 buffersink = avfilter_get_by_name("buffersink");
 if (!buffersink)
 {
 fprintf(stderr, "Unable to find buffersink filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Create overlay filter
 overlay_filter = avfilter_get_by_name("overlay");
 if (!overlay_filter)
 {
 fprintf(stderr, "Unable to find overlay filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Create format filter
 format_filter = avfilter_get_by_name("format");
 if (!format_filter) 
 {
 fprintf(stderr, "Unable to find format filter.\n");
 return AVERROR_FILTER_NOT_FOUND;
 }

 // Initialize the main video buffer source
 char args[512];
 snprintf(args, sizeof(args),
 "video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25:pixel_aspect=1/1");
 ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, filter_graph);
 if (ret < 0)
 {
 fprintf(stderr, "Unable to create buffer source filter for main video.\n");
 return ret;
 }

 // Initialize the overlay buffer source
 snprintf(args, sizeof(args),
 "video_size=165x165:pix_fmt=bgr24:time_base=1/25:pixel_aspect=1/1");
 ret = avfilter_graph_create_filter(&overlay_buffersrc_ctx, overlay_buffersrc, "overlay_in", args, NULL,
 filter_graph);
 if (ret < 0)
 {
 fprintf(stderr, "Unable to create buffer source filter for overlay.\n");
 return ret;
 }

 // Initialize the format filter to convert overlay image to yuv420p
 snprintf(args, sizeof(args), "pix_fmts=yuv420p");
 ret = avfilter_graph_create_filter(&format_ctx, format_filter, "format", args, NULL, filter_graph);

 if (ret < 0) 
 {
 fprintf(stderr, "Unable to create format filter.\n");
 return ret;
 }

 // Initialize the buffer sink
 ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, NULL, filter_graph);
 if (ret < 0)
 {
 fprintf(stderr, "Unable to create buffer sink filter.\n");
 return ret;
 }

 // Initialize the overlay filter
 ret = avfilter_graph_create_filter(&overlay_ctx, overlay_filter, "overlay", "W-w:H-h:enable='between(t,0,20)':format=yuv420", NULL, filter_graph);
 if (ret < 0)
 {
 fprintf(stderr, "Unable to create overlay filter.\n");
 return ret;
 }

 // Connect the filters
 ret = avfilter_link(overlay_buffersrc_ctx, 0, format_ctx, 0);

 if (ret >= 0)
 {
 ret = avfilter_link(buffersrc_ctx, 0, overlay_ctx, 0);
 }
 else
 {
 fprintf(stderr, "Unable to configure filter graph.\n");
 return ret;
 }


 if (ret >= 0) 
 {
 ret = avfilter_link(format_ctx, 0, overlay_ctx, 1);
 }
 else
 {
 fprintf(stderr, "Unable to configure filter graph.\n");
 return ret;
 }

 if (ret >= 0) 
 {
 if ((ret = avfilter_link(overlay_ctx, 0, buffersink_ctx, 0)) < 0)
 {
 fprintf(stderr, "Unable to link filter graph.\n");
 return ret;
 }
 }
 else
 {
 fprintf(stderr, "Unable to configure filter graph.\n");
 return ret;
 }

 // Configure the filter graph
 if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
 {
 fprintf(stderr, "Unable to configure filter graph.\n");
 return ret;
 }

 *graph = filter_graph;
 *src_ctx = buffersrc_ctx;
 *overlay_src_ctx = overlay_buffersrc_ctx;
 *sink_ctx = buffersink_ctx;

 return 0;
}



Feeding the filter graph is done this way :


av_buffersrc_add_frame_flags(buffersrc_ctx, pFrameGrabberFrame, AV_BUFFERSRC_FLAG_KEEP_REF)
av_buffersink_get_frame(buffersink_ctx, filtered_frame)



av_buffersink_get_frame
returns alwaysEAGAIN
, no matter how many frames I feed into the graph. The frames (from framegrabber and the overlay frame) itself are looking fine.

I did set libav logging level to maximum but I do not see any warnings or errors or helpful, related information in the log.


Here the log output related to the filter configuration :


[in @ 00000288ee494f40] Setting 'video_size' to value '1920x1080'
[in @ 00000288ee494f40] Setting 'pix_fmt' to value 'yuv420p'
[in @ 00000288ee494f40] Setting 'time_base' to value '1/25'
[in @ 00000288ee494f40] Setting 'pixel_aspect' to value '1/1'
[in @ 00000288ee494f40] w:1920 h:1080 pixfmt:yuv420p tb:1/25 fr:0/1 sar:1/1 csp:unknown range:unknown
[overlay_in @ 00000288ff1013c0] Setting 'video_size' to value '165x165'
[overlay_in @ 00000288ff1013c0] Setting 'pix_fmt' to value 'bgr24'
[overlay_in @ 00000288ff1013c0] Setting 'time_base' to value '1/25'
[overlay_in @ 00000288ff1013c0] Setting 'pixel_aspect' to value '1/1'
[overlay_in @ 00000288ff1013c0] w:165 h:165 pixfmt:bgr24 tb:1/25 fr:0/1 sar:1/1 csp:unknown range:unknown
[format @ 00000288ff1015c0] Setting 'pix_fmts' to value 'yuv420p'
[overlay @ 00000288ff101880] Setting 'x' to value 'W-w'
[overlay @ 00000288ff101880] Setting 'y' to value 'H-h'
[overlay @ 00000288ff101880] Setting 'enable' to value 'between(t,0,20)'
[overlay @ 00000288ff101880] Setting 'format' to value 'yuv420'
[auto_scale_0 @ 00000288ff101ec0] w:iw h:ih flags:'' interl:0
[format @ 00000288ff1015c0] auto-inserting filter 'auto_scale_0' between the filter 'overlay_in' and the filter 'format'
[auto_scale_1 @ 00000288ee4a4cc0] w:iw h:ih flags:'' interl:0
[overlay @ 00000288ff101880] auto-inserting filter 'auto_scale_1' between the filter 'format' and the filter 'overlay'
[AVFilterGraph @ 00000288ee495c80] query_formats: 5 queried, 6 merged, 6 already done, 0 delayed
[auto_scale_0 @ 00000288ff101ec0] w:165 h:165 fmt:bgr24 csp:gbr range:pc sar:1/1 -> w:165 h:165 fmt:yuv420p csp:unknown range:unknown sar:1/1 flags:0x00000004
[auto_scale_1 @ 00000288ee4a4cc0] w:165 h:165 fmt:yuv420p csp:unknown range:unknown sar:1/1 -> w:165 h:165 fmt:yuva420p csp:unknown range:unknown sar:1/1 flags:0x00000004
[overlay @ 00000288ff101880] main w:1920 h:1080 fmt:yuv420p overlay w:165 h:165 fmt:yuva420p
[overlay @ 00000288ff101880] [framesync @ 00000288ff1019a8] Selected 1/25 time base
[overlay @ 00000288ff101880] [framesync @ 00000288ff1019a8] Sync level 2