This fixes regressions caused by switching from ffmpegs system to avfilters.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
| ... | ... |
@@ -24,6 +24,7 @@ |
| 24 | 24 |
#include <string.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "libavutil/audioconvert.h" |
| 27 |
+#include "libavutil/pixdesc.h" |
|
| 27 | 28 |
#include "avfilter.h" |
| 28 | 29 |
#include "avfiltergraph.h" |
| 29 | 30 |
#include "internal.h" |
| ... | ... |
@@ -252,13 +253,26 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) |
| 252 | 252 |
return 0; |
| 253 | 253 |
} |
| 254 | 254 |
|
| 255 |
-static void pick_format(AVFilterLink *link) |
|
| 255 |
+static void pick_format(AVFilterLink *link, AVFilterLink *ref) |
|
| 256 | 256 |
{
|
| 257 | 257 |
if (!link || !link->in_formats) |
| 258 | 258 |
return; |
| 259 | 259 |
|
| 260 |
+ if (link->type == AVMEDIA_TYPE_VIDEO) {
|
|
| 261 |
+ if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
|
|
| 262 |
+ int has_alpha= av_pix_fmt_descriptors[ref->format].nb_components % 2 == 0; |
|
| 263 |
+ enum PixelFormat best= PIX_FMT_NONE; |
|
| 264 |
+ int i; |
|
| 265 |
+ for (i=0; i<link->in_formats->format_count; i++) {
|
|
| 266 |
+ enum PixelFormat p = link->in_formats->formats[i]; |
|
| 267 |
+ best= avcodec_find_best_pix_fmt2(best, p, ref->format, has_alpha, NULL); |
|
| 268 |
+ } |
|
| 269 |
+ link->format = best; |
|
| 270 |
+ }else |
|
| 271 |
+ link->format = link->in_formats->formats[0]; |
|
| 272 |
+ } |
|
| 273 |
+ |
|
| 260 | 274 |
link->in_formats->format_count = 1; |
| 261 |
- link->format = link->in_formats->formats[0]; |
|
| 262 | 275 |
avfilter_formats_unref(&link->in_formats); |
| 263 | 276 |
avfilter_formats_unref(&link->out_formats); |
| 264 | 277 |
|
| ... | ... |
@@ -324,11 +338,21 @@ static void pick_formats(AVFilterGraph *graph) |
| 324 | 324 |
|
| 325 | 325 |
for (i = 0; i < graph->filter_count; i++) {
|
| 326 | 326 |
AVFilterContext *filter = graph->filters[i]; |
| 327 |
- |
|
| 328 |
- for (j = 0; j < filter->input_count; j++) |
|
| 329 |
- pick_format(filter->inputs[j]); |
|
| 330 |
- for (j = 0; j < filter->output_count; j++) |
|
| 331 |
- pick_format(filter->outputs[j]); |
|
| 327 |
+ if (filter->input_count && filter->output_count) {
|
|
| 328 |
+ for (j = 0; j < filter->input_count; j++) |
|
| 329 |
+ pick_format(filter->inputs[j], NULL); |
|
| 330 |
+ for (j = 0; j < filter->output_count; j++) |
|
| 331 |
+ pick_format(filter->outputs[j], filter->inputs[0]); |
|
| 332 |
+ } |
|
| 333 |
+ } |
|
| 334 |
+ for (i = 0; i < graph->filter_count; i++) {
|
|
| 335 |
+ AVFilterContext *filter = graph->filters[i]; |
|
| 336 |
+ if (!(filter->input_count && filter->output_count)) {
|
|
| 337 |
+ for (j = 0; j < filter->input_count; j++) |
|
| 338 |
+ pick_format(filter->inputs[j], NULL); |
|
| 339 |
+ for (j = 0; j < filter->output_count; j++) |
|
| 340 |
+ pick_format(filter->outputs[j], NULL); |
|
| 341 |
+ } |
|
| 332 | 342 |
} |
| 333 | 343 |
} |
| 334 | 344 |
|