Any tool that can do median per base coverage over pre-defined windows from a BAM file?

I could make the actual per base coverage using `samtools depth` or `genomeCoverageBed`.

    chr pos read_depth
    1   1   6
    1   2   8
    ...

I already have the windows prepared using

    bedtools makewindows \
    	-g "genome.fa.fai" \
    	-w 1000 > "windows.bed"

I am looking for a result like below:

Median per base coverage over 1000bp windows

    chr start  end   median_read_depth
    1   1      1000  5
    1   1000   2000  8
    ...




I 've written : http://lindenb.github.io/jvarkit/BamStats04.html 

    $ java -jar dist/bamstats04.jar -B src/test/resources/toy.bed.gz src/test/resources/toy.bam 2> /dev/null | column -t 
    
    #chrom  start  end  length  sample  mincov  maxcov  meancov  mediancov  nocoveragebp  percentcovered
    ref     10     13   3       S1      3       3       3.0      3.0        0             100
    ref2    1      2    1       S1      2       2       2.0      2.0        0             100
    ref2    13     14   1       S1      6       6       6.0      6.0        0             100
    ref2    16     17   1       S1      6       6       6.0      6.0        0             100