[英]How to use the blackframe avfilter of ffmpeg in C/C++
I want to capture the first-not-black frame for a video as its preview;我想捕获视频的第一个非黑色帧作为预览; I looked at sample which came with FFmpeg examples:我查看了 FFmpeg 示例附带的示例:
/*
* Copyright (c) 2010 Nicolas George
* Copyright (c) 2011 Stefano Sabatini
/**
* @file
* API example for decoding and filtering
* @example filtering_video.c
*/
But how can I use the "blackframe" filter in C/C++?但是如何在 C/C++ 中使用“黑框”过滤器?
Recently, I am also solving the problem of how to detect black frames.最近也在解决如何检测黑框的问题。 Refer to vf_ blackframe.c, when the frame is judged as a black frame, frame->metadata will add a value "lavfi.blackframe.pblack"参考vf_blackframe.c,当frame判断为黑框时,frame->metadata会加一个值“lavfi.blackframe.pblack”
set filter_describe as将 filter_describe 设置为
const char *str_filter_describe = "[in]blackframe=95:30[out]"; const char *str_filter_describe = "[in]blackframe=95:30[out]";
whether it is black frame是否黑框
if (av_buffersrc_add_frame(_buffersrc_ctx, frame)< 0)
{
printf("error");
}
while (ture)
{
int ret = av_buffersink_get_frame_flags(_buffersink_ctx, frame, 0);
if (ret < 0)
{
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
ret = 0;
break;
}
};
if (auto e = av_dict_get(frame->metadata, "lavfi.blackframe.pblack", NULL,AV_DICT_MATCH_CASE){
if (strcmp("0", e->value) != 0){
printf("this is a black frame!!! amount:%s,pts:%ld", e->value, frame->pts);
/*post a message or do something */
//chage it value to 0
av_dict_set(&frame->metadata, "lavfi.blackframe.pblack", temp, 0);
}}
and make sure compile ffmpeg with --enable-filter=blackframe并确保使用 --enable-filter=blackframe 编译 ffmpeg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.