History

avfiltergraph: More advanced heuristic to select colorspace.

This fixes regressions caused by switching from ffmpegs system to avfilters.

Michael Niedermayer committed 14 years ago

Commit 0d115d71 parent 128fa121 file · +31 −7Browse files

Unified · Split

libavfilter/avfiltergraph.c+31−7
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424 #include <string.h>
2525
2626 #include "libavutil/audioconvert.h"
27+#include "libavutil/pixdesc.h"
2728 #include "avfilter.h"
2829 #include "avfiltergraph.h"
2930 #include "internal.h"
@@ -252,13 +253,26 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) · 222 unmodified lines
252253 return 0;
253254 }
254255
255−static void pick_format(AVFilterLink *link)
256+static void pick_format(AVFilterLink *link, AVFilterLink *ref)
256257 {
257258 if (!link || !link->in_formats)
258259 return;
259260
261+ if (link->type == AVMEDIA_TYPE_VIDEO) {
262+ if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
263+ int has_alpha= av_pix_fmt_descriptors[ref->format].nb_components % 2 == 0;
264+ enum PixelFormat best= PIX_FMT_NONE;
265+ int i;
266+ for (i=0; i<link->in_formats->format_count; i++) {
267+ enum PixelFormat p = link->in_formats->formats[i];
268+ best= avcodec_find_best_pix_fmt2(best, p, ref->format, has_alpha, NULL);
269+ }
270+ link->format = best;
271+ }else
272+ link->format = link->in_formats->formats[0];
273+ }
274+
260275 link->in_formats->format_count = 1;
261− link->format = link->in_formats->formats[0];
262276 avfilter_formats_unref(&link->in_formats);
263277 avfilter_formats_unref(&link->out_formats);
264278
@@ -324,11 +338,21 @@ static void pick_formats(AVFilterGraph *graph) · 59 unmodified lines
324338
325339 for (i = 0; i < graph->filter_count; i++) {
326340 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]);
341+ if (filter->input_count && filter->output_count) {
342+ for (j = 0; j < filter->input_count; j++)
343+ pick_format(filter->inputs[j], NULL);
344+ for (j = 0; j < filter->output_count; j++)
345+ pick_format(filter->outputs[j], filter->inputs[0]);
346+ }
347+ }
348+ for (i = 0; i < graph->filter_count; i++) {
349+ AVFilterContext *filter = graph->filters[i];
350+ if (!(filter->input_count && filter->output_count)) {
351+ for (j = 0; j < filter->input_count; j++)
352+ pick_format(filter->inputs[j], NULL);
353+ for (j = 0; j < filter->output_count; j++)
354+ pick_format(filter->outputs[j], NULL);
355+ }
332356 }
333357 }
334358

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t