2016-06-29 40 views

答えて

2

av_picture_crop()は、deprecatedである。

にlibavfilterにbufferbuffersinkフィルタを使用し、vf_cropを使用するには:

#include "libavfilter/avfilter.h" 

static AVFrame *crop_frame(const AVFrame *in, int left, int top, int right, int bottom) 
{ 
    AVFilterContext *buffersink_ctx; 
    AVFilterContext *buffersrc_ctx; 
    AVFilterGraph *filter_graph = avfilter_graph_alloc(); 
    AVFrame *f = av_frame_alloc(); 
    AVFilterInOut *inputs = NULL, *outputs = NULL; 
    char args[512]; 
    int ret; 
    snprintf(args, sizeof(args), 
      "buffer=video_size=%dx%d:pix_fmt=%d:time_base=1/1:pixel_aspect=0/1[in];" 
      "[in]crop=x=%d:y=%d:out_w=in_w-x-%d:out_h=in_h-y-%d[out];" 
      "[out]buffersink", 
      frame->width, frame->height, frame->format, 
      left, top, right, bottom); 

    ret = avfilter_graph_parse2(filter_graph, args, &inputs, &outputs); 
    if (ret < 0) return NULL; 
    assert(inputs == NULL && outputs == NULL); 
    ret = avfilter_graph_config(filter_graph, NULL); 
    if (ret < 0) return NULL; 

    buffersrc_ctx = avfilter_graph_get_filter(filter_graph, "Parsed_buffer_0"); 
    buffersink_ctx = avfilter_graph_get_filter(filter_graph, "Parsed_buffersink_2"); 
    assert(buffersrc_ctx != NULL); 
    assert(buffersink_ctx != NULL); 

    av_frame_ref(f, in); 
    ret = av_buffersrc_add_frame(buffersrc_ctx, f); 
    if (ret < 0) return NULL; 
    ret = av_buffersink_get_frame(buffersink_ctx, f); 
    if (ret < 0) return NULL; 

    avfilter_graph_free(&filter_graph); 

    return f; 
} 

av_frame_free()を使用して返さ(croppped)フレームをUNREFすることを忘れないでください。入力フレームデータは変更されていませんので、この機能を超える必要がない場合は、入力フレームもav_frame_free()にする必要があります。あなたは多くのフレームをトリミングする場合

は、ときにフレームサイズ/フォーマットの変更をフレーム間フィルタ・グラフを保持しだけをリセット(またはそれを再作成する)ことを試みます。私はそれをどのように行うかを理解するためにそれを残しています。

+0

ありがとうRonald、私は何とかav_picture_crop()で処理しましたが、非推奨の関数だと言ったので、私はあなたのソースコードでvf_crop関数を使って試してみます – eruslu

関連する問題