Revision f7ead94c

View differences:

cmdutils.c
747 747

  
748 748
    return pts;
749 749
}
750

  
751
#if CONFIG_AVFILTER
752

  
753
static int ffsink_init(AVFilterContext *ctx, const char *args, void *opaque)
754
{
755
    FFSinkContext *priv = ctx->priv;
756

  
757
    if (!opaque)
758
        return AVERROR(EINVAL);
759
    *priv = *(FFSinkContext *)opaque;
760

  
761
    return 0;
762
}
763

  
764
static void null_end_frame(AVFilterLink *inlink) { }
765

  
766
static int ffsink_query_formats(AVFilterContext *ctx)
767
{
768
    FFSinkContext *priv = ctx->priv;
769
    enum PixelFormat pix_fmts[] = { priv->pix_fmt, PIX_FMT_NONE };
770

  
771
    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
772
    return 0;
773
}
774

  
775
AVFilter ffsink = {
776
    .name      = "ffsink",
777
    .priv_size = sizeof(FFSinkContext),
778
    .init      = ffsink_init,
779

  
780
    .query_formats = ffsink_query_formats,
781

  
782
    .inputs    = (AVFilterPad[]) {{ .name          = "default",
783
                                    .type          = AVMEDIA_TYPE_VIDEO,
784
                                    .end_frame     = null_end_frame,
785
                                    .min_perms     = AV_PERM_READ, },
786
                                  { .name = NULL }},
787
    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
788
};
789

  
790
#endif /* CONFIG_AVFILTER */
cmdutils.h
261 261
 */
262 262
int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t pts, int64_t dts);
263 263

  
264
#if CONFIG_AVFILTER
265
#include "libavfilter/avfilter.h"
266

  
267
typedef struct {
268
    enum PixelFormat pix_fmt;
269
} FFSinkContext;
270

  
271
extern AVFilter ffsink;
272

  
273
#endif /* CONFIG_AVFILTER */
274

  
264 275
#endif /* FFMPEG_CMDUTILS_H */
ffmpeg.c
339 339
#endif
340 340

  
341 341
#if CONFIG_AVFILTER
342
typedef struct {
343
    int pix_fmt;
344
} FilterOutPriv;
345

  
346

  
347
static int output_init(AVFilterContext *ctx, const char *args, void *opaque)
348
{
349
    FilterOutPriv *priv = ctx->priv;
350

  
351
    if(!opaque) return -1;
352

  
353
    priv->pix_fmt = *((int *)opaque);
354

  
355
    return 0;
356
}
357

  
358
static void output_end_frame(AVFilterLink *link)
359
{
360
}
361

  
362
static int output_query_formats(AVFilterContext *ctx)
363
{
364
    FilterOutPriv *priv = ctx->priv;
365
    enum PixelFormat pix_fmts[] = { priv->pix_fmt, PIX_FMT_NONE };
366

  
367
    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
368
    return 0;
369
}
370 342

  
371 343
static int get_filtered_video_pic(AVFilterContext *ctx,
372 344
                                  AVFilterBufferRef **picref, AVFrame *pic2,
......
391 363
    return 1;
392 364
}
393 365

  
394
static AVFilter output_filter =
395
{
396
    .name      = "ffmpeg_output",
397

  
398
    .priv_size = sizeof(FilterOutPriv),
399
    .init      = output_init,
400

  
401
    .query_formats = output_query_formats,
402

  
403
    .inputs    = (AVFilterPad[]) {{ .name          = "default",
404
                                    .type          = AVMEDIA_TYPE_VIDEO,
405
                                    .end_frame     = output_end_frame,
406
                                    .min_perms     = AV_PERM_READ, },
407
                                  { .name = NULL }},
408
    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
409
};
410

  
411 366
static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
412 367
{
413 368
    AVFilterContext *last_filter, *filter;
414 369
    /** filter graph containing all filters including input & output */
415 370
    AVCodecContext *codec = ost->st->codec;
416 371
    AVCodecContext *icodec = ist->st->codec;
372
    FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt };
