Statistics
| Branch: | Revision:

ffmpeg / libavfilter / vf_slicify.c @ 5f6cb6eb

History | View | Annotate | Download (3.68 KB)

1 bc37ec92 Stefano Sabatini
/*
2
 * copyright (c) 2007 Bobby Bingham
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
/**
22
 * @file libavfilter/vf_slicify.c
23
 * video slicing filter
24
 */
25
26
#include "avfilter.h"
27
28
typedef struct {
29
    int h;          ///< output slice height
30
    int vshift;     ///< vertical chroma subsampling shift
31
} SliceContext;
32
33
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
34
{
35
    SliceContext *slice = ctx->priv;
36
37
    slice->h = 16;
38
    if (args)
39
        sscanf(args, "%d", &slice->h);
40
41
    return 0;
42
}
43
44
static int config_props(AVFilterLink *link)
45
{
46
    SliceContext *slice = link->dst->priv;
47
    int tmp;
48
49
    avcodec_get_chroma_sub_sample(link->format, &tmp, &slice->vshift);
50
51
    /* ensure that slices play nice with chroma subsampling, and enforce
52
     * a reasonable minimum size for the slices */
53
    slice->h = FFMAX(8, slice->h & (-1 << slice->vshift));
54
55
    av_log(link->dst, AV_LOG_INFO, "h:%d\n", slice->h);
56
57
    return 0;
58
}
59
60
static AVFilterPicRef *get_video_buffer(AVFilterLink *link, int perms,
61
                                        int w, int h)
62
{
63
    return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
64
}
65
66
static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
67
{
68
    avfilter_start_frame(link->dst->outputs[0], picref);
69
}
70
71
static void end_frame(AVFilterLink *link)
72
{
73
    avfilter_end_frame(link->dst->outputs[0]);
74
}
75
76 a13a5437 Stefano Sabatini
static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
77 bc37ec92 Stefano Sabatini
{
78
    SliceContext *slice = link->dst->priv;
79
    int y2;
80
81 bf972d5e Stefano Sabatini
    if (slice_dir == 1) {
82 3a1acfd7 Stefano Sabatini
        for (y2 = y; y2 + slice->h <= y + h; y2 += slice->h)
83
            avfilter_draw_slice(link->dst->outputs[0], y2, slice->h, slice_dir);
84 bc37ec92 Stefano Sabatini
85 3a1acfd7 Stefano Sabatini
        if (y2 < y + h)
86
            avfilter_draw_slice(link->dst->outputs[0], y2, y + h - y2, slice_dir);
87 bf972d5e Stefano Sabatini
    } else if (slice_dir == -1) {
88
        for (y2 = y + h; y2 - slice->h >= y; y2 -= slice->h)
89
            avfilter_draw_slice(link->dst->outputs[0], y2 - slice->h, slice->h, slice_dir);
90
91
        if (y2 > y)
92
            avfilter_draw_slice(link->dst->outputs[0], y, y2 - y, slice_dir);
93
    }
94 bc37ec92 Stefano Sabatini
}
95
96
AVFilter avfilter_vf_slicify = {
97
    .name      = "slicify",
98
    .description = "Pass the images of input video on to next video filter as multiple slices.",
99
100
    .init      = init,
101
102
    .priv_size = sizeof(SliceContext),
103
104
    .inputs    = (AVFilterPad[]) {{ .name             = "default",
105
                                    .type             = CODEC_TYPE_VIDEO,
106
                                    .get_video_buffer = get_video_buffer,
107
                                    .start_frame      = start_frame,
108
                                    .draw_slice       = draw_slice,
109
                                    .config_props     = config_props,
110
                                    .end_frame        = end_frame, },
111
                                  { .name = NULL}},
112
    .outputs   = (AVFilterPad[]) {{ .name            = "default",
113
                                    .type            = CODEC_TYPE_VIDEO, },
114
                                  { .name = NULL}},
115
};