~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to doc/examples/filtering_video.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <libavfilter/avcodec.h>
37
37
#include <libavfilter/buffersink.h>
38
38
#include <libavfilter/buffersrc.h>
 
39
#include <libavutil/opt.h>
39
40
 
40
41
const char *filter_descr = "scale=78:24";
41
42
 
70
71
    }
71
72
    video_stream_index = ret;
72
73
    dec_ctx = fmt_ctx->streams[video_stream_index]->codec;
 
74
    av_opt_set_int(dec_ctx, "refcounted_frames", 1, 0);
73
75
 
74
76
    /* init the video decoder */
75
77
    if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) {
83
85
static int init_filters(const char *filters_descr)
84
86
{
85
87
    char args[512];
86
 
    int ret;
 
88
    int ret = 0;
87
89
    AVFilter *buffersrc  = avfilter_get_by_name("buffer");
88
90
    AVFilter *buffersink = avfilter_get_by_name("buffersink");
89
91
    AVFilterInOut *outputs = avfilter_inout_alloc();
90
92
    AVFilterInOut *inputs  = avfilter_inout_alloc();
91
93
    enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
92
 
    AVBufferSinkParams *buffersink_params;
93
94
 
94
95
    filter_graph = avfilter_graph_alloc();
 
96
    if (!outputs || !inputs || !filter_graph) {
 
97
        ret = AVERROR(ENOMEM);
 
98
        goto end;
 
99
    }
95
100
 
96
101
    /* buffer video source: the decoded frames from the decoder will be inserted here. */
97
102
    snprintf(args, sizeof(args),
104
109
                                       args, NULL, filter_graph);
105
110
    if (ret < 0) {
106
111
        av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
107
 
        return ret;
 
112
        goto end;
108
113
    }
109
114
 
110
115
    /* buffer video sink: to terminate the filter chain. */
111
 
    buffersink_params = av_buffersink_params_alloc();
112
 
    buffersink_params->pixel_fmts = pix_fmts;
113
116
    ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
114
 
                                       NULL, buffersink_params, filter_graph);
115
 
    av_free(buffersink_params);
 
117
                                       NULL, NULL, filter_graph);
116
118
    if (ret < 0) {
117
119
        av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
118
 
        return ret;
 
120
        goto end;
 
121
    }
 
122
 
 
123
    ret = av_opt_set_int_list(buffersink_ctx, "pix_fmts", pix_fmts,
 
124
                              AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
 
125
    if (ret < 0) {
 
126
        av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");
 
127
        goto end;
119
128
    }
120
129
 
121
130
    /* Endpoints for the filter graph. */
131
140
 
132
141
    if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,
133
142
                                    &inputs, &outputs, NULL)) < 0)
134
 
        return ret;
 
143
        goto end;
135
144
 
136
145
    if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
137
 
        return ret;
138
 
    return 0;
 
146
        goto end;
 
147
 
 
148
end:
 
149
    avfilter_inout_free(&inputs);
 
150
    avfilter_inout_free(&outputs);
 
151
 
 
152
    return ret;
139
153
}
140
154
 
141
155
static void display_frame(const AVFrame *frame, AVRational time_base)
228
242
                    display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base);
229
243
                    av_frame_unref(filt_frame);
230
244
                }
 
245
                av_frame_unref(frame);
231
246
            }
232
247
        }
233
248
        av_free_packet(&packet);
234
249
    }
235
250
end:
236
251
    avfilter_graph_free(&filter_graph);
237
 
    if (dec_ctx)
238
 
        avcodec_close(dec_ctx);
 
252
    avcodec_close(dec_ctx);
239
253
    avformat_close_input(&fmt_ctx);
240
254
    av_frame_free(&frame);
241
255
    av_frame_free(&filt_frame);
242
256
 
243
257
    if (ret < 0 && ret != AVERROR_EOF) {
244
 
        char buf[1024];
245
 
        av_strerror(ret, buf, sizeof(buf));
246
 
        fprintf(stderr, "Error occurred: %s\n", buf);
 
258
        fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
247
259
        exit(1);
248
260
    }
249
261