mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
fftools/ffmpeg_filter: stop accessing AVCodecContext.codec
Instead pass the encoder through a newly-added output options struct, analogous to previously added input options. Will allow decoupling filtering from encoding in future commits.
This commit is contained in:
parent
8c33085313
commit
8e35e33d42
@ -263,6 +263,11 @@ typedef struct InputFilterOptions {
|
|||||||
AVFrame *fallback;
|
AVFrame *fallback;
|
||||||
} InputFilterOptions;
|
} InputFilterOptions;
|
||||||
|
|
||||||
|
typedef struct OutputFilterOptions {
|
||||||
|
// Codec used for encoding, may be NULL
|
||||||
|
const AVCodec *enc;
|
||||||
|
} OutputFilterOptions;
|
||||||
|
|
||||||
typedef struct InputFilter {
|
typedef struct InputFilter {
|
||||||
struct FilterGraph *graph;
|
struct FilterGraph *graph;
|
||||||
uint8_t *name;
|
uint8_t *name;
|
||||||
@ -684,7 +689,8 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id
|
|||||||
int filtergraph_is_simple(const FilterGraph *fg);
|
int filtergraph_is_simple(const FilterGraph *fg);
|
||||||
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
|
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
|
||||||
char *graph_desc,
|
char *graph_desc,
|
||||||
Scheduler *sch, unsigned sch_idx_enc);
|
Scheduler *sch, unsigned sch_idx_enc,
|
||||||
|
const OutputFilterOptions *opts);
|
||||||
int fg_finalise_bindings(FilterGraph *fg);
|
int fg_finalise_bindings(FilterGraph *fg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -699,7 +705,8 @@ FrameData *packet_data (AVPacket *pkt);
|
|||||||
const FrameData *packet_data_c(AVPacket *pkt);
|
const FrameData *packet_data_c(AVPacket *pkt);
|
||||||
|
|
||||||
int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
|
int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
|
||||||
unsigned sched_idx_enc);
|
unsigned sched_idx_enc,
|
||||||
|
const OutputFilterOptions *opts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new filtergraph in the global filtergraph list.
|
* Create a new filtergraph in the global filtergraph list.
|
||||||
|
@ -763,13 +763,13 @@ static int set_channel_layout(OutputFilterPriv *f, const AVChannelLayout *layout
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
|
int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
|
||||||
unsigned sched_idx_enc)
|
unsigned sched_idx_enc,
|
||||||
|
const OutputFilterOptions *opts)
|
||||||
{
|
{
|
||||||
const OutputFile *of = ost->file;
|
const OutputFile *of = ost->file;
|
||||||
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
|
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
|
||||||
FilterGraph *fg = ofilter->graph;
|
FilterGraph *fg = ofilter->graph;
|
||||||
FilterGraphPriv *fgp = fgp_from_fg(fg);
|
FilterGraphPriv *fgp = fgp_from_fg(fg);
|
||||||
const AVCodec *c = ost->enc_ctx->codec;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
av_assert0(!ofilter->ost);
|
av_assert0(!ofilter->ost);
|
||||||
@ -786,14 +786,14 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
|
|||||||
ofp->height = ost->enc_ctx->height;
|
ofp->height = ost->enc_ctx->height;
|
||||||
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
|
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
|
||||||
ofp->format = ost->enc_ctx->pix_fmt;
|
ofp->format = ost->enc_ctx->pix_fmt;
|
||||||
} else {
|
} else if (opts->enc) {
|
||||||
ofp->formats = c->pix_fmts;
|
ofp->formats = opts->enc->pix_fmts;
|
||||||
|
|
||||||
// MJPEG encoder exports a full list of supported pixel formats,
|
// MJPEG encoder exports a full list of supported pixel formats,
|
||||||
// but the full-range ones are experimental-only.
|
// but the full-range ones are experimental-only.
|
||||||
// Restrict the auto-conversion list unless -strict experimental
|
// Restrict the auto-conversion list unless -strict experimental
|
||||||
// has been specified.
|
// has been specified.
|
||||||
if (!strcmp(c->name, "mjpeg")) {
|
if (!strcmp(opts->enc->name, "mjpeg")) {
|
||||||
// FIXME: YUV420P etc. are actually supported with full color range,
|
// FIXME: YUV420P etc. are actually supported with full color range,
|
||||||
// yet the latter information isn't available here.
|
// yet the latter information isn't available here.
|
||||||
static const enum AVPixelFormat mjpeg_formats[] =
|
static const enum AVPixelFormat mjpeg_formats[] =
|
||||||
@ -822,11 +822,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
|
|||||||
|
|
||||||
ofp->fps.framerate = ost->frame_rate;
|
ofp->fps.framerate = ost->frame_rate;
|
||||||
ofp->fps.framerate_max = ost->max_frame_rate;
|
ofp->fps.framerate_max = ost->max_frame_rate;
|
||||||
ofp->fps.framerate_supported = ost->force_fps ?
|
ofp->fps.framerate_supported = ost->force_fps && opts->enc ?
|
||||||
NULL : c->supported_framerates;
|
NULL : opts->enc->supported_framerates;
|
||||||
|
|
||||||
// reduce frame rate for mpeg4 to be within the spec limits
|
// reduce frame rate for mpeg4 to be within the spec limits
|
||||||
if (c->id == AV_CODEC_ID_MPEG4)
|
if (opts->enc && opts->enc->id == AV_CODEC_ID_MPEG4)
|
||||||
ofp->fps.framerate_clip = 65535;
|
ofp->fps.framerate_clip = 65535;
|
||||||
|
|
||||||
ofp->fps.dup_warning = 1000;
|
ofp->fps.dup_warning = 1000;
|
||||||
@ -835,20 +835,21 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
|
|||||||
case AVMEDIA_TYPE_AUDIO:
|
case AVMEDIA_TYPE_AUDIO:
|
||||||
if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
|
if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
|
||||||
ofp->format = ost->enc_ctx->sample_fmt;
|
ofp->format = ost->enc_ctx->sample_fmt;
|
||||||
} else {
|
} else if (opts->enc) {
|
||||||
ofp->formats = c->sample_fmts;
|
ofp->formats = opts->enc->sample_fmts;
|
||||||
}
|
}
|
||||||
if (ost->enc_ctx->sample_rate) {
|
if (ost->enc_ctx->sample_rate) {
|
||||||
ofp->sample_rate = ost->enc_ctx->sample_rate;
|
ofp->sample_rate = ost->enc_ctx->sample_rate;
|
||||||
} else {
|
} else if (opts->enc) {
|
||||||
ofp->sample_rates = c->supported_samplerates;
|
ofp->sample_rates = opts->enc->supported_samplerates;
|
||||||
}
|
}
|
||||||
if (ost->enc_ctx->ch_layout.nb_channels) {
|
if (ost->enc_ctx->ch_layout.nb_channels) {
|
||||||
int ret = set_channel_layout(ofp, c->ch_layouts, &ost->enc_ctx->ch_layout);
|
int ret = set_channel_layout(ofp, opts->enc ? opts->enc->ch_layouts : NULL,
|
||||||
|
&ost->enc_ctx->ch_layout);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else if (c->ch_layouts) {
|
} else if (opts->enc) {
|
||||||
ofp->ch_layouts = c->ch_layouts;
|
ofp->ch_layouts = opts->enc->ch_layouts;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1079,7 +1080,8 @@ fail:
|
|||||||
|
|
||||||
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
|
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
|
||||||
char *graph_desc,
|
char *graph_desc,
|
||||||
Scheduler *sch, unsigned sched_idx_enc)
|
Scheduler *sch, unsigned sched_idx_enc,
|
||||||
|
const OutputFilterOptions *opts)
|
||||||
{
|
{
|
||||||
FilterGraph *fg;
|
FilterGraph *fg;
|
||||||
FilterGraphPriv *fgp;
|
FilterGraphPriv *fgp;
|
||||||
@ -1111,7 +1113,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = ofilter_bind_ost(fg->outputs[0], ost, sched_idx_enc);
|
ret = ofilter_bind_ost(fg->outputs[0], ost, sched_idx_enc, opts);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -1371,14 +1371,18 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
|
|||||||
|
|
||||||
if (ost->enc &&
|
if (ost->enc &&
|
||||||
(type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
|
(type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
|
||||||
|
OutputFilterOptions opts = {
|
||||||
|
.enc = enc,
|
||||||
|
};
|
||||||
|
|
||||||
if (ofilter) {
|
if (ofilter) {
|
||||||
ost->filter = ofilter;
|
ost->filter = ofilter;
|
||||||
ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc);
|
ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc, &opts);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
ret = init_simple_filtergraph(ost->ist, ost, filters,
|
ret = init_simple_filtergraph(ost->ist, ost, filters,
|
||||||
mux->sch, ms->sch_idx_enc);
|
mux->sch, ms->sch_idx_enc, &opts);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_log(ost, AV_LOG_ERROR,
|
av_log(ost, AV_LOG_ERROR,
|
||||||
"Error initializing a simple filtergraph\n");
|
"Error initializing a simple filtergraph\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user