You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
vsrc_buffer: make the source accept sws_param in init
Avoid the need of two distinct av_vsrc_add_video_buffer_ref* functions. Simplify the interface.
This commit is contained in:
@@ -1536,9 +1536,10 @@ This source is mainly intended for a programmatic use, in particular
|
|||||||
through the interface defined in @file{libavfilter/vsrc_buffer.h}.
|
through the interface defined in @file{libavfilter/vsrc_buffer.h}.
|
||||||
|
|
||||||
It accepts the following parameters:
|
It accepts the following parameters:
|
||||||
@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}
|
@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}:@var{scale_params}
|
||||||
|
|
||||||
All the parameters need to be explicitely defined.
|
All the parameters but @var{scale_params} need to be explicitely
|
||||||
|
defined.
|
||||||
|
|
||||||
Follows the list of the accepted parameters.
|
Follows the list of the accepted parameters.
|
||||||
|
|
||||||
@@ -1559,6 +1560,11 @@ timestamps of the buffered frames.
|
|||||||
@item sample_aspect_ratio.num, sample_aspect_ratio.den
|
@item sample_aspect_ratio.num, sample_aspect_ratio.den
|
||||||
Specify numerator and denominator of the sample aspect ratio assumed
|
Specify numerator and denominator of the sample aspect ratio assumed
|
||||||
by the video frames.
|
by the video frames.
|
||||||
|
|
||||||
|
@item scale_params
|
||||||
|
Specify the optional parameters to be used for the scale filter which
|
||||||
|
is automatically inserted when an input change is detected in the
|
||||||
|
input size or format.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
2
ffmpeg.c
2
ffmpeg.c
@@ -1652,7 +1652,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
|
|||||||
|
|
||||||
picref =
|
picref =
|
||||||
avfilter_get_video_buffer_ref_from_frame(&picture, AV_PERM_WRITE);
|
avfilter_get_video_buffer_ref_from_frame(&picture, AV_PERM_WRITE);
|
||||||
av_vsrc_buffer_add_video_buffer_ref(ost->input_video_filter, picref, ""); //TODO user setable params
|
av_vsrc_buffer_add_video_buffer_ref(ost->input_video_filter, picref);
|
||||||
picref->buf->data[0] = NULL;
|
picref->buf->data[0] = NULL;
|
||||||
avfilter_unref_buffer(picref);
|
avfilter_unref_buffer(picref);
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
#include "libavutil/samplefmt.h"
|
#include "libavutil/samplefmt.h"
|
||||||
|
|
||||||
#define LIBAVFILTER_VERSION_MAJOR 2
|
#define LIBAVFILTER_VERSION_MAJOR 2
|
||||||
#define LIBAVFILTER_VERSION_MINOR 6
|
#define LIBAVFILTER_VERSION_MINOR 7
|
||||||
#define LIBAVFILTER_VERSION_MICRO 0
|
#define LIBAVFILTER_VERSION_MICRO 0
|
||||||
|
|
||||||
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
||||||
|
@@ -37,8 +37,7 @@ typedef struct {
|
|||||||
char sws_param[256];
|
char sws_param[256];
|
||||||
} BufferSourceContext;
|
} BufferSourceContext;
|
||||||
|
|
||||||
int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref,
|
int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref)
|
||||||
const char *sws_param)
|
|
||||||
{
|
{
|
||||||
BufferSourceContext *c = buffer_filter->priv;
|
BufferSourceContext *c = buffer_filter->priv;
|
||||||
AVFilterLink *outlink = buffer_filter->outputs[0];
|
AVFilterLink *outlink = buffer_filter->outputs[0];
|
||||||
@@ -52,13 +51,10 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte
|
|||||||
//return -1;
|
//return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!c->sws_param[0]) {
|
|
||||||
snprintf(c->sws_param, 255, "%d:%d:%s", c->w, c->h, sws_param);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) {
|
if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) {
|
||||||
AVFilterContext *scale = buffer_filter->outputs[0]->dst;
|
AVFilterContext *scale = buffer_filter->outputs[0]->dst;
|
||||||
AVFilterLink *link;
|
AVFilterLink *link;
|
||||||
|
char scale_param[1024];
|
||||||
|
|
||||||
av_log(buffer_filter, AV_LOG_INFO,
|
av_log(buffer_filter, AV_LOG_INFO,
|
||||||
"Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
|
"Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
|
||||||
@@ -72,7 +68,8 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte
|
|||||||
if ((ret = avfilter_open(&scale, f, "Input equalizer")) < 0)
|
if ((ret = avfilter_open(&scale, f, "Input equalizer")) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if ((ret = avfilter_init_filter(scale, c->sws_param, NULL)) < 0) {
|
snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s", c->w, c->h, c->sws_param);
|
||||||
|
if ((ret = avfilter_init_filter(scale, scale_param, NULL)) < 0) {
|
||||||
avfilter_free(scale);
|
avfilter_free(scale);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -85,8 +82,9 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte
|
|||||||
|
|
||||||
scale->outputs[0]->format= c->pix_fmt;
|
scale->outputs[0]->format= c->pix_fmt;
|
||||||
} else if (!strcmp(scale->filter->name, "scale")) {
|
} else if (!strcmp(scale->filter->name, "scale")) {
|
||||||
snprintf(c->sws_param, 255, "%d:%d:%s", scale->outputs[0]->w, scale->outputs[0]->h, sws_param);
|
snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s",
|
||||||
scale->filter->init(scale, c->sws_param, NULL);
|
scale->outputs[0]->w, scale->outputs[0]->h, c->sws_param);
|
||||||
|
scale->filter->init(scale, scale_param, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
c->pix_fmt = scale->inputs[0]->format = picref->format;
|
c->pix_fmt = scale->inputs[0]->format = picref->format;
|
||||||
@@ -108,24 +106,21 @@ int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilte
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref)
|
|
||||||
{
|
|
||||||
return av_vsrc_buffer_add_video_buffer_ref2(buffer_filter, picref, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
|
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
|
||||||
{
|
{
|
||||||
BufferSourceContext *c = ctx->priv;
|
BufferSourceContext *c = ctx->priv;
|
||||||
char pix_fmt_str[128];
|
char pix_fmt_str[128];
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
*c->sws_param = 0;
|
||||||
|
|
||||||
if (!args ||
|
if (!args ||
|
||||||
(n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d", &c->w, &c->h, pix_fmt_str,
|
(n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d:%255c", &c->w, &c->h, pix_fmt_str,
|
||||||
&c->time_base.num, &c->time_base.den,
|
&c->time_base.num, &c->time_base.den,
|
||||||
&c->sample_aspect_ratio.num, &c->sample_aspect_ratio.den)) != 7) {
|
&c->sample_aspect_ratio.num, &c->sample_aspect_ratio.den, c->sws_param)) < 7) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but only %d found in '%s'\n", n, args);
|
av_log(ctx, AV_LOG_ERROR, "Expected at least 7 arguments, but only %d found in '%s'\n", n, args);
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) {
|
if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) {
|
||||||
char *tail;
|
char *tail;
|
||||||
c->pix_fmt = strtol(pix_fmt_str, &tail, 10);
|
c->pix_fmt = strtol(pix_fmt_str, &tail, 10);
|
||||||
@@ -135,10 +130,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d\n",
|
av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d sws_param:%s\n",
|
||||||
c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name,
|
c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name,
|
||||||
c->time_base.num, c->time_base.den,
|
c->time_base.num, c->time_base.den,
|
||||||
c->sample_aspect_ratio.num, c->sample_aspect_ratio.den);
|
c->sample_aspect_ratio.num, c->sample_aspect_ratio.den, c->sws_param);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,7 +31,4 @@
|
|||||||
|
|
||||||
int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref);
|
int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref);
|
||||||
|
|
||||||
int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref,
|
|
||||||
const char *sws_param);
|
|
||||||
|
|
||||||
#endif /* AVFILTER_VSRC_BUFFER_H */
|
#endif /* AVFILTER_VSRC_BUFFER_H */
|
||||||
|
Reference in New Issue
Block a user