Beispiel #1
0
int av_buffersink_poll_frame(AVFilterContext *ctx)
{
    BufferSinkContext *buf = ctx->priv;
    AVFilterLink *inlink = ctx->inputs[0];

    return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + avfilter_poll_frame(inlink);
}
Beispiel #2
0
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
{
    AVFilterBufferRef *buf;
    mp_image_t *cmpi = NULL;

    if (!(mpi->flags & MP_IMGFLAG_DIRECT)) {
        cmpi = vf_get_image(vf, mpi->imgfmt, MP_IMGTYPE_TEMP,
                            MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
                            mpi->w, mpi->h);
        copy_mpi(cmpi, mpi);
        buf = cmpi->priv;
    } else {
        buf = mpi->priv;
    }
    buf->video->key_frame = mpi->pict_type == 1;
    buf->video->pict_type = mpi->pict_type; /* seems to be the same code */
    buf->video->interlaced = !!(mpi->fields & MP_IMGFIELD_INTERLACED);
    buf->video->top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
    vf->priv->in_buf = buf;
    if (pts != MP_NOPTS_VALUE)
        buf->pts = pts * AV_TIME_BASE;
    while (avfilter_poll_frame(vf->priv->out->inputs[0])) {
        if (avfilter_request_frame(vf->priv->out->inputs[0]))
            break;
    }
    return 1;
}
Beispiel #3
0
static int poll_frame(AVFilterLink *link)
{
    FPSContext *fps = link->src->priv;

    if (fps->has_frame)
        return 1;

    if(avfilter_poll_frame(link->src->inputs[0]) &&
       avfilter_request_frame(link->src->inputs[0])) {
        fps->videoend = 1;
        return 1;
    }

    fps->has_frame = !!(fps->pic && fps->pic->pts >= fps->pts);
    return fps->has_frame;
}
Beispiel #4
0
int avfilter_poll_frame(AVFilterLink *link)
{
    int i, min = INT_MAX;

    if (link->srcpad->poll_frame)
        return link->srcpad->poll_frame(link);

    for (i = 0; i < link->src->input_count; i++) {
        int val;
        if (!link->src->inputs[i])
            return -1;
        val = avfilter_poll_frame(link->src->inputs[i]);
        min = FFMIN(min, val);
    }

    return min;
}
Beispiel #5
0
static int poll_frame(AVFilterLink *outlink)
{
    SelectContext *select = outlink->src->priv;
    AVFilterLink *inlink = outlink->src->inputs[0];
    int count, ret;

    if (!av_fifo_size(select->pending_frames)) {
        if ((count = avfilter_poll_frame(inlink)) <= 0)
            return count;
        /* request frame from input, and apply select condition to it */
        select->cache_frames = 1;
        while (count-- && av_fifo_space(select->pending_frames)) {
            ret = avfilter_request_frame(inlink);
            if (ret < 0)
                break;
        }
        select->cache_frames = 0;
    }

    return av_fifo_size(select->pending_frames)/sizeof(AVFilterBufferRef *);
}
int filter(AVFrame* src, AVFrame *dst)
{
    int ret;
    AVFilterBufferRef *picref;

    /* push the decoded frame into the filtergraph. 3rd parameter might not be needed with new ffmpeg */
    av_vsrc_buffer_add_frame(buffersrc_ctx, src, 0);

    /* pull filtered pictures from the filtergraph */
    ret = avfilter_poll_frame(buffersink_ctx->inputs[0]);
    if (ret > 0) {
        av_vsink_buffer_get_video_buffer_ref(buffersink_ctx, &picref, 0);
        if (picref) {
            avfilter_fill_frame_from_video_buffer_ref(dst, picref);
            dst->pts = picref->pts;
            avfilter_unref_buffer(picref);
        }
    }
    if (ret != 1) {
        av_log(NULL, AV_LOG_WARNING, "filter unexpected number of immediately available frames: %d\n", ret);
    }

    return ret;
}
Beispiel #7
0
int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
{
    BufferSinkContext *sink = ctx->priv;
    AVFilterLink      *link = ctx->inputs[0];
    int ret;

    if (!buf) {
        if (av_fifo_size(sink->fifo))
            return av_fifo_size(sink->fifo)/sizeof(*buf);
        else
            return avfilter_poll_frame(ctx->inputs[0]);
    }

    if (!av_fifo_size(sink->fifo) &&
        (ret = avfilter_request_frame(link)) < 0)
        return ret;

    if (!av_fifo_size(sink->fifo))
        return AVERROR(EINVAL);

    av_fifo_generic_read(sink->fifo, buf, sizeof(*buf), NULL);

    return 0;
}
int main(int argc, char **argv)
{
    int ret;
    AVPacket packet;
    AVFrame frame;
    int got_frame;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s file | %s\n", argv[0], player);
        exit(1);
    }

    avcodec_register_all();
    av_register_all();
    avfilter_register_all();

    if ((ret = open_input_file(argv[1])) < 0)
        goto end;
    if ((ret = init_filters(filter_descr)) < 0)
        goto end;

    /* read all packets */
    while (1) {
        AVFilterBufferRef *samplesref;
        if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
            break;

        if (packet.stream_index == audio_stream_index) {
            avcodec_get_frame_defaults(&frame);
            got_frame = 0;
            ret = avcodec_decode_audio4(dec_ctx, &frame, &got_frame, &packet);
            av_free_packet(&packet);
            if (ret < 0) {
                av_log(NULL, AV_LOG_ERROR, "Error decoding audio\n");
                continue;
            }

            if (got_frame) {
                /* push the audio data from decoded frame into the filtergraph */
                if (av_buffersrc_add_frame(buffersrc_ctx, &frame, 0) < 0) {
                    av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");
                    break;
                }

                /* pull filtered audio from the filtergraph */
                while (avfilter_poll_frame(buffersink_ctx->inputs[0])) {
                    av_buffersink_get_buffer_ref(buffersink_ctx, &samplesref, 0);
                    if (samplesref) {
                        print_samplesref(samplesref);
                        avfilter_unref_buffer(samplesref);
                    }
                }
            }
        }
    }
end:
    avfilter_graph_free(&filter_graph);
    if (dec_ctx)
        avcodec_close(dec_ctx);
    avformat_close_input(&fmt_ctx);

    if (ret < 0 && ret != AVERROR_EOF) {
        char buf[1024];
        av_strerror(ret, buf, sizeof(buf));
        fprintf(stderr, "Error occurred: %s\n", buf);
        exit(1);
    }

    exit(0);
}