Getting resulting width and height from scale filter

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting resulting width and height from scale filter

Michael Bachmann
Is there a way to get the resulting width and height from a scale filter, so i can setup the Encoding-AVCodecContext correctly (with width and height)?


Here's my init filter method, which gets feeded with the filter description "scale=-1:'min(720,iw)'":


int FFMPEGCommands::init_filters(const char *filters_descr, int width, int height, int streamFrameRate)
{
    char args[512];
    int ret = 0;
    const AVFilter *buffersrc = avfilter_get_by_name("buffer");
    const AVFilter *buffersink = avfilter_get_by_name("buffersink");
    AVFilterInOut *outputs = avfilter_inout_alloc();
    AVFilterInOut *inputs = avfilter_inout_alloc();
    AVRational time_base = { 1, streamFrameRate };
    //AVRational time_base = fmt_ctx->streams[video_stream_index]->time_base;
    enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE };
    filter_graph = avfilter_graph_alloc();
    if (!outputs || !inputs || !filter_graph) {
        ret = AVERROR(ENOMEM);
        goto end;
    }
    /* buffer video source: the decoded frames from the decoder will be inserted here. */
    snprintf(args, sizeof(args),
        "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
        width, height, STREAM_PIX_FMT,
        time_base.num, time_base.den,
        0, 1);
    ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
        args, NULL, filter_graph);
    if (ret < 0) {
        av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
        goto end;
    }
    /* buffer video sink: to terminate the filter chain. */
    ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
        NULL, NULL, filter_graph);
    if (ret < 0) {
        av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
        goto end;
    }
    ret = av_opt_set_int_list(buffersink_ctx, "pix_fmts", pix_fmts,
        AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
    if (ret < 0) {
        av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");
        goto end;
    }
    /*
     * Set the endpoints for the filter graph. The filter_graph will
     * be linked to the graph described by filters_descr.
     */
     /*
      * The buffer source output must be connected to the input pad of
      * the first filter described by filters_descr; since the first
      * filter input label is not specified, it is set to "in" by
      * default.
      */
    outputs->name = av_strdup("in");
    outputs->filter_ctx = buffersrc_ctx;
    outputs->pad_idx = 0;
    outputs->next = NULL;
    /*
     * The buffer sink input must be connected to the output pad of
     * the last filter described by filters_descr; since the last
     * filter output label is not specified, it is set to "out" by
     * default.
     */
    inputs->name = av_strdup("out");
    inputs->filter_ctx = buffersink_ctx;
    inputs->pad_idx = 0;
    inputs->next = NULL;
    if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,
        &inputs, &outputs, NULL)) < 0)
        goto end;
    if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
        goto end;
end:
    avfilter_inout_free(&inputs);
    avfilter_inout_free(&outputs);
    return ret;
}

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Getting resulting width and height from scale filter

Lou Logan
On Thu, Feb 21, 2019, at 2:52 AM, Michael Bachmann wrote:
> Is there a way to get the resulting width and height from a scale
> filter, so i can setup the Encoding-AVCodecContext correctly (with
> width and height)?

This mailing list (ffmpeg-user) is only for questions involving the FFmpeg command-line tools (ffmpeg, ffplay, ffprobe). Usage questions involving the FFmpeg libraries (libavcodec, libavformat, etc) should be asked at libav-user.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Getting resulting width and height from scale filter

Michael Bachmann
Yeah, realized it myself and asked the question there. Thanks for the info anyway.


-----Urspr√ľngliche Nachricht-----
Von: ffmpeg-user <[hidden email]> Im Auftrag von Lou Logan
Gesendet: 21 February 2019 19:47
An: [hidden email]
Betreff: Re: [FFmpeg-user] Getting resulting width and height from scale filter

On Thu, Feb 21, 2019, at 2:52 AM, Michael Bachmann wrote:
> Is there a way to get the resulting width and height from a scale
> filter, so i can setup the Encoding-AVCodecContext correctly (with
> width and height)?

This mailing list (ffmpeg-user) is only for questions involving the FFmpeg command-line tools (ffmpeg, ffplay, ffprobe). Usage questions involving the FFmpeg libraries (libavcodec, libavformat, etc) should be asked at libav-user.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".