This ensures that the output buffers will have the channel layout set,
which is required by filters.
Also consistent with ffmpeg.c behavior.
... | ... |
@@ -162,6 +162,29 @@ static int open_stream(void *log, MovieStream *st) |
162 | 162 |
return 0; |
163 | 163 |
} |
164 | 164 |
|
165 |
+static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx) |
|
166 |
+{ |
|
167 |
+ AVCodecContext *dec_ctx = st->st->codec; |
|
168 |
+ char buf[256]; |
|
169 |
+ int64_t chl = av_get_default_channel_layout(dec_ctx->channels); |
|
170 |
+ |
|
171 |
+ if (!chl) { |
|
172 |
+ av_log(log_ctx, AV_LOG_ERROR, |
|
173 |
+ "Channel layout is not set in stream %d, and could not " |
|
174 |
+ "be guessed from the number of channels (%d)\n", |
|
175 |
+ st_index, dec_ctx->channels); |
|
176 |
+ return AVERROR(EINVAL); |
|
177 |
+ } |
|
178 |
+ |
|
179 |
+ av_get_channel_layout_string(buf, sizeof(buf), dec_ctx->channels, chl); |
|
180 |
+ av_log(log_ctx, AV_LOG_WARNING, |
|
181 |
+ "Channel layout is not set in output stream %d, " |
|
182 |
+ "guessed channel layout is '%s'\n", |
|
183 |
+ st_index, buf); |
|
184 |
+ dec_ctx->channel_layout = chl; |
|
185 |
+ return 0; |
|
186 |
+} |
|
187 |
+ |
|
165 | 188 |
static av_cold int movie_init(AVFilterContext *ctx, const char *args) |
166 | 189 |
{ |
167 | 190 |
MovieContext *movie = ctx->priv; |
... | ... |
@@ -282,6 +305,12 @@ static av_cold int movie_init(AVFilterContext *ctx, const char *args) |
282 | 282 |
ret = open_stream(ctx, &movie->st[i]); |
283 | 283 |
if (ret < 0) |
284 | 284 |
return ret; |
285 |
+ if ( movie->st[i].st->codec->codec->type == AVMEDIA_TYPE_AUDIO && |
|
286 |
+ !movie->st[i].st->codec->channel_layout) { |
|
287 |
+ ret = guess_channel_layout(&movie->st[i], i, ctx); |
|
288 |
+ if (ret < 0) |
|
289 |
+ return ret; |
|
290 |
+ } |
|
285 | 291 |
} |
286 | 292 |
|
287 | 293 |
if (!(movie->frame = avcodec_alloc_frame()) ) { |
... | ... |
@@ -337,8 +366,7 @@ static int movie_query_formats(AVFilterContext *ctx) |
337 | 337 |
ff_formats_ref(ff_make_format_list(list), &outlink->in_formats); |
338 | 338 |
list[0] = c->sample_rate; |
339 | 339 |
ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates); |
340 |
- list64[0] = c->channel_layout ? c->channel_layout : |
|
341 |
- av_get_default_channel_layout(c->channels); |
|
340 |
+ list64[0] = c->channel_layout; |
|
342 | 341 |
ff_channel_layouts_ref(avfilter_make_format64_list(list64), |
343 | 342 |
&outlink->in_channel_layouts); |
344 | 343 |
break; |