fftools/ffmpeg_opt: Don't duplicate array unnecessarily

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-11-26 19:44:21 +01:00
parent d9f07a506d
commit 4913f05ccf
3 changed files with 12 additions and 41 deletions

View File

@ -555,9 +555,6 @@ static void ffmpeg_cleanup(int ret)
avfilter_inout_free(&ofilter->out_tmp); avfilter_inout_free(&ofilter->out_tmp);
av_freep(&ofilter->name); av_freep(&ofilter->name);
av_freep(&ofilter->formats);
av_freep(&ofilter->channel_layouts);
av_freep(&ofilter->sample_rates);
av_freep(&fg->outputs[j]); av_freep(&fg->outputs[j]);
} }
av_freep(&fg->outputs); av_freep(&fg->outputs);

View File

@ -273,9 +273,10 @@ typedef struct OutputFilter {
uint64_t channel_layout; uint64_t channel_layout;
// those are only set if no format is specified and the encoder gives us multiple options // those are only set if no format is specified and the encoder gives us multiple options
int *formats; // They point directly to the relevant lists of the encoder.
uint64_t *channel_layouts; const int *formats;
int *sample_rates; const uint64_t *channel_layouts;
const int *sample_rates;
} OutputFilter; } OutputFilter;
typedef struct FilterGraph { typedef struct FilterGraph {

View File

@ -2614,7 +2614,6 @@ loop_end:
/* set the filter output constraints */ /* set the filter output constraints */
if (ost->filter) { if (ost->filter) {
OutputFilter *f = ost->filter; OutputFilter *f = ost->filter;
int count;
switch (ost->enc_ctx->codec_type) { switch (ost->enc_ctx->codec_type) {
case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_VIDEO:
f->frame_rate = ost->frame_rate; f->frame_rate = ost->frame_rate;
@ -2622,51 +2621,25 @@ loop_end:
f->height = ost->enc_ctx->height; f->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) {
f->format = ost->enc_ctx->pix_fmt; f->format = ost->enc_ctx->pix_fmt;
} else if (ost->enc->pix_fmts) { } else {
count = 0; f->formats = ost->enc->pix_fmts;
while (ost->enc->pix_fmts[count] != AV_PIX_FMT_NONE)
count++;
f->formats = av_calloc(count + 1, sizeof(*f->formats));
if (!f->formats)
exit_program(1);
memcpy(f->formats, ost->enc->pix_fmts, (count + 1) * sizeof(*f->formats));
} }
break; break;
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) {
f->format = ost->enc_ctx->sample_fmt; f->format = ost->enc_ctx->sample_fmt;
} else if (ost->enc->sample_fmts) { } else {
count = 0; f->formats = ost->enc->sample_fmts;
while (ost->enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
count++;
f->formats = av_calloc(count + 1, sizeof(*f->formats));
if (!f->formats)
exit_program(1);
memcpy(f->formats, ost->enc->sample_fmts, (count + 1) * sizeof(*f->formats));
} }
if (ost->enc_ctx->sample_rate) { if (ost->enc_ctx->sample_rate) {
f->sample_rate = ost->enc_ctx->sample_rate; f->sample_rate = ost->enc_ctx->sample_rate;
} else if (ost->enc->supported_samplerates) { } else {
count = 0; f->sample_rates = ost->enc->supported_samplerates;
while (ost->enc->supported_samplerates[count])
count++;
f->sample_rates = av_calloc(count + 1, sizeof(*f->sample_rates));
if (!f->sample_rates)
exit_program(1);
memcpy(f->sample_rates, ost->enc->supported_samplerates,
(count + 1) * sizeof(*f->sample_rates));
} }
if (ost->enc_ctx->channels) { if (ost->enc_ctx->channels) {
f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels); f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels);
} else if (ost->enc->channel_layouts) { } else {
count = 0; f->channel_layouts = ost->enc->channel_layouts;
while (ost->enc->channel_layouts[count])
count++;
f->channel_layouts = av_calloc(count + 1, sizeof(*f->channel_layouts));
if (!f->channel_layouts)
exit_program(1);
memcpy(f->channel_layouts, ost->enc->channel_layouts,
(count + 1) * sizeof(*f->channel_layouts));
} }
break; break;
} }