Revision ec7ab610 libavfilter/vf_slicify.c

View differences:

libavfilter/vf_slicify.c
29 29
typedef struct {
30 30
    int h;          ///< output slice height
31 31
    int vshift;     ///< vertical chroma subsampling shift
32
    uint32_t lcg_state; ///< LCG state used to compute random slice height
33
    int use_random_h;   ///< enable the use of random slice height values
32 34
} SliceContext;
33 35

  
34 36
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
......
36 38
    SliceContext *slice = ctx->priv;
37 39

  
38 40
    slice->h = 16;
39
    if (args)
40
        sscanf(args, "%d", &slice->h);
41

  
41
    if (args) {
42
        if (!strcmp(args, "random")) {
43
            slice->use_random_h = 1;
44
        } else {
45
            sscanf(args, "%d", &slice->h);
46
        }
47
    }
42 48
    return 0;
43 49
}
44 50

  
......
48 54

  
49 55
    slice->vshift = av_pix_fmt_descriptors[link->format].log2_chroma_h;
50 56

  
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 57
    return 0;
58 58
}
59 59

  
......
65 65

  
66 66
static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
67 67
{
68
    SliceContext *slice = link->dst->priv;
69

  
70
    if (slice->use_random_h) {
71
        slice->lcg_state = slice->lcg_state * 1664525 + 1013904223;
72
        slice->h = 8 + (uint64_t)slice->lcg_state * 25 / UINT32_MAX;
73
    }
74

  
75
    /* ensure that slices play nice with chroma subsampling, and enforce
76
     * a reasonable minimum size for the slices */
77
    slice->h = FFMAX(8, slice->h & (-1 << slice->vshift));
78

  
79
    av_log(link->dst, AV_LOG_DEBUG, "h:%d\n", slice->h);
80

  
68 81
    avfilter_start_frame(link->dst->outputs[0], picref);
69 82
}
70 83

  

Also available in: Unified diff