417 373
    char args[255];
418 374
    int ret;
419 375

  
......
421 377

  
422 378
    if ((ret = avfilter_open(&ist->input_video_filter, avfilter_get_by_name("buffer"), "src")) < 0)
423 379
        return ret;
424
    if ((ret = avfilter_open(&ist->output_video_filter, &output_filter, "out")) < 0)
380
    if ((ret = avfilter_open(&ist->output_video_filter, &ffsink, "out")) < 0)
425 381
        return ret;
426 382

  
427 383
    snprintf(args, 255, "%d:%d:%d:%d:%d", ist->st->codec->width,
......
429 385
             ist->st->time_base.num, ist->st->time_base.den);
430 386
    if ((ret = avfilter_init_filter(ist->input_video_filter, args, NULL)) < 0)
431 387
        return ret;
432
    if ((ret = avfilter_init_filter(ist->output_video_filter, NULL, &codec->pix_fmt)) < 0)
388
    if ((ret = avfilter_init_filter(ist->output_video_filter, NULL, &ffsink_ctx)) < 0)
433 389
        return ret;
434 390

  
435 391
    /* add input and output filters to the overall graph */
ffplay.c
1779 1779
                                  { .name = NULL }},
1780 1780
};
1781 1781

  
1782
static void output_end_frame(AVFilterLink *link)
1783
{
1784
}
1785

  
1786
static int output_query_formats(AVFilterContext *ctx)
1787
{
1788
    enum PixelFormat pix_fmts[] = { PIX_FMT_YUV420P, PIX_FMT_NONE };
1789

  
1790
    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
1791
    return 0;
1792
}
1793

  
1794 1782
static int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
1795 1783
                                    int64_t *pts, AVRational *tb, int64_t *pos)
1796 1784
{
......
1812 1800

  
1813 1801
    return 1;
1814 1802
}
1815

  
1816
static AVFilter output_filter =
1817
{
1818
    .name      = "ffplay_output",
1819

  
1820
    .query_formats = output_query_formats,
1821

  
1822
    .inputs    = (AVFilterPad[]) {{ .name          = "default",
1823
                                    .type          = AVMEDIA_TYPE_VIDEO,
1824
                                    .end_frame     = output_end_frame,
1825
                                    .min_perms     = AV_PERM_READ, },
1826
                                  { .name = NULL }},
1827
    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
1828
};
1829 1803
#endif  /* CONFIG_AVFILTER */
1830 1804

  
1831 1805
static int video_thread(void *arg)
......
1839 1813
#if CONFIG_AVFILTER
1840 1814
    int64_t pos;
1841 1815
    char sws_flags_str[128];
1816
    FFSinkContext ffsink_ctx = { .pix_fmt = PIX_FMT_YUV420P };
1842 1817
    AVFilterContext *filt_src = NULL, *filt_out = NULL;
1843 1818
    AVFilterGraph *graph = av_mallocz(sizeof(AVFilterGraph));
1844 1819
    snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%d", sws_flags);
1845 1820
    graph->scale_sws_opts = av_strdup(sws_flags_str);
1846 1821

  
1847 1822
    if (avfilter_open(&filt_src, &input_filter,  "src") < 0) goto the_end;
1848
    if (avfilter_open(&filt_out, &output_filter, "out") < 0) goto the_end;
1823
    if (avfilter_open(&filt_out, &ffsink      ,  "out") < 0) goto the_end;
1849 1824

  
1850 1825
    if(avfilter_init_filter(filt_src, NULL, is))             goto the_end;
1851
    if(avfilter_init_filter(filt_out, NULL, NULL))           goto the_end;
1826
    if(avfilter_init_filter(filt_out, NULL, &ffsink_ctx))    goto the_end;
1852 1827

  
1853 1828

  
1854 1829
    if(vfilters) {

Also available in: Unified diff