text:
using StochasticDiffEq, DiffEqProblemLibrary, Random, Base.Threads
using DiffEqProblemLibrary.SDEProblemLibrary: importsdeproblems; importsdeproblems()
prob = DiffEqProblemLibrary.SDEProblemLibrary.oval2ModelExample(largeFluctuations=true,useBigs=false)
prob_func(prob,i,repeat) = remake(prob,seed=i)
prob = EnsembleProblem(remake(prob,tspan=(0.0,1.0)),prob_func=prob_func)
js = 16:21
dts = 1.0 ./ 2.0 .^ (js)
trajectories = 1000
fails = Array{Int}(undef,length(dts),3)
times = Array{Float64}(undef,length(dts),3)

sol = solve(prob,SRIW1(),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-7),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SRIW1(),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-7),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? Inf : adaptive_time
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SRI(error_terms=2),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-7),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SRI(error_terms=2),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-7),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SRI(),EnsembleThreads(),abstol=2.0^(-14),reltol=2.0^(-18),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SRI(),EnsembleThreads(),abstol=2.0^(-14),reltol=2.0^(-18),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SRI(tableau=StochasticDiffEq.constructSRIOpt1()),EnsembleThreads(),abstol=2.0^(-7),reltol=2.0^(-4),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SRI(tableau=StochasticDiffEq.constructSRIOpt1()),EnsembleThreads(),abstol=2.0^(-7),reltol=2.0^(-4),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-7),reltol=2.0^(-4),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-7),reltol=2.0^(-4),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-7),reltol=2.0^(-6),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-7),reltol=2.0^(-6),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-12),reltol=2.0^(-15),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-12),reltol=2.0^(-15),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-7),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-7),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-12),reltol=2.0^(-15),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SOSRI(),EnsembleThreads(),abstol=2.0^(-12),reltol=2.0^(-15),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SOSRI2(),EnsembleThreads(),abstol=2.0^(-12),reltol=2.0^(-15),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SOSRI2(),EnsembleThreads(),abstol=2.0^(-12),reltol=2.0^(-15),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SOSRI2(),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-11),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SOSRI2(),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-11),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

sol = solve(prob,SOSRI2(),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-11),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=Threads.nthreads())
adaptive_time = @elapsed sol = solve(prob,SOSRI2(),EnsembleThreads(),abstol=2.0^(-13),reltol=2.0^(-11),maxiters=Int(1e11),qmax=1.125,save_everystep=false,trajectories=trajectories)
numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
best_adaptive_time = numfails != 0 ? adaptive_time : min(best_adaptive_time,adaptive_time)
println("The number of Adaptive Fails is $numfails. Elapsed time was $adaptive_time")

for j in eachindex(js)
  println("j = $j")
  sol =solve(prob,EM(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=Threads.nthreads())
  t1 = @elapsed sol = solve(prob,EM(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=trajectories)
  numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
  println("The number of Euler-Maruyama Fails is $numfails. Elapsed time was $t1")
  fails[j,1] = numfails
  times[j,1] = t1
end

for j in 1:4
  println("j = $j")
  sol =solve(prob,SRIW1(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=Threads.nthreads())
  t1 = @elapsed sol = solve(prob,SRIW1(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=trajectories)
  numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
  println("The number of SRIW1 Fails is $numfails. Elapsed time was $t1")
  fails[j,3] = numfails
  times[j,3] = t1
end

js = 17:21
dts = 1.0 ./2.0 .^ (js)
for j in 1:6
  println("j = $j")
  sol =solve(prob,ImplicitEM(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=Threads.nthreads())
  t1 = @elapsed sol = solve(prob,ImplicitEM(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=trajectories)
  numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
  println("The number of Implicit-EM Fails is $numfails. Elapsed time was $t1")
end

js = 17:21
dts = 1.0 ./ 2.0 .^(js)

for j in 1:6
  println("j = $j")
  sol =solve(prob,ImplicitRKMil(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=Threads.nthreads())
  t1 = @elapsed sol = solve(prob,ImplicitRKMil(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=trajectories)
  numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
  println("The number of Implicit-RKMil Fails is $numfails. Elapsed time was $t1")
end

for j in 1:6
  println("j = $j")
  sol =solve(prob,RKMil(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=Threads.nthreads())
  t1 = @elapsed sol = solve(prob,RKMil(),EnsembleThreads(),dt=dts[j],maxiters=Int(1e11),save_everystep=false,verbose=false,trajectories=trajectories)
  numfails = sum([Int(any(isnan,sol[i]) || sol[i].t[end] != 1) for i in 1:trajectories])
  println("The number of RKMil Fails is $numfails. Elapsed time was $t1")
  fails[j,2] = numfails
  times[j,2] = t1
end

using Plots
lw = 3
p2 = plot(dts,times,xscale=:log2,yscale=:log2,guidefont=font(16),tickfont=font(14),yguide="Elapsed Time (s)",xguide=L"Chosen $\Delta t$",top_margin=50px,linewidth=lw,lab=["Euler-Maruyama" "RK-Mil" "RosslerSRI"],legendfont=font(14))
plot!(dts,repmat([best_adaptive_time],11),linewidth=lw,line=:dash,lab="ESRK+RSwM3",left_margin=75px)
scatter!([2.0^(-20);2.0^(-20);2.0^(-18)],[times[5,1];times[5,2];times[3,3]],markersize=20,c=:red,lab="")
plot(p2,size=(800,800))

using DiffEqBenchmarks
DiffEqBenchmarks.bench_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])


text:
using Colors
import OnlineStats
using DataFrames

# Islands are collects of adjacent CartesianIndex with their population count.  The first CartesianIndex is maintained
# as the one with the largest population. Internal use only.
Island = Vector{Tuple{CartesianIndex,Int}}

# This function converts the data values into bin index
defbin(x) = floor(Integer, min(1.0, max(0.0, x)) * 25.0)

# Are two CartesianIndex(s) adjacent?
adj(ci1::CartesianIndex, ci2::CartesianIndex) = sum(abs(ci1.I[i] - ci2.I[i]) for i in eachindex(ci1.I)) <= 1
# Is this CartesianIndex adjacent to the island cis2?
adj(ci::CartesianIndex, cis2::Island) = any(adj(ci, ci2[1]) for ci2 in cis2)
# Are two islands of CartesianIndex(s) adjacent by any CI within an island being adjacent to a CI from the other island?
adj(cis1::Island, cis2::Island) = any(adj(ci[1], cis2) for ci in cis1)

# The height of an island is the count in the first (highest) bin
height(isl::Island) = isl[1][2]

# Are two islands of heights `h1` and `h2` connected by the index `ci` of height `hi`?
defconnects(ci::CartesianIndex, hi::Int, h1::Int, h2::Int, σ::Float64 = 3.0) = hi > min(h1, h2) - σ * sqrt(min(h1, h2))

"""
Clusters N-dimensional data using an algorithm based on a N-dimensional histogram.  The data is summarized in an
N-dimensional histogram.  The bins are sorted according to population count.  Starting with the most populous bin,
adjacent bins are joined into islands according to the following rules.  If a bin is adjacent to one island then the
bin is added to the island.  If the bin is adjacent to two islands and it's population exceeds a threshold of the
highest bin in each island, then the islands are joined together into a larger island.  If the bin height is less than
the threshold, the bin is added to the less island with the smaller highest bin.  So constructed, each island represents
a cluster.  The clusters are assigned integer indexes starting at 1 and cluster assignments for each pixel are written
to an `Array`.

This algorithm is best for data like compositional data which is naturally normalized to a unity sum and for which
each layer in the data is on an equivalent scale.  The algorithm can be extended to work with other data types or the
data can be preprocessed to bring it onto an equivalent scale.
"""
struct DiluvianCluster
  labels::Vector
  # An Vector of planes of data Arrays (one for each label)
  data::Vector{Array}
  # An Array containing the cluster assignment
  clusters::Array{Int16}
  # Cached cluster count
  count::Int

  function DiluvianCluster(df::AbstractDataFrame, bin::Function = defbin, connects::Function = defconnects)
    return DiluvianCluster(names(df), [ df[:, name] for name in names ], bin=bin, connects=connects)
  end

  function DiluvianCluster(
    labels::Vector,
    data::Vector{<:AbstractArray};
    bin::Function = defbin,
    connects::Function = defconnects,
  )
    @assert length(labels) == length(data) "length(labels) must equal length(data)"
    @assert all(size(data[1]) == size(datum) for datum in data[2:end]) "The arrays in data must all be the same size."
    islands = flood(buildhistogram(data, bin), connects)
    clusters = buildclusters(islands, data, bin)
    return new(labels, data, clusters, length(islands))
  end

  function DiluvianCluster(labeleddata::Tuple{Any,AbstractArray}...; bin::Function = defbin, connects::Function = defconnects)
    lbls = [lbl for (lbl, _) in labeleddata]
    data = [arr for (_, arr) in labeleddata]
    return DiluvianCluster(lbls, data, bin = bin, connects = connects)
  end
end

Base.show(io::IO, dc::DiluvianCluster) = print(io, "DiluvianCluster[$(dc.count) clusters]")

# Bin the data in a N-dimensional histogram
function buildhistogram(data::Vector{<:AbstractArray}, bin::Function)
  binindex = (ci, data, bin) -> CartesianIndex((bin(datum[ci]) for datum in data)...)
  hist = Dict{CartesianIndex,Integer}()
  for ci in CartesianIndices(data[1])
    cc = binindex(ci, data, bin)
    hist[cc] = get(hist, cc, 0) + 1
  end
  return hist
end

# Construct islands by joining adjacent bins unless there is a valley between peaks
function flood(hist::Dict{CartesianIndex,Integer}, connects::Function)::Vector{Island}
  dist(ci, isl) = sum((ci.I .- isl[1][1].I) .^ 2)
  # Sort by bins by height (highest first)
  shist = sort([(ci, n) for (ci, n) in hist], lt = (a, b) -> a[2] > b[2])
  islands = Vector{Island}()  # Maintained in height(island) order (highest first)
  for (ci, n) in shist
    added = false
    for (i1, isl1) in enumerate(islands)
      if adj(ci, isl1)
        rm, h1 = [], height(isl1)
        # Add ci to the closest adjacent peak
        closest, cdist = isl1, dist(ci, isl1)
        # Is ci adjacent to any other islands?
        for i2 in i1+1:length(islands)
          isl2 = islands[i2]
          if adj(ci, isl2)
            if connects(ci, n, h1, height(isl2))
              append!(isl1, isl2)
              push!(rm, i2)
              # The bin ci connects isl1 to isl2 so always add it to isl1
              closest, cdist = isl1, 0
            else
              if dist(ci, isl2) < cdist
                # ci is closer to the peak of isl2 than closest
                closest, cdist = isl2, dist(ci, isl2)
              end
            end
          end
        end
        added = true
        push!(closest, (ci, n))
        deleteat!(islands, rm)
        break
      end
    end
    if !added # create a new Island which is shorter than all previous Islands
      push!(islands, [(ci, n)])
    end
  end
  binsum = isl -> sum(n for (_, n) in isl)
  return sort!(islands, lt = (a, b) -> binsum(a) < binsum(b), rev = true)
end

# Build an array summarizing cluster membership
function buildclusters(islands::Vector{Island}, data::Vector{<:Array}, bin::Function)::Array{UInt16}
  binindex = (ci, data, bin) -> CartesianIndex((bin(datum[ci]) for datum in data)...)
  idxforci = Dict{CartesianIndex,UInt16}(ci => i for (i, island) in enumerate(islands) for (ci, _) in island)
  return map(ci -> idxforci[binindex(ci, data, bin)], CartesianIndices(data[1]))
end

Base.length(dc::DiluvianCluster) = dc.count
Base.eachindex(dc::DiluvianCluster) = Base.OneTo(dc.count)

"""
    asimage(dc::DiluvianCluster, colors::Vector{Colorant}, other = colorant"black")::Array{Colorant}
    asimage(dc::DiluvianCluster)

Get a colorized image when the first `length(colors)` clusters are colored according to `colors` and the
remainder are `other`. The second version uses `distinguishable_colors(…)` to generate the enough colors
automatically.
"""
asimage(dc::DiluvianCluster, colors::Vector{<:Colorant}, other = colorant"black")::Array{<:Colorant} =
  map(v -> get(colors, v, other), dc.clusters)

defaultpalette(dc::DiluvianCluster) = distinguishable_colors(length(dc), colorant"yellow")

asimage(dc::DiluvianCluster) = asimage(dc, defaultpalette(dc))

"""
    asa(::Type{DataFrame}, dc::DiluvianCluster, cluster::Int)::DataFrame

Create a DataFrame with the data from each pixel in `cluster`.
"""
function NeXLUncertainties.asa(::Type{DataFrame}, dc::DiluvianCluster, cluster::Int)::DataFrame
  cis = collect(filter(ci -> dc.clusters[ci] == cluster, CartesianIndices(dc.clusters)))
  df = DataFrame(Cluster = [cluster for _ in cis], Index = cis)
  for (i, lbl) in enumerate(dc.labels)
    datum = dc.data[i]
    insertcols!(df, "$lbl" => [datum[ci] for ci in cis])
  end
  return df
end

"""
    asmask(dc::DiluvianCluster, cluster::Int)

Get a Bool mask for the specified cluster
"""
asmask(dc::DiluvianCluster, cluster::Int)::BitArray =
  BitArray(dc.clusters[ci] == cluster for ci in CartesianIndices(dc.clusters))

"""
  clusters(dc::DiluvianCluster)::Array{UInt16}

Returns an Array containing the cluster assignment as an integer index.
"""
clusters(dc::DiluvianCluster) = dc.clusters

"""
    membercounts(dc::DiluvianCluster)

How many data points are there in each cluster?
"""
membercounts(dc::DiluvianCluster) = [count(v -> v == cl, dc.clusters) for cl = 1:length(dc)]
Base.count(dc::DiluvianCluster, i::Integer) = count(v -> v == i, dc.clusters)

function clusterstats(dc::DiluvianCluster, cluster::Int)
  stats = Dict(lbl => Series(Mean(), Variance(), Extrema()) for lbl in dc.labels)
  cis = filter(ci -> dc.clusters[ci] == cluster, CartesianIndices(dc.clusters))
  for (i, lbl) in enumerate(dc.labels)
    fit!(stats[lbl], (dc.data[i][ci] for ci in cis))
  end
  return stats
end

function clusterstats(dc::DiluvianCluster, clusters::Vector{Int})
  cls = Set(clusters)
  stats = Dict(lbl => Series(Mean(), Variance(), Extrema()) for lbl in dc.labels)
  cis = filter(ci -> dc.clusters[ci] in cls, CartesianIndices(dc.clusters))
  for (i, lbl) in enumerate(dc.labels)
    fit!(stats[lbl], (dc.data[i][ci] for ci in cis))
  end
  return stats
end

function summarizeclusters(dc::DiluvianCluster; statistics = false, sorted = true)
  dcidx = Base.OneTo(length(dc))
  stats = [Series(Mean(), Variance(), Extrema()) for cl in dcidx, lbl in dc.labels]
  for (ii, cl) in enumerate(dc.clusters), lbli in eachindex(dc.labels)
    fit!(stats[cl, lbli], dc.data[lbli][ii])
  end
  res = DataFrame(Cluster = collect(dcidx), Count = membercounts(dc))
  sl = [ (i, dc.labels[i]) for i in eachindex(dc.labels)]
  if sorted
    sort!(sl , lt=(a,b)->a[2]<b[2])
  end
  for i in eachindex(sl)
    (lbli, lbl) = sl[i]
    insertcols!(res, "$lbl" => [OnlineStats.value(stats[cl, lbli].stats[1]) for cl in dcidx])
    if statistics
      insertcols!(res, "σ[$lbl]" => [sqrt(OnlineStats.value(stats[cl, lbli].stats[2])) for cl in dcidx])
      insertcols!(res, "min[$lbl]" => [minimum(stats[cl, lbli].stats[3]) for cl in dcidx])
      insertcols!(res, "max[$lbl]" => [maximum(stats[cl, lbli].stats[3]) for cl in dcidx])
    end
  end
  return res
end

"""
    multiternary(dc::DiluvianCluster, cluster::Int; maxitems=1000, norm=1.0, palette = nothing, variance = false)

Plot the data from the specified cluster from most significant dimensions as ternary diagram.
`maxitems` limits the total number of points plotted when there are a very large number of data points.
`norm` is useful if the data is normalized to something other than unity.
`palette` defaults to the same default palette as toimage(…) or can be specified as `Colorant[]`
`variance` determines whether maximum mean value or maximum variance is used to select elements to plot
"""
function multiternary(dc::DiluvianCluster, clusters::Vector{Int}; maxitems = 1000, norm = 1.0, palette = nothing, variance = false)
  sts = [(OnlineStats.value(s.stats[variance ? 2 : 1]), lbl) for (lbl, s) in clusterstats(dc, clusters)]
  sort!(sts, lt = (a, b) -> a[1] > b[1])
  cols = [Symbol(st[2]) for st in sts]
  df = mapreduce(cluster -> asa(DataFrame, dc, cluster), vcat, clusters)
  insertcols!(df, :Randomizer => randperm(nrow(df)))
  sort!(df, :Randomizer)
  df = nrow(df) > maxitems ? df[1:maxitems, :] : df
  if isnothing(palette)
    palette = distinguishable_colors(length(dc), colorant"yellow")[clusters]
  end
  return multiternary(df, cols, :Cluster, norm = norm, withcount = false, palette = palette)
end

ext: jl

max_stars_repo_name: NicholasWMRitchie/NeXLParticle

max_issues_repo_name: NicholasWMRitchie/NeXLParticle

max_forks_repo_name: NicholasWMRitchie/NeXLParticle


text:
using MushroomBody
using Test

@testset "MushroomBody.jl" begin
    # Write your own tests here.
end


text:
using ReproducePlotUtils
using Test

@testset "ReproducePlotUtils.jl" begin
    # Write your tests here.
end


text:
import Base.zero

export
    SampleFormat,
    SAMPLE_FMT_NONE,
    SAMPLE_FMT_U8,
    SAMPLE_FMT_S16,
    SAMPLE_FMT_S32,
    SAMPLE_FMT_FLT,
    SAMPLE_FMT_DBL,
    SAMPLE_FMT_NB,
    CH_FRONT_LEFT,
    CH_FRONT_RIGHT,
    CH_FRONT_CENTER,
    CH_LOW_FREQUENCY,
    CH_BACK_LEFT,
    CH_BACK_RIGHT,
    CH_FRONT_LEFT_OF_CENTER,
    CH_FRONT_RIGHT_OF_CENTER,
    CH_BACK_CENTER,
    CH_SIDE_LEFT,
    CH_SIDE_RIGHT,
    CH_TOP_CENTER,
    CH_TOP_FRONT_LEFT,
    CH_TOP_FRONT_CENTER,
    CH_TOP_FRONT_RIGHT,
    CH_TOP_BACK_LEFT,
    CH_TOP_BACK_CENTER,
    CH_TOP_BACK_RIGHT,
    CH_STEREO_LEFT,
    CH_STEREO_RIGHT,
    CH_LAYOUT_NATIVE,
    CH_LAYOUT_MONO,
    CH_LAYOUT_STEREO,
    CH_LAYOUT_2_1,
    CH_LAYOUT_SURROUND,
    CH_LAYOUT_4POINT0,
    CH_LAYOUT_2_2,
    CH_LAYOUT_QUAD,
    CH_LAYOUT_5POINT0,
    CH_LAYOUT_5POINT1,
    CH_LAYOUT_5POINT0_BACK,
    CH_LAYOUT_5POINT1_BACK,
    CH_LAYOUT_7POINT0,
    CH_LAYOUT_7POINT1,
    CH_LAYOUT_7POINT1_WIDE,
    CH_LAYOUT_STEREO_DOWNMIX,
    AVCODEC_MAX_AUDIO_FRAME_SIZE,
    CODEC_FLAG_QSCALE,
    CODEC_FLAG_4MV,
    CODEC_FLAG_QPEL,
    CODEC_FLAG_GMC,
    CODEC_FLAG_MV0,
    CODEC_FLAG_INPUT_PRESERVED,
    CODEC_FLAG_PASS1,
    CODEC_FLAG_PASS2,
    CODEC_FLAG_GRAY,
    CODEC_FLAG_EMU_EDGE,
    CODEC_FLAG_PSNR,
    CODEC_FLAG_TRUNCATED,
    CODEC_FLAG_NORMALIZE_AQP,
    CODEC_FLAG_INTERLACED_DCT,
    CODEC_FLAG_LOW_DELAY,
    CODEC_FLAG_GLOBAL_HEADER,
    CODEC_FLAG_BITEXACT,
    CODEC_FLAG_AC_PRED,
    CODEC_FLAG_CBP_RD,
    CODEC_FLAG_QP_RD,
    CODEC_FLAG_LOOP_FILTER,
    CODEC_FLAG_INTERLACED_ME,
    CODEC_FLAG_CLOSED_GOP,
    CODEC_FLAG2_FAST,
    CODEC_FLAG2_STRICT_GOP,
    CODEC_FLAG2_NO_OUTPUT,
    CODEC_FLAG2_LOCAL_HEADER,
    CODEC_FLAG2_SKIP_RD,
    CODEC_FLAG2_CHUNKS,
    CODEC_FLAG_OBMC,
    CODEC_FLAG_H263P_AIV,
    CODEC_FLAG_PART,
    CODEC_FLAG_ALT_SCAN,
    CODEC_FLAG_H263P_UMV,
    CODEC_FLAG_H263P_SLICE_STRUCT,
    CODEC_FLAG_SVCD_SCAN_OFFSET,
    CODEC_FLAG2_INTRA_VLC,
    CODEC_FLAG2_DROP_FRAME_TIMECODE,
    CODEC_FLAG2_NON_LINEAR_QUANT,
    CODEC_FLAG_EXTERN_HUFF,
    CODEC_FLAG2_BPYRAMID,
    CODEC_FLAG2_WPRED,
    CODEC_FLAG2_MIXED_REFS,
    CODEC_FLAG2_8X8DCT,
    CODEC_FLAG2_FASTPSKIP,
    CODEC_FLAG2_AUD,
    CODEC_FLAG2_BRDO,
    CODEC_FLAG2_MBTREE,
    CODEC_FLAG2_PSY,
    CODEC_FLAG2_SSIM,
    CODEC_FLAG2_INTRA_REFRESH,
    CODEC_FLAG2_MEMC_ONLY,
    CODEC_FLAG2_BIT_RESERVOIR,
    CODEC_CAP_DRAW_HORIZ_BAND,
    CODEC_CAP_DR1,
    CODEC_CAP_PARSE_ONLY,
    CODEC_CAP_TRUNCATED,
    CODEC_CAP_HWACCEL,
    CODEC_CAP_DELAY,
    CODEC_CAP_SMALL_LAST_FRAME,
    CODEC_CAP_HWACCEL_VDPAU,
    CODEC_CAP_SUBFRAMES,
    CODEC_CAP_EXPERIMENTAL,
    CODEC_CAP_CHANNEL_CONF,
    CODEC_CAP_NEG_LINESIZES,
    CODEC_CAP_FRAME_THREADS,
    CODEC_CAP_SLICE_THREADS,
    CODEC_CAP_PARAM_CHANGE,
    CODEC_CAP_AUTO_THREADS,
    CODEC_CAP_VARIABLE_FRAME_SIZE,
    MB_TYPE_INTRA4x4,
    MB_TYPE_INTRA16x16,
    MB_TYPE_INTRA_PCM,
    MB_TYPE_16x16,
    MB_TYPE_16x8,
    MB_TYPE_8x16,
    MB_TYPE_8x8,
    MB_TYPE_INTERLACED,
    MB_TYPE_DIRECT2,
    MB_TYPE_ACPRED,
    MB_TYPE_GMC,
    MB_TYPE_SKIP,
    MB_TYPE_P0L0,
    MB_TYPE_P1L0,
    MB_TYPE_P0L1,
    MB_TYPE_P1L1,
    MB_TYPE_L0,
    MB_TYPE_L1,
    MB_TYPE_L0L1,
    MB_TYPE_QUANT,
    MB_TYPE_CBP,
    AV_PKT_FLAG_KEY,
    AV_PKT_FLAG_CORRUPT,
    AV_NUM_DATA_POINTERS,
    SLICE_FLAG_CODED_ORDER,
    SLICE_FLAG_ALLOW_FIELD,
    SLICE_FLAG_ALLOW_PLANE,
    X264_PART_I4X4,
    X264_PART_I8X8,
    X264_PART_P8X8,
    X264_PART_P4X4,
    X264_PART_B8X8,
    AV_EF_CRCCHECK,
    AV_EF_BITSTREAM,
    AV_EF_BUFFER,
    AV_EF_EXPLODE,
    AVPALETTE_SIZE,
    AVPALETTE_COUNT,
    AV_PARSER_PTS_NB,
    PARSER_FLAG_COMPLETE_FRAMES,
    PARSER_FLAG_ONCE,
    PARSER_FLAG_FETCHED_OFFSET,
    CodecID,
    CODEC_ID_NONE,
    CODEC_ID_MPEG1VIDEO,
    CODEC_ID_MPEG2VIDEO,
    CODEC_ID_MPEG2VIDEO_XVMC,
    CODEC_ID_H261,
    CODEC_ID_H263,
    CODEC_ID_RV10,
    CODEC_ID_RV20,
    CODEC_ID_MJPEG,
    CODEC_ID_MJPEGB,
    CODEC_ID_LJPEG,
    CODEC_ID_SP5X,
    CODEC_ID_JPEGLS,
    CODEC_ID_MPEG4,
    CODEC_ID_RAWVIDEO,
    CODEC_ID_MSMPEG4V1,
    CODEC_ID_MSMPEG4V2,
    CODEC_ID_MSMPEG4V3,
    CODEC_ID_WMV1,
    CODEC_ID_WMV2,
    CODEC_ID_H263P,
    CODEC_ID_H263I,
    CODEC_ID_FLV1,
    CODEC_ID_SVQ1,
    CODEC_ID_SVQ3,
    CODEC_ID_DVVIDEO,
    CODEC_ID_HUFFYUV,
    CODEC_ID_CYUV,
    CODEC_ID_H264,
    CODEC_ID_INDEO3,
    CODEC_ID_VP3,
    CODEC_ID_THEORA,
    CODEC_ID_ASV1,
    CODEC_ID_ASV2,
    CODEC_ID_FFV1,
    CODEC_ID_4XM,
    CODEC_ID_VCR1,
    CODEC_ID_CLJR,
    CODEC_ID_MDEC,
    CODEC_ID_ROQ,
    CODEC_ID_INTERPLAY_VIDEO,
    CODEC_ID_XAN_WC3,
    CODEC_ID_XAN_WC4,
    CODEC_ID_RPZA,
    CODEC_ID_CINEPAK,
    CODEC_ID_WS_VQA,
    CODEC_ID_MSRLE,
    CODEC_ID_MSVIDEO1,
    CODEC_ID_IDCIN,
    CODEC_ID_8BPS,
    CODEC_ID_SMC,
    CODEC_ID_FLIC,
    CODEC_ID_TRUEMOTION1,
    CODEC_ID_VMDVIDEO,
    CODEC_ID_MSZH,
    CODEC_ID_ZLIB,
    CODEC_ID_QTRLE,
    CODEC_ID_SNOW,
    CODEC_ID_TSCC,
    CODEC_ID_ULTI,
    CODEC_ID_QDRAW,
    CODEC_ID_VIXL,
    CODEC_ID_QPEG,
    CODEC_ID_PNG,
    CODEC_ID_PPM,
    CODEC_ID_PBM,
    CODEC_ID_PGM,
    CODEC_ID_PGMYUV,
    CODEC_ID_PAM,
    CODEC_ID_FFVHUFF,
    CODEC_ID_RV30,
    CODEC_ID_RV40,
    CODEC_ID_VC1,
    CODEC_ID_WMV3,
    CODEC_ID_LOCO,
    CODEC_ID_WNV1,
    CODEC_ID_AASC,
    CODEC_ID_INDEO2,
    CODEC_ID_FRAPS,
    CODEC_ID_TRUEMOTION2,
    CODEC_ID_BMP,
    CODEC_ID_CSCD,
    CODEC_ID_MMVIDEO,
    CODEC_ID_ZMBV,
    CODEC_ID_AVS,
    CODEC_ID_SMACKVIDEO,
    CODEC_ID_NUV,
    CODEC_ID_KMVC,
    CODEC_ID_FLASHSV,
    CODEC_ID_CAVS,
    CODEC_ID_JPEG2000,
    CODEC_ID_VMNC,
    CODEC_ID_VP5,
    CODEC_ID_VP6,
    CODEC_ID_VP6F,
    CODEC_ID_TARGA,
    CODEC_ID_DSICINVIDEO,
    CODEC_ID_TIERTEXSEQVIDEO,
    CODEC_ID_TIFF,
    CODEC_ID_GIF,
    CODEC_ID_FFH264,
    CODEC_ID_DXA,
    CODEC_ID_DNXHD,
    CODEC_ID_THP,
    CODEC_ID_SGI,
    CODEC_ID_C93,
    CODEC_ID_BETHSOFTVID,
    CODEC_ID_PTX,
    CODEC_ID_TXD,
    CODEC_ID_VP6A,
    CODEC_ID_AMV,
    CODEC_ID_VB,
    CODEC_ID_PCX,
    CODEC_ID_SUNRAST,
    CODEC_ID_INDEO4,
    CODEC_ID_INDEO5,
    CODEC_ID_MIMIC,
    CODEC_ID_RL2,
    CODEC_ID_8SVX_EXP,
    CODEC_ID_8SVX_FIB,
    CODEC_ID_ESCAPE124,
    CODEC_ID_DIRAC,
    CODEC_ID_BFI,
    CODEC_ID_CMV,
    CODEC_ID_MOTIONPIXELS,
    CODEC_ID_TGV,
    CODEC_ID_TGQ,
    CODEC_ID_TQI,
    CODEC_ID_AURA,
    CODEC_ID_AURA2,
    CODEC_ID_V210X,
    CODEC_ID_TMV,
    CODEC_ID_V210,
    CODEC_ID_DPX,
    CODEC_ID_MAD,
    CODEC_ID_FRWU,
    CODEC_ID_FLASHSV2,
    CODEC_ID_CDGRAPHICS,
    CODEC_ID_R210,
    CODEC_ID_ANM,
    CODEC_ID_BINKVIDEO,
    CODEC_ID_IFF_ILBM,
    CODEC_ID_IFF_BYTERUN1,
    CODEC_ID_KGV1,
    CODEC_ID_YOP,
    CODEC_ID_VP8,
    CODEC_ID_PICTOR,
    CODEC_ID_ANSI,
    CODEC_ID_A64_MULTI,
    CODEC_ID_A64_MULTI5,
    CODEC_ID_R10K,
    CODEC_ID_MXPEG,
    CODEC_ID_LAGARITH,
    CODEC_ID_PRORES,
    CODEC_ID_JV,
    CODEC_ID_DFA,
    CODEC_ID_WMV3IMAGE,
    CODEC_ID_VC1IMAGE,
    CODEC_ID_G723_1,
    CODEC_ID_G729,
    CODEC_ID_UTVIDEO,
    CODEC_ID_BMV_VIDEO,
    CODEC_ID_VBLE,
    CODEC_ID_DXTORY,
    CODEC_ID_V410,
    CODEC_ID_FIRST_AUDIO,
    CODEC_ID_PCM_S16LE,
    CODEC_ID_PCM_S16BE,
    CODEC_ID_PCM_U16LE,
    CODEC_ID_PCM_U16BE,
    CODEC_ID_PCM_S8,
    CODEC_ID_PCM_U8,
    CODEC_ID_PCM_MULAW,
    CODEC_ID_PCM_ALAW,
    CODEC_ID_PCM_S32LE,
    CODEC_ID_PCM_S32BE,
    CODEC_ID_PCM_U32LE,
    CODEC_ID_PCM_U32BE,
    CODEC_ID_PCM_S24LE,
    CODEC_ID_PCM_S24BE,
    CODEC_ID_PCM_U24LE,
    CODEC_ID_PCM_U24BE,
    CODEC_ID_PCM_S24DAUD,
    CODEC_ID_PCM_ZORK,
    CODEC_ID_PCM_S16LE_PLANAR,
    CODEC_ID_PCM_DVD,
    CODEC_ID_PCM_F32BE,
    CODEC_ID_PCM_F32LE,
    CODEC_ID_PCM_F64BE,
    CODEC_ID_PCM_F64LE,
    CODEC_ID_PCM_BLURAY,
    CODEC_ID_PCM_LXF,
    CODEC_ID_S302M,
    CODEC_ID_PCM_S8_PLANAR,
    CODEC_ID_ADPCM_IMA_QT,
    CODEC_ID_ADPCM_IMA_WAV,
    CODEC_ID_ADPCM_IMA_DK3,
    CODEC_ID_ADPCM_IMA_DK4,
    CODEC_ID_ADPCM_IMA_WS,
    CODEC_ID_ADPCM_IMA_SMJPEG,
    CODEC_ID_ADPCM_MS,
    CODEC_ID_ADPCM_4XM,
    CODEC_ID_ADPCM_XA,
    CODEC_ID_ADPCM_ADX,
    CODEC_ID_ADPCM_EA,
    CODEC_ID_ADPCM_G726,
    CODEC_ID_ADPCM_CT,
    CODEC_ID_ADPCM_SWF,
    CODEC_ID_ADPCM_YAMAHA,
    CODEC_ID_ADPCM_SBPRO_4,
    CODEC_ID_ADPCM_SBPRO_3,
    CODEC_ID_ADPCM_SBPRO_2,
    CODEC_ID_ADPCM_THP,
    CODEC_ID_ADPCM_IMA_AMV,
    CODEC_ID_ADPCM_EA_R1,
    CODEC_ID_ADPCM_EA_R3,
    CODEC_ID_ADPCM_EA_R2,
    CODEC_ID_ADPCM_IMA_EA_SEAD,
    CODEC_ID_ADPCM_IMA_EA_EACS,
    CODEC_ID_ADPCM_EA_XAS,
    CODEC_ID_ADPCM_EA_MAXIS_XA,
    CODEC_ID_ADPCM_IMA_ISS,
    CODEC_ID_ADPCM_G722,
    CODEC_ID_AMR_NB,
    CODEC_ID_AMR_WB,
    CODEC_ID_RA_144,
    CODEC_ID_RA_288,
    CODEC_ID_ROQ_DPCM,
    CODEC_ID_INTERPLAY_DPCM,
    CODEC_ID_XAN_DPCM,
    CODEC_ID_SOL_DPCM,
    CODEC_ID_MP2,
    CODEC_ID_MP3,
    CODEC_ID_AAC,
    CODEC_ID_AC3,
    CODEC_ID_DTS,
    CODEC_ID_VORBIS,
    CODEC_ID_DVAUDIO,
    CODEC_ID_WMAV1,
    CODEC_ID_WMAV2,
    CODEC_ID_MACE3,
    CODEC_ID_MACE6,
    CODEC_ID_VMDAUDIO,
    CODEC_ID_SONIC,
    CODEC_ID_SONIC_LS,
    CODEC_ID_FLAC,
    CODEC_ID_MP3ADU,
    CODEC_ID_MP3ON4,
    CODEC_ID_SHORTEN,
    CODEC_ID_ALAC,
    CODEC_ID_WESTWOOD_SND1,
    CODEC_ID_GSM,
    CODEC_ID_QDM2,
    CODEC_ID_COOK,
    CODEC_ID_TRUESPEECH,
    CODEC_ID_TTA,
    CODEC_ID_SMACKAUDIO,
    CODEC_ID_QCELP,
    CODEC_ID_WAVPACK,
    CODEC_ID_DSICINAUDIO,
    CODEC_ID_IMC,
    CODEC_ID_MUSEPACK7,
    CODEC_ID_MLP,
    CODEC_ID_GSM_MS,
    CODEC_ID_ATRAC3,
    CODEC_ID_VOXWARE,
    CODEC_ID_APE,
    CODEC_ID_NELLYMOSER,
    CODEC_ID_MUSEPACK8,
    CODEC_ID_SPEEX,
    CODEC_ID_WMAVOICE,
    CODEC_ID_WMAPRO,
    CODEC_ID_WMALOSSLESS,
    CODEC_ID_ATRAC3P,
    CODEC_ID_EAC3,
    CODEC_ID_SIPR,
    CODEC_ID_MP1,
    CODEC_ID_TWINVQ,
    CODEC_ID_TRUEHD,
    CODEC_ID_MP4ALS,
    CODEC_ID_ATRAC1,
    CODEC_ID_BINKAUDIO_RDFT,
    CODEC_ID_BINKAUDIO_DCT,
    CODEC_ID_AAC_LATM,
    CODEC_ID_QDMC,
    CODEC_ID_CELT,
    CODEC_ID_BMV_AUDIO,
    CODEC_ID_FIRST_SUBTITLE,
    CODEC_ID_DVD_SUBTITLE,
    CODEC_ID_DVB_SUBTITLE,
    CODEC_ID_TEXT,
    CODEC_ID_XSUB,
    CODEC_ID_SSA,
    CODEC_ID_MOV_TEXT,
    CODEC_ID_HDMV_PGS_SUBTITLE,
    CODEC_ID_DVB_TELETEXT,
    CODEC_ID_SRT,
    CODEC_ID_FIRST_UNKNOWN,
    CODEC_ID_TTF,
    CODEC_ID_PROBE,
    CODEC_ID_MPEG2TS,
    CODEC_ID_MPEG4SYSTEMS,
    CODEC_ID_FFMETADATA,
    Motion_Est_ID,
    ME_ZERO,
    ME_FULL,
    ME_LOG,
    ME_PHODS,
    ME_EPZS,
    ME_X1,
    ME_HEX,
    ME_UMH,
    ME_ITER,
    ME_TESA,
    AVDiscard,
    AVDISCARD_NONE,
    AVDISCARD_DEFAULT,
    AVDISCARD_NONREF,
    AVDISCARD_BIDIR,
    AVDISCARD_NONKEY,
    AVDISCARD_ALL,
    AVColorPrimaries,
    AVCOL_PRI_BT709,
    AVCOL_PRI_UNSPECIFIED,
    AVCOL_PRI_BT470M,
    AVCOL_PRI_BT470BG,
    AVCOL_PRI_SMPTE170M,
    AVCOL_PRI_SMPTE240M,
    AVCOL_PRI_FILM,
    AVCOL_PRI_NB,
    AVColorTransferCharacteristic,
    AVCOL_TRC_BT709,
    AVCOL_TRC_UNSPECIFIED,
    AVCOL_TRC_GAMMA22,
    AVCOL_TRC_GAMMA28,
    AVCOL_TRC_NB,
    AVColorSpace,
    AVCOL_SPC_RGB,
    AVCOL_SPC_BT709,
    AVCOL_SPC_UNSPECIFIED,
    AVCOL_SPC_FCC,
    AVCOL_SPC_BT470BG,
    AVCOL_SPC_SMPTE170M,
    AVCOL_SPC_SMPTE240M,
    AVCOL_SPC_NB,
    AVColorRange,
    AVCOL_RANGE_UNSPECIFIED,
    AVCOL_RANGE_MPEG,
    AVCOL_RANGE_JPEG,
    AVCOL_RANGE_NB,
    AVChromaLocation,
    AVCHROMA_LOC_UNSPECIFIED,
    AVCHROMA_LOC_LEFT,
    AVCHROMA_LOC_CENTER,
    AVCHROMA_LOC_TOPLEFT,
    AVCHROMA_LOC_TOP,
    AVCHROMA_LOC_BOTTOMLEFT,
    AVCHROMA_LOC_BOTTOM,
    AVCHROMA_LOC_NB,
    AVLPCType,
    AV_LPC_TYPE_DEFAULT,
    AV_LPC_TYPE_NONE,
    AV_LPC_TYPE_FIXED,
    AV_LPC_TYPE_LEVINSON,
    AV_LPC_TYPE_CHOLESKY,
    AV_LPC_TYPE_NB,
    AVAudioServiceType,
    AV_AUDIO_SERVICE_TYPE_MAIN,
    AV_AUDIO_SERVICE_TYPE_EFFECTS,
    AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED,
    AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED,
    AV_AUDIO_SERVICE_TYPE_DIALOGUE,
    AV_AUDIO_SERVICE_TYPE_COMMENTARY,
    AV_AUDIO_SERVICE_TYPE_EMERGENCY,
    AV_AUDIO_SERVICE_TYPE_VOICE_OVER,
    AV_AUDIO_SERVICE_TYPE_KARAOKE,
    AV_AUDIO_SERVICE_TYPE_NB,
    RcOverride,
    Array_2_Int16,
    Array_3_Array_2_Int16,
    AVPanScan,
    AVPacketSideDataType,
    AV_PKT_DATA_PALETTE,
    AV_PKT_DATA_NEW_EXTRADATA,
    AV_PKT_DATA_PARAM_CHANGE,
    AVPacket,
    AVSideDataParamChangeFlags,
    AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT,
    AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT,
    AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE,
    AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS,
    Array_4_Ptr,
    Array_4_Cint,
    Array_2_Ptr,
    Array_4_Uint64,
    AVProfile,
    AVCodecDefault,
    AVCodec,
    Array_32_Uint8,
    Array_256_Uint32,
    AVPaletteControl,
    AVHWAccel,
    AVCodecInternal,
    AVFieldOrder,
    AV_FIELD_UNKNOWN,
    AV_FIELD_PROGRESSIVE,
    AV_FIELD_TT,
    AV_FIELD_BB,
    AV_FIELD_TB,
    AV_FIELD_BT,
    AVCodecContext,
    AVFrame,
    AVPicture,
    AVSubtitleType,
    SUBTITLE_NONE,
    SUBTITLE_BITMAP,
    SUBTITLE_TEXT,
    SUBTITLE_ASS,
    AVSubtitleRect,
    AVSubtitle,
    ReSampleContext,
    AVResampleContext,
    Array_4_Int64,
    Array_5_Cint,
    AVCodecParser,
    AVCodecParserContext,
    AVBitStreamFilter,
    AVBitStreamFilterContext,
    AVLockOp,
    AV_LOCK_CREATE,
    AV_LOCK_OBTAIN,
    AV_LOCK_RELEASE,
    AV_LOCK_DESTROY,
    LIBAVCODEC_VERSION_MAJOR,
    LIBAVCODEC_VERSION_MINOR,
    LIBAVCODEC_VERSION_MICRO,
    LIBAVCODEC_BUILD,
    vaapi_context,
    vdpau_render_state,
    AV_XVMC_ID,
    xvmc_pix_fmt

const SampleFormat = AVSampleFormat
const SAMPLE_FMT_NONE = AV_SAMPLE_FMT_NONE
const SAMPLE_FMT_U8 = AV_SAMPLE_FMT_U8
const SAMPLE_FMT_S16 = AV_SAMPLE_FMT_S16
const SAMPLE_FMT_S32 = AV_SAMPLE_FMT_S32
const SAMPLE_FMT_FLT = AV_SAMPLE_FMT_FLT
const SAMPLE_FMT_DBL = AV_SAMPLE_FMT_DBL
const SAMPLE_FMT_NB = AV_SAMPLE_FMT_NB
const CH_FRONT_LEFT = AV_CH_FRONT_LEFT
const CH_FRONT_RIGHT = AV_CH_FRONT_RIGHT
const CH_FRONT_CENTER = AV_CH_FRONT_CENTER
const CH_LOW_FREQUENCY = AV_CH_LOW_FREQUENCY
const CH_BACK_LEFT = AV_CH_BACK_LEFT
const CH_BACK_RIGHT = AV_CH_BACK_RIGHT
const CH_FRONT_LEFT_OF_CENTER = AV_CH_FRONT_LEFT_OF_CENTER
const CH_FRONT_RIGHT_OF_CENTER = AV_CH_FRONT_RIGHT_OF_CENTER
const CH_BACK_CENTER = AV_CH_BACK_CENTER
const CH_SIDE_LEFT = AV_CH_SIDE_LEFT
const CH_SIDE_RIGHT = AV_CH_SIDE_RIGHT
const CH_TOP_CENTER = AV_CH_TOP_CENTER
const CH_TOP_FRONT_LEFT = AV_CH_TOP_FRONT_LEFT
const CH_TOP_FRONT_CENTER = AV_CH_TOP_FRONT_CENTER
const CH_TOP_FRONT_RIGHT = AV_CH_TOP_FRONT_RIGHT
const CH_TOP_BACK_LEFT = AV_CH_TOP_BACK_LEFT
const CH_TOP_BACK_CENTER = AV_CH_TOP_BACK_CENTER
const CH_TOP_BACK_RIGHT = AV_CH_TOP_BACK_RIGHT
const CH_STEREO_LEFT = AV_CH_STEREO_LEFT
const CH_STEREO_RIGHT = AV_CH_STEREO_RIGHT
const CH_LAYOUT_NATIVE = AV_CH_LAYOUT_NATIVE
const CH_LAYOUT_MONO = AV_CH_LAYOUT_MONO
const CH_LAYOUT_STEREO = AV_CH_LAYOUT_STEREO
const CH_LAYOUT_2_1 = AV_CH_LAYOUT_2_1
const CH_LAYOUT_SURROUND = AV_CH_LAYOUT_SURROUND
const CH_LAYOUT_4POINT0 = AV_CH_LAYOUT_4POINT0
const CH_LAYOUT_2_2 = AV_CH_LAYOUT_2_2
const CH_LAYOUT_QUAD = AV_CH_LAYOUT_QUAD
const CH_LAYOUT_5POINT0 = AV_CH_LAYOUT_5POINT0
const CH_LAYOUT_5POINT1 = AV_CH_LAYOUT_5POINT1
const CH_LAYOUT_5POINT0_BACK = AV_CH_LAYOUT_5POINT0_BACK
const CH_LAYOUT_5POINT1_BACK = AV_CH_LAYOUT_5POINT1_BACK
const CH_LAYOUT_7POINT0 = AV_CH_LAYOUT_7POINT0
const CH_LAYOUT_7POINT1 = AV_CH_LAYOUT_7POINT1
const CH_LAYOUT_7POINT1_WIDE = AV_CH_LAYOUT_7POINT1_WIDE
const CH_LAYOUT_STEREO_DOWNMIX = AV_CH_LAYOUT_STEREO_DOWNMIX
const AVCODEC_MAX_AUDIO_FRAME_SIZE = 192000
const FF_INPUT_BUFFER_PADDING_SIZE = 8
const FF_MIN_BUFFER_SIZE = 16384
const FF_MAX_B_FRAMES = 16
const CODEC_FLAG_QSCALE = 0x0002
const CODEC_FLAG_4MV = 0x0004
const CODEC_FLAG_QPEL = 0x0010
const CODEC_FLAG_GMC = 0x0020
const CODEC_FLAG_MV0 = 0x0040
const CODEC_FLAG_INPUT_PRESERVED = 0x0100
const CODEC_FLAG_PASS1 = 0x0200
const CODEC_FLAG_PASS2 = 0x0400
const CODEC_FLAG_GRAY = 0x2000
const CODEC_FLAG_EMU_EDGE = 0x4000
const CODEC_FLAG_PSNR = 0x8000
const CODEC_FLAG_TRUNCATED = 0x00010000
const CODEC_FLAG_NORMALIZE_AQP = 0x00020000
const CODEC_FLAG_INTERLACED_DCT = 0x00040000
const CODEC_FLAG_LOW_DELAY = 0x00080000
const CODEC_FLAG_GLOBAL_HEADER = 0x00400000
const CODEC_FLAG_BITEXACT = 0x00800000
const CODEC_FLAG_AC_PRED = 0x01000000
const CODEC_FLAG_CBP_RD = 0x04000000
const CODEC_FLAG_QP_RD = 0x08000000
const CODEC_FLAG_LOOP_FILTER = 0x00000800
const CODEC_FLAG_INTERLACED_ME = 0x20000000
const CODEC_FLAG_CLOSED_GOP = 0x80000000
const CODEC_FLAG2_FAST = 0x00000001
const CODEC_FLAG2_STRICT_GOP = 0x00000002
const CODEC_FLAG2_NO_OUTPUT = 0x00000004
const CODEC_FLAG2_LOCAL_HEADER = 0x00000008
const CODEC_FLAG2_SKIP_RD = 0x00004000
const CODEC_FLAG2_CHUNKS = 0x00008000
const CODEC_FLAG_OBMC = 0x00000001
const CODEC_FLAG_H263P_AIV = 0x00000008
const CODEC_FLAG_PART = 0x0080
const CODEC_FLAG_ALT_SCAN = 0x00100000
const CODEC_FLAG_H263P_UMV = 0x02000000
const CODEC_FLAG_H263P_SLICE_STRUCT = 0x10000000
const CODEC_FLAG_SVCD_SCAN_OFFSET = 0x40000000
const CODEC_FLAG2_INTRA_VLC = 0x00000800
const CODEC_FLAG2_DROP_FRAME_TIMECODE = 0x00002000
const CODEC_FLAG2_NON_LINEAR_QUANT = 0x00010000
const CODEC_FLAG_EXTERN_HUFF = 0x1000
const CODEC_FLAG2_BPYRAMID = 0x00000010
const CODEC_FLAG2_WPRED = 0x00000020
const CODEC_FLAG2_MIXED_REFS = 0x00000040
const CODEC_FLAG2_8X8DCT = 0x00000080
const CODEC_FLAG2_FASTPSKIP = 0x00000100
const CODEC_FLAG2_AUD = 0x00000200
const CODEC_FLAG2_BRDO = 0x00000400
const CODEC_FLAG2_MBTREE = 0x00040000
const CODEC_FLAG2_PSY = 0x00080000
const CODEC_FLAG2_SSIM = 0x00100000
const CODEC_FLAG2_INTRA_REFRESH = 0x00200000
const CODEC_FLAG2_MEMC_ONLY = 0x00001000
const CODEC_FLAG2_BIT_RESERVOIR = 0x00020000
const CODEC_CAP_DRAW_HORIZ_BAND = 0x0001
const CODEC_CAP_DR1 = 0x0002
const CODEC_CAP_PARSE_ONLY = 0x0004
const CODEC_CAP_TRUNCATED = 0x0008
const CODEC_CAP_HWACCEL = 0x0010
const CODEC_CAP_DELAY = 0x0020
const CODEC_CAP_SMALL_LAST_FRAME = 0x0040
const CODEC_CAP_HWACCEL_VDPAU = 0x0080
const CODEC_CAP_SUBFRAMES = 0x0100
const CODEC_CAP_EXPERIMENTAL = 0x0200
const CODEC_CAP_CHANNEL_CONF = 0x0400
const CODEC_CAP_NEG_LINESIZES = 0x0800
const CODEC_CAP_FRAME_THREADS = 0x1000
const CODEC_CAP_SLICE_THREADS = 0x2000
const CODEC_CAP_PARAM_CHANGE = 0x4000
const CODEC_CAP_AUTO_THREADS = 0x8000
const CODEC_CAP_VARIABLE_FRAME_SIZE = 0x00010000
const MB_TYPE_INTRA4x4 = 0x0001
const MB_TYPE_INTRA16x16 = 0x0002
const MB_TYPE_INTRA_PCM = 0x0004
const MB_TYPE_16x16 = 0x0008
const MB_TYPE_16x8 = 0x0010
const MB_TYPE_8x16 = 0x0020
const MB_TYPE_8x8 = 0x0040
const MB_TYPE_INTERLACED = 0x0080
const MB_TYPE_DIRECT2 = 0x0100
const MB_TYPE_ACPRED = 0x0200
const MB_TYPE_GMC = 0x0400
const MB_TYPE_SKIP = 0x0800
const MB_TYPE_P0L0 = 0x1000
const MB_TYPE_P1L0 = 0x2000
const MB_TYPE_P0L1 = 0x4000
const MB_TYPE_P1L1 = 0x8000
const MB_TYPE_L0 = MB_TYPE_P0L0 | MB_TYPE_P1L0
const MB_TYPE_L1 = MB_TYPE_P0L1 | MB_TYPE_P1L1
const MB_TYPE_L0L1 = MB_TYPE_L0 | MB_TYPE_L1
const MB_TYPE_QUANT = 0x00010000
const MB_TYPE_CBP = 0x00020000
const FF_QSCALE_TYPE_MPEG1 = 0
const FF_QSCALE_TYPE_MPEG2 = 1
const FF_QSCALE_TYPE_H264 = 2
const FF_QSCALE_TYPE_VP56 = 3
const FF_BUFFER_TYPE_INTERNAL = 1
const FF_BUFFER_TYPE_USER = 2
const FF_BUFFER_TYPE_SHARED = 4
const FF_BUFFER_TYPE_COPY = 8
const FF_I_TYPE = AV_PICTURE_TYPE_I
const FF_P_TYPE = AV_PICTURE_TYPE_P
const FF_B_TYPE = AV_PICTURE_TYPE_B
const FF_S_TYPE = AV_PICTURE_TYPE_S
const FF_SI_TYPE = AV_PICTURE_TYPE_SI
const FF_SP_TYPE = AV_PICTURE_TYPE_SP
const FF_BI_TYPE = AV_PICTURE_TYPE_BI
const FF_BUFFER_HINTS_VALID = 0x01
const FF_BUFFER_HINTS_READABLE = 0x02
const FF_BUFFER_HINTS_PRESERVE = 0x04
const FF_BUFFER_HINTS_REUSABLE = 0x08
const AV_PKT_FLAG_KEY = 0x0001
const AV_PKT_FLAG_CORRUPT = 0x0002
const AV_NUM_DATA_POINTERS = 4
const FF_ASPECT_EXTENDED = 15
const FF_RC_STRATEGY_XVID = 1
const FF_BUG_AUTODETECT = 1
const FF_BUG_OLD_MSMPEG4 = 2
const FF_BUG_XVID_ILACE = 4
const FF_BUG_UMP4 = 8
const FF_BUG_NO_PADDING = 16
const FF_BUG_AMV = 32
const FF_BUG_AC_VLC = 0
const FF_BUG_QPEL_CHROMA = 64
const FF_BUG_STD_QPEL = 128
const FF_BUG_QPEL_CHROMA2 = 256
const FF_BUG_DIRECT_BLOCKSIZE = 512
const FF_BUG_EDGE = 1024
const FF_BUG_HPEL_CHROMA = 2048
const FF_BUG_DC_CLIP = 4096
const FF_BUG_MS = 8192
const FF_BUG_TRUNCATED = 16384
const FF_COMPLIANCE_VERY_STRICT = 2
const FF_COMPLIANCE_STRICT = 1
const FF_COMPLIANCE_NORMAL = 0
const FF_COMPLIANCE_UNOFFICIAL = -1
const FF_COMPLIANCE_EXPERIMENTAL = -2
const FF_ER_CAREFUL = 1
const FF_ER_COMPLIANT = 2
const FF_ER_AGGRESSIVE = 3
const FF_ER_VERY_AGGRESSIVE = 4
const FF_ER_EXPLODE = 5
const FF_DCT_AUTO = 0
const FF_DCT_FASTINT = 1
const FF_DCT_INT = 2
const FF_DCT_MMX = 3
const FF_DCT_MLIB = 4
const FF_DCT_ALTIVEC = 5
const FF_DCT_FAAN = 6
const FF_IDCT_AUTO = 0
const FF_IDCT_INT = 1
const FF_IDCT_SIMPLE = 2
const FF_IDCT_SIMPLEMMX = 3
const FF_IDCT_LIBMPEG2MMX = 4
const FF_IDCT_PS2 = 5
const FF_IDCT_MLIB = 6
const FF_IDCT_ARM = 7
const FF_IDCT_ALTIVEC = 8
const FF_IDCT_SH4 = 9
const FF_IDCT_SIMPLEARM = 10
const FF_IDCT_H264 = 11
const FF_IDCT_VP3 = 12
const FF_IDCT_IPP = 13
const FF_IDCT_XVIDMMX = 14
const FF_IDCT_CAVS = 15
const FF_IDCT_SIMPLEARMV5TE = 16
const FF_IDCT_SIMPLEARMV6 = 17
const FF_IDCT_SIMPLEVIS = 18
const FF_IDCT_WMV2 = 19
const FF_IDCT_FAAN = 20
const FF_IDCT_EA = 21
const FF_IDCT_SIMPLENEON = 22
const FF_IDCT_SIMPLEALPHA = 23
const FF_IDCT_BINK = 24
const FF_EC_GUESS_MVS = 1
const FF_EC_DEBLOCK = 2
const FF_PRED_LEFT = 0
const FF_PRED_PLANE = 1
const FF_PRED_MEDIAN = 2
const FF_DEBUG_PICT_INFO = 1
const FF_DEBUG_RC = 2
const FF_DEBUG_BITSTREAM = 4
const FF_DEBUG_MB_TYPE = 8
const FF_DEBUG_QP = 16
const FF_DEBUG_MV = 32
const FF_DEBUG_DCT_COEFF = 0x00000040
const FF_DEBUG_SKIP = 0x00000080
const FF_DEBUG_STARTCODE = 0x00000100
const FF_DEBUG_PTS = 0x00000200
const FF_DEBUG_ER = 0x00000400
const FF_DEBUG_MMCO = 0x00000800
const FF_DEBUG_BUGS = 0x00001000
const FF_DEBUG_VIS_QP = 0x00002000
const FF_DEBUG_VIS_MB_TYPE = 0x00004000
const FF_DEBUG_BUFFERS = 0x00008000
const FF_DEBUG_THREADS = 0x00010000
const FF_DEBUG_VIS_MV_P_FOR = 0x00000001
const FF_DEBUG_VIS_MV_B_FOR = 0x00000002
const FF_DEBUG_VIS_MV_B_BACK = 0x00000004
const FF_CMP_SAD = 0
const FF_CMP_SSE = 1
const FF_CMP_SATD = 2
const FF_CMP_DCT = 3
const FF_CMP_PSNR = 4
const FF_CMP_BIT = 5
const FF_CMP_RD = 6
const FF_CMP_ZERO = 7
const FF_CMP_VSAD = 8
const FF_CMP_VSSE = 9
const FF_CMP_NSSE = 10
const FF_CMP_W53 = 11
const FF_CMP_W97 = 12
const FF_CMP_DCTMAX = 13
const FF_CMP_DCT264 = 14
const FF_CMP_CHROMA = 256
const FF_DTG_AFD_SAME = 8
const FF_DTG_AFD_4_3 = 9
const FF_DTG_AFD_16_9 = 10
const FF_DTG_AFD_14_9 = 11
const FF_DTG_AFD_4_3_SP_14_9 = 13
const FF_DTG_AFD_16_9_SP_14_9 = 14
const FF_DTG_AFD_SP_4_3 = 15
const FF_DEFAULT_QUANT_BIAS = 999999
const FF_CODER_TYPE_VLC = 0
const FF_CODER_TYPE_AC = 1
const FF_CODER_TYPE_RAW = 2
const FF_CODER_TYPE_RLE = 3
const FF_CODER_TYPE_DEFLATE = 4
const SLICE_FLAG_CODED_ORDER = 0x0001
const SLICE_FLAG_ALLOW_FIELD = 0x0002
const SLICE_FLAG_ALLOW_PLANE = 0x0004
const FF_MB_DECISION_SIMPLE = 0
const FF_MB_DECISION_BITS = 1
const FF_MB_DECISION_RD = 2
const FF_AA_AUTO = 0
const FF_AA_FASTINT = 1
const FF_AA_INT = 2
const FF_AA_FLOAT = 3
const FF_PROFILE_UNKNOWN = -99
const FF_PROFILE_RESERVED = -100
const FF_PROFILE_AAC_MAIN = 0
const FF_PROFILE_AAC_LOW = 1
const FF_PROFILE_AAC_SSR = 2
const FF_PROFILE_AAC_LTP = 3
const FF_PROFILE_DTS = 20
const FF_PROFILE_DTS_ES = 30
const FF_PROFILE_DTS_96_24 = 40
const FF_PROFILE_DTS_HD_HRA = 50
const FF_PROFILE_DTS_HD_MA = 60
const FF_PROFILE_MPEG2_422 = 0
const FF_PROFILE_MPEG2_HIGH = 1
const FF_PROFILE_MPEG2_SS = 2
const FF_PROFILE_MPEG2_SNR_SCALABLE = 3
const FF_PROFILE_MPEG2_MAIN = 4
const FF_PROFILE_MPEG2_SIMPLE = 5
const FF_PROFILE_H264_CONSTRAINED = 1 << 9
const FF_PROFILE_H264_INTRA = 1 << 11
const FF_PROFILE_H264_BASELINE = 66
const FF_PROFILE_H264_CONSTRAINED_BASELINE = 66 | FF_PROFILE_H264_CONSTRAINED
const FF_PROFILE_H264_MAIN = 77
const FF_PROFILE_H264_EXTENDED = 88
const FF_PROFILE_H264_HIGH = 100
const FF_PROFILE_H264_HIGH_10 = 110
const FF_PROFILE_H264_HIGH_10_INTRA = 110 | FF_PROFILE_H264_INTRA
const FF_PROFILE_H264_HIGH_422 = 122
const FF_PROFILE_H264_HIGH_422_INTRA = 122 | FF_PROFILE_H264_INTRA
const FF_PROFILE_H264_HIGH_444 = 144
const FF_PROFILE_H264_HIGH_444_PREDICTIVE = 244
const FF_PROFILE_H264_HIGH_444_INTRA = 244 | FF_PROFILE_H264_INTRA
const FF_PROFILE_H264_CAVLC_444 = 44
const FF_PROFILE_VC1_SIMPLE = 0
const FF_PROFILE_VC1_MAIN = 1
const FF_PROFILE_VC1_COMPLEX = 2
const FF_PROFILE_VC1_ADVANCED = 3
const FF_PROFILE_MPEG4_SIMPLE = 0
const FF_PROFILE_MPEG4_SIMPLE_SCALABLE = 1
const FF_PROFILE_MPEG4_CORE = 2
const FF_PROFILE_MPEG4_MAIN = 3
const FF_PROFILE_MPEG4_N_BIT = 4
const FF_PROFILE_MPEG4_SCALABLE_TEXTURE = 5
const FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION = 6
const FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE = 7
const FF_PROFILE_MPEG4_HYBRID = 8
const FF_PROFILE_MPEG4_ADVANCED_REAL_TIME = 9
const FF_PROFILE_MPEG4_CORE_SCALABLE = 10
const FF_PROFILE_MPEG4_ADVANCED_CODING = 11
const FF_PROFILE_MPEG4_ADVANCED_CORE = 12
const FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE = 13
const FF_PROFILE_MPEG4_SIMPLE_STUDIO = 14
const FF_PROFILE_MPEG4_ADVANCED_SIMPLE = 15
const FF_LEVEL_UNKNOWN = -99
const X264_PART_I4X4 = 0x0001
const X264_PART_I8X8 = 0x0002
const X264_PART_P8X8 = 0x0010
const X264_PART_P4X4 = 0x0020
const X264_PART_B8X8 = 0x0100
const FF_COMPRESSION_DEFAULT = -1
const FF_THREAD_FRAME = 1
const FF_THREAD_SLICE = 2
const AV_EF_CRCCHECK = 1 << 0
const AV_EF_BITSTREAM = 1 << 1
const AV_EF_BUFFER = 1 << 2
const AV_EF_EXPLODE = 1 << 3
const AVPALETTE_SIZE = 1024
const AVPALETTE_COUNT = 256
const FF_LOSS_RESOLUTION = 0x0001
const FF_LOSS_DEPTH = 0x0002
const FF_LOSS_COLORSPACE = 0x0004
const FF_LOSS_ALPHA = 0x0008
const FF_LOSS_COLORQUANT = 0x0010
const FF_LOSS_CHROMA = 0x0020
const FF_ALPHA_TRANSP = 0x0001
const FF_ALPHA_SEMI_TRANSP = 0x0002
const AV_PARSER_PTS_NB = 4
const PARSER_FLAG_COMPLETE_FRAMES = 0x0001
const PARSER_FLAG_ONCE = 0x0002
const PARSER_FLAG_FETCHED_OFFSET = 0x0004

# begin enum CodecID
typealias CodecID Uint32
const CODEC_ID_NONE = @compat UInt32(0)
const CODEC_ID_MPEG1VIDEO = @compat UInt32(1)
const CODEC_ID_MPEG2VIDEO = @compat UInt32(2)
const CODEC_ID_MPEG2VIDEO_XVMC = @compat UInt32(3)
const CODEC_ID_H261 = @compat UInt32(4)
const CODEC_ID_H263 = @compat UInt32(5)
const CODEC_ID_RV10 = @compat UInt32(6)
const CODEC_ID_RV20 = @compat UInt32(7)
const CODEC_ID_MJPEG = @compat UInt32(8)
const CODEC_ID_MJPEGB = @compat UInt32(9)
const CODEC_ID_LJPEG = @compat UInt32(10)
const CODEC_ID_SP5X = @compat UInt32(11)
const CODEC_ID_JPEGLS = @compat UInt32(12)
const CODEC_ID_MPEG4 = @compat UInt32(13)
const CODEC_ID_RAWVIDEO = @compat UInt32(14)
const CODEC_ID_MSMPEG4V1 = @compat UInt32(15)
const CODEC_ID_MSMPEG4V2 = @compat UInt32(16)
const CODEC_ID_MSMPEG4V3 = @compat UInt32(17)
const CODEC_ID_WMV1 = @compat UInt32(18)
const CODEC_ID_WMV2 = @compat UInt32(19)
const CODEC_ID_H263P = @compat UInt32(20)
const CODEC_ID_H263I = @compat UInt32(21)
const CODEC_ID_FLV1 = @compat UInt32(22)
const CODEC_ID_SVQ1 = @compat UInt32(23)
const CODEC_ID_SVQ3 = @compat UInt32(24)
const CODEC_ID_DVVIDEO = @compat UInt32(25)
const CODEC_ID_HUFFYUV = @compat UInt32(26)
const CODEC_ID_CYUV = @compat UInt32(27)
const CODEC_ID_H264 = @compat UInt32(28)
const CODEC_ID_INDEO3 = @compat UInt32(29)
const CODEC_ID_VP3 = @compat UInt32(30)
const CODEC_ID_THEORA = @compat UInt32(31)
const CODEC_ID_ASV1 = @compat UInt32(32)
const CODEC_ID_ASV2 = @compat UInt32(33)
const CODEC_ID_FFV1 = @compat UInt32(34)
const CODEC_ID_4XM = @compat UInt32(35)
const CODEC_ID_VCR1 = @compat UInt32(36)
const CODEC_ID_CLJR = @compat UInt32(37)
const CODEC_ID_MDEC = @compat UInt32(38)
const CODEC_ID_ROQ = @compat UInt32(39)
const CODEC_ID_INTERPLAY_VIDEO = @compat UInt32(40)
const CODEC_ID_XAN_WC3 = @compat UInt32(41)
const CODEC_ID_XAN_WC4 = @compat UInt32(42)
const CODEC_ID_RPZA = @compat UInt32(43)
const CODEC_ID_CINEPAK = @compat UInt32(44)
const CODEC_ID_WS_VQA = @compat UInt32(45)
const CODEC_ID_MSRLE = @compat UInt32(46)
const CODEC_ID_MSVIDEO1 = @compat UInt32(47)
const CODEC_ID_IDCIN = @compat UInt32(48)
const CODEC_ID_8BPS = @compat UInt32(49)
const CODEC_ID_SMC = @compat UInt32(50)
const CODEC_ID_FLIC = @compat UInt32(51)
const CODEC_ID_TRUEMOTION1 = @compat UInt32(52)
const CODEC_ID_VMDVIDEO = @compat UInt32(53)
const CODEC_ID_MSZH = @compat UInt32(54)
const CODEC_ID_ZLIB = @compat UInt32(55)
const CODEC_ID_QTRLE = @compat UInt32(56)
const CODEC_ID_SNOW = @compat UInt32(57)
const CODEC_ID_TSCC = @compat UInt32(58)
const CODEC_ID_ULTI = @compat UInt32(59)
const CODEC_ID_QDRAW = @compat UInt32(60)
const CODEC_ID_VIXL = @compat UInt32(61)
const CODEC_ID_QPEG = @compat UInt32(62)
const CODEC_ID_PNG = @compat UInt32(63)
const CODEC_ID_PPM = @compat UInt32(64)
const CODEC_ID_PBM = @compat UInt32(65)
const CODEC_ID_PGM = @compat UInt32(66)
const CODEC_ID_PGMYUV = @compat UInt32(67)
const CODEC_ID_PAM = @compat UInt32(68)
const CODEC_ID_FFVHUFF = @compat UInt32(69)
const CODEC_ID_RV30 = @compat UInt32(70)
const CODEC_ID_RV40 = @compat UInt32(71)
const CODEC_ID_VC1 = @compat UInt32(72)
const CODEC_ID_WMV3 = @compat UInt32(73)
const CODEC_ID_LOCO = @compat UInt32(74)
const CODEC_ID_WNV1 = @compat UInt32(75)
const CODEC_ID_AASC = @compat UInt32(76)
const CODEC_ID_INDEO2 = @compat UInt32(77)
const CODEC_ID_FRAPS = @compat UInt32(78)
const CODEC_ID_TRUEMOTION2 = @compat UInt32(79)
const CODEC_ID_BMP = @compat UInt32(80)
const CODEC_ID_CSCD = @compat UInt32(81)
const CODEC_ID_MMVIDEO = @compat UInt32(82)
const CODEC_ID_ZMBV = @compat UInt32(83)
const CODEC_ID_AVS = @compat UInt32(84)
const CODEC_ID_SMACKVIDEO = @compat UInt32(85)
const CODEC_ID_NUV = @compat UInt32(86)
const CODEC_ID_KMVC = @compat UInt32(87)
const CODEC_ID_FLASHSV = @compat UInt32(88)
const CODEC_ID_CAVS = @compat UInt32(89)
const CODEC_ID_JPEG2000 = @compat UInt32(90)
const CODEC_ID_VMNC = @compat UInt32(91)
const CODEC_ID_VP5 = @compat UInt32(92)
const CODEC_ID_VP6 = @compat UInt32(93)
const CODEC_ID_VP6F = @compat UInt32(94)
const CODEC_ID_TARGA = @compat UInt32(95)
const CODEC_ID_DSICINVIDEO = @compat UInt32(96)
const CODEC_ID_TIERTEXSEQVIDEO = @compat UInt32(97)
const CODEC_ID_TIFF = @compat UInt32(98)
const CODEC_ID_GIF = @compat UInt32(99)
const CODEC_ID_FFH264 = @compat UInt32(100)
const CODEC_ID_DXA = @compat UInt32(101)
const CODEC_ID_DNXHD = @compat UInt32(102)
const CODEC_ID_THP = @compat UInt32(103)
const CODEC_ID_SGI = @compat UInt32(104)
const CODEC_ID_C93 = @compat UInt32(105)
const CODEC_ID_BETHSOFTVID = @compat UInt32(106)
const CODEC_ID_PTX = @compat UInt32(107)
const CODEC_ID_TXD = @compat UInt32(108)
const CODEC_ID_VP6A = @compat UInt32(109)
const CODEC_ID_AMV = @compat UInt32(110)
const CODEC_ID_VB = @compat UInt32(111)
const CODEC_ID_PCX = @compat UInt32(112)
const CODEC_ID_SUNRAST = @compat UInt32(113)
const CODEC_ID_INDEO4 = @compat UInt32(114)
const CODEC_ID_INDEO5 = @compat UInt32(115)
const CODEC_ID_MIMIC = @compat UInt32(116)
const CODEC_ID_RL2 = @compat UInt32(117)
const CODEC_ID_8SVX_EXP = @compat UInt32(118)
const CODEC_ID_8SVX_FIB = @compat UInt32(119)
const CODEC_ID_ESCAPE124 = @compat UInt32(120)
const CODEC_ID_DIRAC = @compat UInt32(121)
const CODEC_ID_BFI = @compat UInt32(122)
const CODEC_ID_CMV = @compat UInt32(123)
const CODEC_ID_MOTIONPIXELS = @compat UInt32(124)
const CODEC_ID_TGV = @compat UInt32(125)
const CODEC_ID_TGQ = @compat UInt32(126)
const CODEC_ID_TQI = @compat UInt32(127)
const CODEC_ID_AURA = @compat UInt32(128)
const CODEC_ID_AURA2 = @compat UInt32(129)
const CODEC_ID_V210X = @compat UInt32(130)
const CODEC_ID_TMV = @compat UInt32(131)
const CODEC_ID_V210 = @compat UInt32(132)
const CODEC_ID_DPX = @compat UInt32(133)
const CODEC_ID_MAD = @compat UInt32(134)
const CODEC_ID_FRWU = @compat UInt32(135)
const CODEC_ID_FLASHSV2 = @compat UInt32(136)
const CODEC_ID_CDGRAPHICS = @compat UInt32(137)
const CODEC_ID_R210 = @compat UInt32(138)
const CODEC_ID_ANM = @compat UInt32(139)
const CODEC_ID_BINKVIDEO = @compat UInt32(140)
const CODEC_ID_IFF_ILBM = @compat UInt32(141)
const CODEC_ID_IFF_BYTERUN1 = @compat UInt32(142)
const CODEC_ID_KGV1 = @compat UInt32(143)
const CODEC_ID_YOP = @compat UInt32(144)
const CODEC_ID_VP8 = @compat UInt32(145)
const CODEC_ID_PICTOR = @compat UInt32(146)
const CODEC_ID_ANSI = @compat UInt32(147)
const CODEC_ID_A64_MULTI = @compat UInt32(148)
const CODEC_ID_A64_MULTI5 = @compat UInt32(149)
const CODEC_ID_R10K = @compat UInt32(150)
const CODEC_ID_MXPEG = @compat UInt32(151)
const CODEC_ID_LAGARITH = @compat UInt32(152)
const CODEC_ID_PRORES = @compat UInt32(153)
const CODEC_ID_JV = @compat UInt32(154)
const CODEC_ID_DFA = @compat UInt32(155)
const CODEC_ID_WMV3IMAGE = @compat UInt32(156)
const CODEC_ID_VC1IMAGE = @compat UInt32(157)
const CODEC_ID_G723_1 = @compat UInt32(158)
const CODEC_ID_G729 = @compat UInt32(159)
const CODEC_ID_UTVIDEO = @compat UInt32(160)
const CODEC_ID_BMV_VIDEO = @compat UInt32(161)
const CODEC_ID_VBLE = @compat UInt32(162)
const CODEC_ID_DXTORY = @compat UInt32(163)
const CODEC_ID_V410 = @compat UInt32(164)
const CODEC_ID_FIRST_AUDIO = @compat UInt32(65536)
const CODEC_ID_PCM_S16LE = @compat UInt32(65536)
const CODEC_ID_PCM_S16BE = @compat UInt32(65537)
const CODEC_ID_PCM_U16LE = @compat UInt32(65538)
const CODEC_ID_PCM_U16BE = @compat UInt32(65539)
const CODEC_ID_PCM_S8 = @compat UInt32(65540)
const CODEC_ID_PCM_U8 = @compat UInt32(65541)
const CODEC_ID_PCM_MULAW = @compat UInt32(65542)
const CODEC_ID_PCM_ALAW = @compat UInt32(65543)
const CODEC_ID_PCM_S32LE = @compat UInt32(65544)
const CODEC_ID_PCM_S32BE = @compat UInt32(65545)
const CODEC_ID_PCM_U32LE = @compat UInt32(65546)
const CODEC_ID_PCM_U32BE = @compat UInt32(65547)
const CODEC_ID_PCM_S24LE = @compat UInt32(65548)
const CODEC_ID_PCM_S24BE = @compat UInt32(65549)
const CODEC_ID_PCM_U24LE = @compat UInt32(65550)
const CODEC_ID_PCM_U24BE = @compat UInt32(65551)
const CODEC_ID_PCM_S24DAUD = @compat UInt32(65552)
const CODEC_ID_PCM_ZORK = @compat UInt32(65553)
const CODEC_ID_PCM_S16LE_PLANAR = @compat UInt32(65554)
const CODEC_ID_PCM_DVD = @compat UInt32(65555)
const CODEC_ID_PCM_F32BE = @compat UInt32(65556)
const CODEC_ID_PCM_F32LE = @compat UInt32(65557)
const CODEC_ID_PCM_F64BE = @compat UInt32(65558)
const CODEC_ID_PCM_F64LE = @compat UInt32(65559)
const CODEC_ID_PCM_BLURAY = @compat UInt32(65560)
const CODEC_ID_PCM_LXF = @compat UInt32(65561)
const CODEC_ID_S302M = @compat UInt32(65562)
const CODEC_ID_PCM_S8_PLANAR = @compat UInt32(65563)
const CODEC_ID_ADPCM_IMA_QT = @compat UInt32(69632)
const CODEC_ID_ADPCM_IMA_WAV = @compat UInt32(69633)
const CODEC_ID_ADPCM_IMA_DK3 = @compat UInt32(69634)
const CODEC_ID_ADPCM_IMA_DK4 = @compat UInt32(69635)
const CODEC_ID_ADPCM_IMA_WS = @compat UInt32(69636)
const CODEC_ID_ADPCM_IMA_SMJPEG = @compat UInt32(69637)
const CODEC_ID_ADPCM_MS = @compat UInt32(69638)
const CODEC_ID_ADPCM_4XM = @compat UInt32(69639)
const CODEC_ID_ADPCM_XA = @compat UInt32(69640)
const CODEC_ID_ADPCM_ADX = @compat UInt32(69641)
const CODEC_ID_ADPCM_EA = @compat UInt32(69642)
const CODEC_ID_ADPCM_G726 = @compat UInt32(69643)
const CODEC_ID_ADPCM_CT = @compat UInt32(69644)
const CODEC_ID_ADPCM_SWF = @compat UInt32(69645)
const CODEC_ID_ADPCM_YAMAHA = @compat UInt32(69646)
const CODEC_ID_ADPCM_SBPRO_4 = @compat UInt32(69647)
const CODEC_ID_ADPCM_SBPRO_3 = @compat UInt32(69648)
const CODEC_ID_ADPCM_SBPRO_2 = @compat UInt32(69649)
const CODEC_ID_ADPCM_THP = @compat UInt32(69650)
const CODEC_ID_ADPCM_IMA_AMV = @compat UInt32(69651)
const CODEC_ID_ADPCM_EA_R1 = @compat UInt32(69652)
const CODEC_ID_ADPCM_EA_R3 = @compat UInt32(69653)
const CODEC_ID_ADPCM_EA_R2 = @compat UInt32(69654)
const CODEC_ID_ADPCM_IMA_EA_SEAD = @compat UInt32(69655)
const CODEC_ID_ADPCM_IMA_EA_EACS = @compat UInt32(69656)
const CODEC_ID_ADPCM_EA_XAS = @compat UInt32(69657)
const CODEC_ID_ADPCM_EA_MAXIS_XA = @compat UInt32(69658)
const CODEC_ID_ADPCM_IMA_ISS = @compat UInt32(69659)
const CODEC_ID_ADPCM_G722 = @compat UInt32(69660)
const CODEC_ID_AMR_NB = @compat UInt32(73728)
const CODEC_ID_AMR_WB = @compat UInt32(73729)
const CODEC_ID_RA_144 = @compat UInt32(77824)
const CODEC_ID_RA_288 = @compat UInt32(77825)
const CODEC_ID_ROQ_DPCM = @compat UInt32(81920)
const CODEC_ID_INTERPLAY_DPCM = @compat UInt32(81921)
const CODEC_ID_XAN_DPCM = @compat UInt32(81922)
const CODEC_ID_SOL_DPCM = @compat UInt32(81923)
const CODEC_ID_MP2 = @compat UInt32(86016)
const CODEC_ID_MP3 = @compat UInt32(86017)
const CODEC_ID_AAC = @compat UInt32(86018)
const CODEC_ID_AC3 = @compat UInt32(86019)
const CODEC_ID_DTS = @compat UInt32(86020)
const CODEC_ID_VORBIS = @compat UInt32(86021)
const CODEC_ID_DVAUDIO = @compat UInt32(86022)
const CODEC_ID_WMAV1 = @compat UInt32(86023)
const CODEC_ID_WMAV2 = @compat UInt32(86024)
const CODEC_ID_MACE3 = @compat UInt32(86025)
const CODEC_ID_MACE6 = @compat UInt32(86026)
const CODEC_ID_VMDAUDIO = @compat UInt32(86027)
const CODEC_ID_SONIC = @compat UInt32(86028)
const CODEC_ID_SONIC_LS = @compat UInt32(86029)
const CODEC_ID_FLAC = @compat UInt32(86030)
const CODEC_ID_MP3ADU = @compat UInt32(86031)
const CODEC_ID_MP3ON4 = @compat UInt32(86032)
const CODEC_ID_SHORTEN = @compat UInt32(86033)
const CODEC_ID_ALAC = @compat UInt32(86034)
const CODEC_ID_WESTWOOD_SND1 = @compat UInt32(86035)
const CODEC_ID_GSM = @compat UInt32(86036)
const CODEC_ID_QDM2 = @compat UInt32(86037)
const CODEC_ID_COOK = @compat UInt32(86038)
const CODEC_ID_TRUESPEECH = @compat UInt32(86039)
const CODEC_ID_TTA = @compat UInt32(86040)
const CODEC_ID_SMACKAUDIO = @compat UInt32(86041)
const CODEC_ID_QCELP = @compat UInt32(86042)
const CODEC_ID_WAVPACK = @compat UInt32(86043)
const CODEC_ID_DSICINAUDIO = @compat UInt32(86044)
const CODEC_ID_IMC = @compat UInt32(86045)
const CODEC_ID_MUSEPACK7 = @compat UInt32(86046)
const CODEC_ID_MLP = @compat UInt32(86047)
const CODEC_ID_GSM_MS = @compat UInt32(86048)
const CODEC_ID_ATRAC3 = @compat UInt32(86049)
const CODEC_ID_VOXWARE = @compat UInt32(86050)
const CODEC_ID_APE = @compat UInt32(86051)
const CODEC_ID_NELLYMOSER = @compat UInt32(86052)
const CODEC_ID_MUSEPACK8 = @compat UInt32(86053)
const CODEC_ID_SPEEX = @compat UInt32(86054)
const CODEC_ID_WMAVOICE = @compat UInt32(86055)
const CODEC_ID_WMAPRO = @compat UInt32(86056)
const CODEC_ID_WMALOSSLESS = @compat UInt32(86057)
const CODEC_ID_ATRAC3P = @compat UInt32(86058)
const CODEC_ID_EAC3 = @compat UInt32(86059)
const CODEC_ID_SIPR = @compat UInt32(86060)
const CODEC_ID_MP1 = @compat UInt32(86061)
const CODEC_ID_TWINVQ = @compat UInt32(86062)
const CODEC_ID_TRUEHD = @compat UInt32(86063)
const CODEC_ID_MP4ALS = @compat UInt32(86064)
const CODEC_ID_ATRAC1 = @compat UInt32(86065)
const CODEC_ID_BINKAUDIO_RDFT = @compat UInt32(86066)
const CODEC_ID_BINKAUDIO_DCT = @compat UInt32(86067)
const CODEC_ID_AAC_LATM = @compat UInt32(86068)
const CODEC_ID_QDMC = @compat UInt32(86069)
const CODEC_ID_CELT = @compat UInt32(86070)
const CODEC_ID_BMV_AUDIO = @compat UInt32(86071)
const CODEC_ID_FIRST_SUBTITLE = @compat UInt32(94208)
const CODEC_ID_DVD_SUBTITLE = @compat UInt32(94208)
const CODEC_ID_DVB_SUBTITLE = @compat UInt32(94209)
const CODEC_ID_TEXT = @compat UInt32(94210)
const CODEC_ID_XSUB = @compat UInt32(94211)
const CODEC_ID_SSA = @compat UInt32(94212)
const CODEC_ID_MOV_TEXT = @compat UInt32(94213)
const CODEC_ID_HDMV_PGS_SUBTITLE = @compat UInt32(94214)
const CODEC_ID_DVB_TELETEXT = @compat UInt32(94215)
const CODEC_ID_SRT = @compat UInt32(94216)
const CODEC_ID_FIRST_UNKNOWN = @compat UInt32(98304)
const CODEC_ID_TTF = @compat UInt32(98304)
const CODEC_ID_PROBE = @compat UInt32(102400)
const CODEC_ID_MPEG2TS = @compat UInt32(131072)
const CODEC_ID_MPEG4SYSTEMS = @compat UInt32(131073)
const CODEC_ID_FFMETADATA = @compat UInt32(135168)
# end enum CodecID

# begin enum Motion_Est_ID
typealias Motion_Est_ID Uint32
const ME_ZERO = @compat UInt32(1)
const ME_FULL = @compat UInt32(2)
const ME_LOG = @compat UInt32(3)
const ME_PHODS = @compat UInt32(4)
const ME_EPZS = @compat UInt32(5)
const ME_X1 = @compat UInt32(6)
const ME_HEX = @compat UInt32(7)
const ME_UMH = @compat UInt32(8)
const ME_ITER = @compat UInt32(9)
const ME_TESA = @compat UInt32(10)
# end enum Motion_Est_ID

# begin enum AVDiscard
typealias AVDiscard Cint
const AVDISCARD_NONE = int32(-16)
const AVDISCARD_DEFAULT = int32(0)
const AVDISCARD_NONREF = int32(8)
const AVDISCARD_BIDIR = int32(16)
const AVDISCARD_NONKEY = int32(32)
const AVDISCARD_ALL = int32(48)
# end enum AVDiscard

# begin enum AVColorPrimaries
typealias AVColorPrimaries Uint32
const AVCOL_PRI_BT709 = @compat UInt32(1)
const AVCOL_PRI_UNSPECIFIED = @compat UInt32(2)
const AVCOL_PRI_BT470M = @compat UInt32(4)
const AVCOL_PRI_BT470BG = @compat UInt32(5)
const AVCOL_PRI_SMPTE170M = @compat UInt32(6)
const AVCOL_PRI_SMPTE240M = @compat UInt32(7)
const AVCOL_PRI_FILM = @compat UInt32(8)
const AVCOL_PRI_NB = @compat UInt32(9)
# end enum AVColorPrimaries

# begin enum AVColorTransferCharacteristic
typealias AVColorTransferCharacteristic Uint32
const AVCOL_TRC_BT709 = @compat UInt32(1)
const AVCOL_TRC_UNSPECIFIED = @compat UInt32(2)
const AVCOL_TRC_GAMMA22 = @compat UInt32(4)
const AVCOL_TRC_GAMMA28 = @compat UInt32(5)
const AVCOL_TRC_NB = @compat UInt32(6)
# end enum AVColorTransferCharacteristic

# begin enum AVColorSpace
typealias AVColorSpace Uint32
const AVCOL_SPC_RGB = @compat UInt32(0)
const AVCOL_SPC_BT709 = @compat UInt32(1)
const AVCOL_SPC_UNSPECIFIED = @compat UInt32(2)
const AVCOL_SPC_FCC = @compat UInt32(4)
const AVCOL_SPC_BT470BG = @compat UInt32(5)
const AVCOL_SPC_SMPTE170M = @compat UInt32(6)
const AVCOL_SPC_SMPTE240M = @compat UInt32(7)
const AVCOL_SPC_NB = @compat UInt32(8)
# end enum AVColorSpace

# begin enum AVColorRange
typealias AVColorRange Uint32
const AVCOL_RANGE_UNSPECIFIED = @compat UInt32(0)
const AVCOL_RANGE_MPEG = @compat UInt32(1)
const AVCOL_RANGE_JPEG = @compat UInt32(2)
const AVCOL_RANGE_NB = @compat UInt32(3)
# end enum AVColorRange

# begin enum AVChromaLocation
typealias AVChromaLocation Uint32
const AVCHROMA_LOC_UNSPECIFIED = @compat UInt32(0)
const AVCHROMA_LOC_LEFT = @compat UInt32(1)
const AVCHROMA_LOC_CENTER = @compat UInt32(2)
const AVCHROMA_LOC_TOPLEFT = @compat UInt32(3)
const AVCHROMA_LOC_TOP = @compat UInt32(4)
const AVCHROMA_LOC_BOTTOMLEFT = @compat UInt32(5)
const AVCHROMA_LOC_BOTTOM = @compat UInt32(6)
const AVCHROMA_LOC_NB = @compat UInt32(7)
# end enum AVChromaLocation

# begin enum AVLPCType
typealias AVLPCType Cint
const AV_LPC_TYPE_DEFAULT = int32(-1)
const AV_LPC_TYPE_NONE = int32(0)
const AV_LPC_TYPE_FIXED = int32(1)
const AV_LPC_TYPE_LEVINSON = int32(2)
const AV_LPC_TYPE_CHOLESKY = int32(3)
const AV_LPC_TYPE_NB = int32(4)
# end enum AVLPCType

# begin enum AVAudioServiceType
typealias AVAudioServiceType Uint32
const AV_AUDIO_SERVICE_TYPE_MAIN = @compat UInt32(0)
const AV_AUDIO_SERVICE_TYPE_EFFECTS = @compat UInt32(1)
const AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = @compat UInt32(2)
const AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED = @compat UInt32(3)
const AV_AUDIO_SERVICE_TYPE_DIALOGUE = @compat UInt32(4)
const AV_AUDIO_SERVICE_TYPE_COMMENTARY = @compat UInt32(5)
const AV_AUDIO_SERVICE_TYPE_EMERGENCY = @compat UInt32(6)
const AV_AUDIO_SERVICE_TYPE_VOICE_OVER = @compat UInt32(7)
const AV_AUDIO_SERVICE_TYPE_KARAOKE = @compat UInt32(8)
const AV_AUDIO_SERVICE_TYPE_NB = @compat UInt32(9)
# end enum AVAudioServiceType

immutable RcOverride
    start_frame::Cint
    end_frame::Cint
    qscale::Cint
    quality_factor::Cfloat
end

immutable Array_2_Int16
    d1::Int16
    d2::Int16
end

zero(::Type{Array_2_Int16}) = Array_2_Int16(fill(zero(Int16),2)...)

immutable Array_3_Array_2_Int16
    d1::Array_2_Int16
    d2::Array_2_Int16
    d3::Array_2_Int16
end

zero(::Type{Array_3_Array_2_Int16}) = Array_3_Array_2_Int16(fill(zero(Array_2_Int16),3)...)

immutable AVPanScan
    id::Cint
    width::Cint
    height::Cint
    position::Array_3_Array_2_Int16
end

# begin enum AVPacketSideDataType
typealias AVPacketSideDataType Uint32
const AV_PKT_DATA_PALETTE = @compat UInt32(0)
const AV_PKT_DATA_NEW_EXTRADATA = @compat UInt32(1)
const AV_PKT_DATA_PARAM_CHANGE = @compat UInt32(2)
# end enum AVPacketSideDataType

immutable AVPacket
    pts::Int64
    dts::Int64
    data::Ptr{Uint8}
    size::Cint
    stream_index::Cint
    flags::Cint
    side_data::Ptr{Void}
    side_data_elems::Cint
    duration::Cint
    destruct::Ptr{Void}
    priv::Ptr{Void}
    pos::Int64
    convergence_duration::Int64
end

# begin enum AVSideDataParamChangeFlags
typealias AVSideDataParamChangeFlags Uint32
const AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = @compat UInt32(1)
const AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = @compat UInt32(2)
const AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = @compat UInt32(4)
const AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = @compat UInt32(8)
# end enum AVSideDataParamChangeFlags

immutable Array_4_Ptr
    d1::Ptr{Uint8}
    d2::Ptr{Uint8}
    d3::Ptr{Uint8}
    d4::Ptr{Uint8}
end

zero(::Type{Array_4_Ptr}) = Array_4_Ptr(fill(C_NULL,4)...)

immutable Array_4_Cint
    d1::Cint
    d2::Cint
    d3::Cint
    d4::Cint
end

zero(::Type{Array_4_Cint}) = Array_4_Cint(fill(zero(Cint),4)...)

immutable Array_2_Ptr
    d1::Ptr{Void}
    d2::Ptr{Void}
end

zero(::Type{Array_2_Ptr}) = Array_2_Ptr(fill(C_NULL,2)...)

immutable Array_4_Uint64
    d1::Uint64
    d2::Uint64
    d3::Uint64
    d4::Uint64
end

zero(::Type{Array_4_Uint64}) = Array_4_Uint64(fill(zero(Uint64),4)...)

immutable AVProfile
    profile::Cint
    name::Ptr{Uint8}
end

typealias AVCodecDefault Void

immutable AVCodec
    name::Ptr{Uint8}
    _type::AVMediaType
    id::CodecID
    priv_data_size::Cint
    init::Ptr{Void}
    encode::Ptr{Void}
    close::Ptr{Void}
    decode::Ptr{Void}
    capabilities::Cint
    next::Ptr{AVCodec}
    flush::Ptr{Void}
    supported_framerates::Ptr{AVRational}
    pix_fmts::Ptr{PixelFormat}
    long_name::Ptr{Uint8}
    supported_samplerates::Ptr{Cint}
    sample_fmts::Ptr{AVSampleFormat}
    channel_layouts::Ptr{Uint64}
    max_lowres::Uint8
    priv_class::Ptr{AVClass}
    profiles::Ptr{AVProfile}
    init_thread_copy::Ptr{Void}
    update_thread_context::Ptr{Void}
    defaults::Ptr{AVCodecDefault}
    init_static_data::Ptr{Void}
    encode2::Ptr{Void}
end

immutable Array_32_Uint8
    d1::Uint8
    d2::Uint8
    d3::Uint8
    d4::Uint8
    d5::Uint8
    d6::Uint8
    d7::Uint8
    d8::Uint8
    d9::Uint8
    d10::Uint8
    d11::Uint8
    d12::Uint8
    d13::Uint8
    d14::Uint8
    d15::Uint8
    d16::Uint8
    d17::Uint8
    d18::Uint8
    d19::Uint8
    d20::Uint8
    d21::Uint8
    d22::Uint8
    d23::Uint8
    d24::Uint8
    d25::Uint8
    d26::Uint8
    d27::Uint8
    d28::Uint8
    d29::Uint8
    d30::Uint8
    d31::Uint8
    d32::Uint8
end

zero(::Type{Array_32_Uint8}) = Array_32_Uint8(fill(zero(Uint8),32)...)

immutable Array_256_Uint32
    d1::Uint32
    d2::Uint32
    d3::Uint32
    d4::Uint32
    d5::Uint32
    d6::Uint32
    d7::Uint32
    d8::Uint32
    d9::Uint32
    d10::Uint32
    d11::Uint32
    d12::Uint32
    d13::Uint32
    d14::Uint32
    d15::Uint32
    d16::Uint32
    d17::Uint32
    d18::Uint32
    d19::Uint32
    d20::Uint32
    d21::Uint32
    d22::Uint32
    d23::Uint32
    d24::Uint32
    d25::Uint32
    d26::Uint32
    d27::Uint32
    d28::Uint32
    d29::Uint32
    d30::Uint32
    d31::Uint32
    d32::Uint32
    d33::Uint32
    d34::Uint32
    d35::Uint32
    d36::Uint32
    d37::Uint32
    d38::Uint32
    d39::Uint32
    d40::Uint32
    d41::Uint32
    d42::Uint32
    d43::Uint32
    d44::Uint32
    d45::Uint32
    d46::Uint32
    d47::Uint32
    d48::Uint32
    d49::Uint32
    d50::Uint32
    d51::Uint32
    d52::Uint32
    d53::Uint32
    d54::Uint32
    d55::Uint32
    d56::Uint32
    d57::Uint32
    d58::Uint32
    d59::Uint32
    d60::Uint32
    d61::Uint32
    d62::Uint32
    d63::Uint32
    d64::Uint32
    d65::Uint32
    d66::Uint32
    d67::Uint32
    d68::Uint32
    d69::Uint32
    d70::Uint32
    d71::Uint32
    d72::Uint32
    d73::Uint32
    d74::Uint32
    d75::Uint32
    d76::Uint32
    d77::Uint32
    d78::Uint32
    d79::Uint32
    d80::Uint32
    d81::Uint32
    d82::Uint32
    d83::Uint32
    d84::Uint32
    d85::Uint32
    d86::Uint32
    d87::Uint32
    d88::Uint32
    d89::Uint32
    d90::Uint32
    d91::Uint32
    d92::Uint32
    d93::Uint32
    d94::Uint32
    d95::Uint32
    d96::Uint32
    d97::Uint32
    d98::Uint32
    d99::Uint32
    d100::Uint32
    d101::Uint32
    d102::Uint32
    d103::Uint32
    d104::Uint32
    d105::Uint32
    d106::Uint32
    d107::Uint32
    d108::Uint32
    d109::Uint32
    d110::Uint32
    d111::Uint32
    d112::Uint32
    d113::Uint32
    d114::Uint32
    d115::Uint32
    d116::Uint32
    d117::Uint32
    d118::Uint32
    d119::Uint32
    d120::Uint32
    d121::Uint32
    d122::Uint32
    d123::Uint32
    d124::Uint32
    d125::Uint32
    d126::Uint32
    d127::Uint32
    d128::Uint32
    d129::Uint32
    d130::Uint32
    d131::Uint32
    d132::Uint32
    d133::Uint32
    d134::Uint32
    d135::Uint32
    d136::Uint32
    d137::Uint32
    d138::Uint32
    d139::Uint32
    d140::Uint32
    d141::Uint32
    d142::Uint32
    d143::Uint32
    d144::Uint32
    d145::Uint32
    d146::Uint32
    d147::Uint32
    d148::Uint32
    d149::Uint32
    d150::Uint32
    d151::Uint32
    d152::Uint32
    d153::Uint32
    d154::Uint32
    d155::Uint32
    d156::Uint32
    d157::Uint32
    d158::Uint32
    d159::Uint32
    d160::Uint32
    d161::Uint32
    d162::Uint32
    d163::Uint32
    d164::Uint32
    d165::Uint32
    d166::Uint32
    d167::Uint32
    d168::Uint32
    d169::Uint32
    d170::Uint32
    d171::Uint32
    d172::Uint32
    d173::Uint32
    d174::Uint32
    d175::Uint32
    d176::Uint32
    d177::Uint32
    d178::Uint32
    d179::Uint32
    d180::Uint32
    d181::Uint32
    d182::Uint32
    d183::Uint32
    d184::Uint32
    d185::Uint32
    d186::Uint32
    d187::Uint32
    d188::Uint32
    d189::Uint32
    d190::Uint32
    d191::Uint32
    d192::Uint32
    d193::Uint32
    d194::Uint32
    d195::Uint32
    d196::Uint32
    d197::Uint32
    d198::Uint32
    d199::Uint32
    d200::Uint32
    d201::Uint32
    d202::Uint32
    d203::Uint32
    d204::Uint32
    d205::Uint32
    d206::Uint32
    d207::Uint32
    d208::Uint32
    d209::Uint32
    d210::Uint32
    d211::Uint32
    d212::Uint32
    d213::Uint32
    d214::Uint32
    d215::Uint32
    d216::Uint32
    d217::Uint32
    d218::Uint32
    d219::Uint32
    d220::Uint32
    d221::Uint32
    d222::Uint32
    d223::Uint32
    d224::Uint32
    d225::Uint32
    d226::Uint32
    d227::Uint32
    d228::Uint32
    d229::Uint32
    d230::Uint32
    d231::Uint32
    d232::Uint32
    d233::Uint32
    d234::Uint32
    d235::Uint32
    d236::Uint32
    d237::Uint32
    d238::Uint32
    d239::Uint32
    d240::Uint32
    d241::Uint32
    d242::Uint32
    d243::Uint32
    d244::Uint32
    d245::Uint32
    d246::Uint32
    d247::Uint32
    d248::Uint32
    d249::Uint32
    d250::Uint32
    d251::Uint32
    d252::Uint32
    d253::Uint32
    d254::Uint32
    d255::Uint32
    d256::Uint32
end

zero(::Type{Array_256_Uint32}) = Array_256_Uint32(fill(zero(Uint32),256)...)

immutable AVPaletteControl
    palette_changed::Cint
    palette::Array_256_Uint32
end

immutable AVHWAccel
    name::Ptr{Uint8}
    _type::AVMediaType
    id::CodecID
    pix_fmt::PixelFormat
    capabilities::Cint
    next::Ptr{AVHWAccel}
    start_frame::Ptr{Void}
    decode_slice::Ptr{Void}
    end_frame::Ptr{Void}
    priv_data_size::Cint
end

typealias AVCodecInternal Void

# begin enum AVFieldOrder
typealias AVFieldOrder Uint32
const AV_FIELD_UNKNOWN = @compat UInt32(0)
const AV_FIELD_PROGRESSIVE = @compat UInt32(1)
const AV_FIELD_TT = @compat UInt32(2)
const AV_FIELD_BB = @compat UInt32(3)
const AV_FIELD_TB = @compat UInt32(4)
const AV_FIELD_BT = @compat UInt32(5)
# end enum AVFieldOrder

immutable AVCodecContext
    av_class::Ptr{AVClass}
    bit_rate::Cint
    bit_rate_tolerance::Cint
    flags::Cint
    sub_id::Cint
    me_method::Cint
    extradata::Ptr{Uint8}
    extradata_size::Cint
    time_base::AVRational
    width::Cint
    height::Cint
    gop_size::Cint
    pix_fmt::PixelFormat
    draw_horiz_band::Ptr{Void}
    sample_rate::Cint
    channels::Cint
    sample_fmt::AVSampleFormat
    frame_size::Cint
    frame_number::Cint
    delay::Cint
    qcompress::Cfloat
    qblur::Cfloat
    qmin::Cint
    qmax::Cint
    max_qdiff::Cint
    max_b_frames::Cint
    b_quant_factor::Cfloat
    rc_strategy::Cint
    b_frame_strategy::Cint
    codec::Ptr{AVCodec}
    priv_data::Ptr{Void}
    rtp_payload_size::Cint
    rtp_callback::Ptr{Void}
    mv_bits::Cint
    header_bits::Cint
    i_tex_bits::Cint
    p_tex_bits::Cint
    i_count::Cint
    p_count::Cint
    skip_count::Cint
    misc_bits::Cint
    frame_bits::Cint
    opaque::Ptr{Void}
    codec_name::Array_32_Uint8
    codec_type::AVMediaType
    codec_id::CodecID
    codec_tag::Uint32
    workaround_bugs::Cint
    luma_elim_threshold::Cint
    chroma_elim_threshold::Cint
    strict_std_compliance::Cint
    b_quant_offset::Cfloat
    error_recognition::Cint
    get_buffer::Ptr{Void}
    release_buffer::Ptr{Void}
    has_b_frames::Cint
    block_align::Cint
    parse_only::Cint
    mpeg_quant::Cint
    stats_out::Ptr{Uint8}
    stats_in::Ptr{Uint8}
    rc_qsquish::Cfloat
    rc_qmod_amp::Cfloat
    rc_qmod_freq::Cint
    rc_override::Ptr{RcOverride}
    rc_override_count::Cint
    rc_eq::Ptr{Uint8}
    rc_max_rate::Cint
    rc_min_rate::Cint
    rc_buffer_size::Cint
    rc_buffer_aggressivity::Cfloat
    i_quant_factor::Cfloat
    i_quant_offset::Cfloat
    rc_initial_cplx::Cfloat
    dct_algo::Cint
    lumi_masking::Cfloat
    temporal_cplx_masking::Cfloat
    spatial_cplx_masking::Cfloat
    p_masking::Cfloat
    dark_masking::Cfloat
    idct_algo::Cint
    slice_count::Cint
    slice_offset::Ptr{Cint}
    error_concealment::Cint
    dsp_mask::Uint32
    bits_per_coded_sample::Cint
    prediction_method::Cint
    sample_aspect_ratio::AVRational
    coded_frame::Ptr{AVFrame}
    debug::Cint
    debug_mv::Cint
    error::Array_4_Uint64
    me_cmp::Cint
    me_sub_cmp::Cint
    mb_cmp::Cint
    ildct_cmp::Cint
    dia_size::Cint
    last_predictor_count::Cint
    pre_me::Cint
    me_pre_cmp::Cint
    pre_dia_size::Cint
    me_subpel_quality::Cint
    get_format::Ptr{Void}
    dtg_active_format::Cint
    me_range::Cint
    intra_quant_bias::Cint
    inter_quant_bias::Cint
    color_table_id::Cint
    internal_buffer_count::Cint
    internal_buffer::Ptr{Void}
    global_quality::Cint
    coder_type::Cint
    context_model::Cint
    slice_flags::Cint
    xvmc_acceleration::Cint
    mb_decision::Cint
    intra_matrix::Ptr{Uint16}
    inter_matrix::Ptr{Uint16}
    stream_codec_tag::Uint32
    scenechange_threshold::Cint
    lmin::Cint
    lmax::Cint
    palctrl::Ptr{AVPaletteControl}
    noise_reduction::Cint
    reget_buffer::Ptr{Void}
    rc_initial_buffer_occupancy::Cint
    inter_threshold::Cint
    flags2::Cint
    error_rate::Cint
    antialias_algo::Cint
    quantizer_noise_shaping::Cint
    thread_count::Cint
    execute::Ptr{Void}
    thread_opaque::Ptr{Void}
    me_threshold::Cint
    mb_threshold::Cint
    intra_dc_precision::Cint
    nsse_weight::Cint
    skip_top::Cint
    skip_bottom::Cint
    profile::Cint
    level::Cint
    lowres::Cint
    coded_width::Cint
    coded_height::Cint
    frame_skip_threshold::Cint
    frame_skip_factor::Cint
    frame_skip_exp::Cint
    frame_skip_cmp::Cint
    border_masking::Cfloat
    mb_lmin::Cint
    mb_lmax::Cint
    me_penalty_compensation::Cint
    skip_loop_filter::AVDiscard
    skip_idct::AVDiscard
    skip_frame::AVDiscard
    bidir_refine::Cint
    brd_scale::Cint
    crf::Cfloat
    cqp::Cint
    keyint_min::Cint
    refs::Cint
    chromaoffset::Cint
    bframebias::Cint
    trellis::Cint
    complexityblur::Cfloat
    deblockalpha::Cint
    deblockbeta::Cint
    partitions::Cint
    directpred::Cint
    cutoff::Cint
    scenechange_factor::Cint
    mv0_threshold::Cint
    b_sensitivity::Cint
    compression_level::Cint
    min_prediction_order::Cint
    max_prediction_order::Cint
    lpc_coeff_precision::Cint
    prediction_order_method::Cint
    min_partition_order::Cint
    max_partition_order::Cint
    timecode_frame_start::Int64
    request_channels::Cint
    drc_scale::Cfloat
    reordered_opaque::Int64
    bits_per_raw_sample::Cint
    channel_layout::Uint64
    request_channel_layout::Uint64
    rc_max_available_vbv_use::Cfloat
    rc_min_vbv_overflow_use::Cfloat
    hwaccel::Ptr{AVHWAccel}
    ticks_per_frame::Cint
    hwaccel_context::Ptr{Void}
    color_primaries::AVColorPrimaries
    color_trc::AVColorTransferCharacteristic
    colorspace::AVColorSpace
    color_range::AVColorRange
    chroma_sample_location::AVChromaLocation
    execute2::Ptr{Void}
    weighted_p_pred::Cint
    aq_mode::Cint
    aq_strength::Cfloat
    psy_rd::Cfloat
    psy_trellis::Cfloat
    rc_lookahead::Cint
    crf_max::Cfloat
    log_level_offset::Cint
    lpc_type::AVLPCType
    lpc_passes::Cint
    slices::Cint
    subtitle_header::Ptr{Uint8}
    subtitle_header_size::Cint
    pkt::Ptr{AVPacket}
    is_copy::Cint
    thread_type::Cint
    active_thread_type::Cint
    thread_safe_callbacks::Cint
    vbv_delay::Uint64
    audio_service_type::AVAudioServiceType
    request_sample_fmt::AVSampleFormat
    err_recognition::Cint
    internal::Ptr{AVCodecInternal}
    field_order::AVFieldOrder
end

immutable AVFrame
    data::Array_4_Ptr
    linesize::Array_4_Cint
    base::Array_4_Ptr
    key_frame::Cint
    pict_type::AVPictureType
    pts::Int64
    coded_picture_number::Cint
    display_picture_number::Cint
    quality::Cint
    age::Cint
    reference::Cint
    qscale_table::Ptr{Int8}
    qstride::Cint
    mbskip_table::Ptr{Uint8}
    motion_val::Array_2_Ptr
    mb_type::Ptr{Uint32}
    motion_subsample_log2::Uint8
    opaque::Ptr{Void}
    error::Array_4_Uint64
    _type::Cint
    repeat_pict::Cint
    qscale_type::Cint
    interlaced_frame::Cint
    top_field_first::Cint
    pan_scan::Ptr{AVPanScan}
    palette_has_changed::Cint
    buffer_hints::Cint
    dct_coeff::Ptr{Int16}
    ref_index::Array_2_Ptr
    reordered_opaque::Int64
    hwaccel_picture_private::Ptr{Void}
    pkt_pts::Int64
    pkt_dts::Int64
    owner::Ptr{AVCodecContext}
    thread_opaque::Ptr{Void}
    nb_samples::Cint
    extended_data::Ptr{Ptr{Uint8}}
    sample_aspect_ratio::AVRational
    width::Cint
    height::Cint
    format::Cint
end

immutable AVPicture
    data::Array_4_Ptr
    linesize::Array_4_Cint
end

# begin enum AVSubtitleType
typealias AVSubtitleType Uint32
const SUBTITLE_NONE = @compat UInt32(0)
const SUBTITLE_BITMAP = @compat UInt32(1)
const SUBTITLE_TEXT = @compat UInt32(2)
const SUBTITLE_ASS = @compat UInt32(3)
# end enum AVSubtitleType

immutable AVSubtitleRect
    x::Cint
    y::Cint
    w::Cint
    h::Cint
    nb_colors::Cint
    pict::AVPicture
    _type::AVSubtitleType
    text::Ptr{Uint8}
    ass::Ptr{Uint8}
end

immutable AVSubtitle
    format::Uint16
    start_display_time::Uint32
    end_display_time::Uint32
    num_rects::Uint32
    rects::Ptr{Ptr{AVSubtitleRect}}
    pts::Int64
end

typealias ReSampleContext Void
typealias AVResampleContext Void

immutable Array_4_Int64
    d1::Int64
    d2::Int64
    d3::Int64
    d4::Int64
end

zero(::Type{Array_4_Int64}) = Array_4_Int64(fill(zero(Int64),4)...)

immutable Array_5_Cint
    d1::Cint
    d2::Cint
    d3::Cint
    d4::Cint
    d5::Cint
end

zero(::Type{Array_5_Cint}) = Array_5_Cint(fill(zero(Cint),5)...)

immutable AVCodecParser
    codec_ids::Array_5_Cint
    priv_data_size::Cint
    parser_init::Ptr{Void}
    parser_parse::Ptr{Void}
    parser_close::Ptr{Void}
    split::Ptr{Void}
    next::Ptr{AVCodecParser}
end

immutable AVCodecParserContext
    priv_data::Ptr{Void}
    parser::Ptr{AVCodecParser}
    frame_offset::Int64
    cur_offset::Int64
    next_frame_offset::Int64
    pict_type::Cint
    repeat_pict::Cint
    pts::Int64
    dts::Int64
    last_pts::Int64
    last_dts::Int64
    fetch_timestamp::Cint
    cur_frame_start_index::Cint
    cur_frame_offset::Array_4_Int64
    cur_frame_pts::Array_4_Int64
    cur_frame_dts::Array_4_Int64
    flags::Cint
    offset::Int64
    cur_frame_end::Array_4_Int64
    key_frame::Cint
    convergence_duration::Int64
    dts_sync_point::Cint
    dts_ref_dts_delta::Cint
    pts_dts_delta::Cint
    cur_frame_pos::Array_4_Int64
    pos::Int64
    last_pos::Int64
end

immutable AVBitStreamFilter
    name::Ptr{Uint8}
    priv_data_size::Cint
    filter::Ptr{Void}
    close::Ptr{Void}
    next::Ptr{AVBitStreamFilter}
end

immutable AVBitStreamFilterContext
    priv_data::Ptr{Void}
    filter::Ptr{AVBitStreamFilter}
    parser::Ptr{AVCodecParserContext}
    next::Ptr{AVBitStreamFilterContext}
end

# begin enum AVLockOp
typealias AVLockOp Uint32
const AV_LOCK_CREATE = @compat UInt32(0)
const AV_LOCK_OBTAIN = @compat UInt32(1)
const AV_LOCK_RELEASE = @compat UInt32(2)
const AV_LOCK_DESTROY = @compat UInt32(3)
# end enum AVLockOp

const LIBAVCODEC_VERSION_MAJOR = 53
const LIBAVCODEC_VERSION_MINOR = 35
const LIBAVCODEC_VERSION_MICRO = 0

# Skipping MacroDefinition: LIBAVCODEC_VERSION_INT AV_VERSION_INT ( LIBAVCODEC_VERSION_MAJOR , LIBAVCODEC_VERSION_MINOR , LIBAVCODEC_VERSION_MICRO )
# Skipping MacroDefinition: LIBAVCODEC_VERSION AV_VERSION ( LIBAVCODEC_VERSION_MAJOR , LIBAVCODEC_VERSION_MINOR , LIBAVCODEC_VERSION_MICRO )

const LIBAVCODEC_BUILD = LIBAVCODEC_VERSION_INT

# Skipping MacroDefinition: LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY ( LIBAVCODEC_VERSION )
# Skipping MacroDefinition: FF_API_PALETTE_CONTROL ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_OLD_SAMPLE_FMT ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_OLD_AUDIOCONVERT ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_ANTIALIAS_ALGO ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_REQUEST_CHANNELS ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_OPT_H ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_THREAD_INIT ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_OLD_FF_PICT_TYPES ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_FLAC_GLOBAL_OPTS ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_GET_PIX_FMT_NAME ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_ALLOC_CONTEXT ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_AVCODEC_OPEN ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_DRC_SCALE ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_ER ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_AVCODEC_INIT ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_X264_GLOBAL_OPTS ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_MPEGVIDEO_GLOBAL_OPTS ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_LAME_GLOBAL_OPTS ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_SNOW_GLOBAL_OPTS ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_MJPEG_GLOBAL_OPTS ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_GET_ALPHA_INFO ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_PARSE_FRAME ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_INTERNAL_CONTEXT ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_TIFFENC_COMPLEVEL ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_DATA_POINTERS ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_OLD_DECODE_AUDIO ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_AVFRAME_AGE ( LIBAVCODEC_VERSION_MAJOR < 54 )
# Skipping MacroDefinition: FF_API_OLD_ENCODE_AUDIO ( LIBAVCODEC_VERSION_MAJOR < 54 )

immutable vaapi_context
    display::Ptr{Void}
    config_id::Uint32
    context_id::Uint32
    pic_param_buf_id::Uint32
    iq_matrix_buf_id::Uint32
    bitplane_buf_id::Uint32
    slice_buf_ids::Ptr{Uint32}
    n_slice_buf_ids::Uint32
    slice_buf_ids_alloc::Uint32
    slice_params::Ptr{Void}
    slice_param_size::Uint32
    slice_params_alloc::Uint32
    slice_count::Uint32
    slice_data::Ptr{Uint8}
    slice_data_size::Uint32
end

const FF_VDPAU_STATE_USED_FOR_RENDER = 1
const FF_VDPAU_STATE_USED_FOR_REFERENCE = 2

immutable vdpau_render_state
    surface::VdpVideoSurface
    state::Cint
    info::VdpPictureInfo
    bitstream_buffers_allocated::Cint
    bitstream_buffers_used::Cint
    bitstream_buffers::Ptr{VdpBitstreamBuffer}
end

const AV_XVMC_ID = 0x1dc711c0

immutable xvmc_pix_fmt
    xvmc_id::Cint
    data_blocks::Ptr{Int16}
    mv_blocks::Ptr{XvMCMacroBlock}
    allocated_mv_blocks::Cint
    allocated_data_blocks::Cint
    idct::Cint
    unsigned_intra::Cint
    p_surface::Ptr{XvMCSurface}
    p_past_surface::Ptr{XvMCSurface}
    p_future_surface::Ptr{XvMCSurface}
    picture_structure::Uint32
    flags::Uint32
    start_mv_blocks_num::Cint
    filled_mv_blocks_num::Cint
    next_free_data_block_num::Cint
end


text:
using Revise, PyPlot, LinearAlgebra, Sobol, ForwardDiff

using MaximumEntropyBasisFunctions
using ISRLutils # Pkg.add("https://github.com/isrlab/ISRLutils)

# # With random points
# lb = [-1 -1]; ub = [1 1];
# p = ISRLutils.cornerPoints(lb,ub)
# s = SobolSeq(lb,ub);
# skip(s,100);
# xData = [p' hcat([next!(s) for i = 1:30]...)];
# xData = hcat([next!(s) for i = 1:20]...);

# With uniform grid
αMax = 3; nData = 3*[1,1]; nEval = 50*[1,1];
lb = [-1,-1]*αMax; ub = [1,1]*αMax;
xData = ISRLutils.GenerateNDGrid(lb,ub,nData);
xEval = ISRLutils.GenerateNDGrid(0.99*lb,0.99*ub,nEval);

# Crete me basis object
ϕ = MaximumEntropyBasisFunctions.CreateMaxEntBasis(xData,nn=4);

# Evaluate mexent basis functions at xEval
nBasis = size(xData,2);
nEval1 = size(xEval,2)
Phi = zeros(nEval1,nBasis);
derPhi = zeros(2*nEval1,nBasis);
@time for i ∈ 1:nEval1
	#  Phi1[i,:] = getBasis(xData,xEval[:,i]);
	 Phi[i,:] = MaximumEntropyBasisFunctions.EvaluateMaxEntBasis(ϕ,xEval[:,i])
	 derPhi[(2*i-1):2*i,:] = MaximumEntropyBasisFunctions.getBasisDerivative(ϕ,xEval[:,i],Phi[i,:]);
end

# Plotting
nCol = 5;
nRow = div(nBasis,nCol)+1;

rc("text", usetex=true);
rc("font", serif="Helvetica");
rc("font", size=9);

figure(1); clf(); pygui(true);
figure(2); clf(); pygui(true);
figure(3); clf(); pygui(true);

XX = reshape(xEval[1,:],nEval[1],nEval[2]);
YY = reshape(xEval[2,:],nEval[1],nEval[2]);
cmin = minimum(derPhi);
cmax = maximum(derPhi);

# Generate functions
for i in 1:nBasis
    figure(1); subplot(nRow,nCol,i);
	pcolor(XX,YY,reshape(Phi[:,i], nEval[1],nEval[2]),shading="auto",ec="face");
	# surf(XX,YY,reshape(Phi[:,i], nEval[1],nEval[2]),cmap=PyPlot.cm.coolwarm);
	scatter(xData[1,:],xData[2,:],s=3,fc="r",ec="none");
	str = "\$" * "\\phi_" * "{$i}" * "\$";
	title(LaTeXString(str));
	axis("equal"); axis("off");  #grid("on");

	# ϕ_x1
	figure(2); subplot(nRow,nCol,i);
	pcolor(XX,YY,reshape(derPhi[1:2:end,i], nEval[1],nEval[2]),shading="auto",ec="face", vmin=cmin, vmax=cmax);
	# surf(XX,YY,reshape(derPhi[1:2:end,i], nEval[1],nEval[2]));
	scatter(xData[1,:],xData[2,:],s=3,fc="r",ec="none");
	str = "\$" * "\\frac{\\partial \\phi_" * "{$i}" * "}{\\partial x_1}\$";
	title(LaTeXString(str));
	axis("equal"); axis("off");  #grid("on");

	# ϕ_x2
	figure(3); subplot(nRow,nCol,i);
	pcolor(XX,YY,reshape(derPhi[2:2:end,i], nEval[1],nEval[2]),shading="auto",ec="face",vmin=cmin, vmax=cmax);
	# surf(XX,YY,reshape(derPhi[2:2:end,i], nEval[1],nEval[2]));
	scatter(xData[1,:],xData[2,:],s=3,fc="r",ec="none");
	# str = "\$" * "\\phi_" * "{$i}" * "\$";
	str = "\$" * "\\frac{\\partial \\phi_" * "{$i}" * "}{\\partial x_2}\$";
	title(LaTeXString(str));
	axis("equal"); axis("off");  #grid("on");
end

figure(1);tight_layout(); #savefig("maxent2D.pdf",dpi=300);
figure(2);tight_layout(); #savefig("maxent2Ddx1.pdf",dpi=300);
figure(3);tight_layout(); #savefig("maxent2Ddx2.pdf",dpi=300);

println("Plotting done ...");
# savefig("maxent2D.pdf",dpi=300);

max_stars_repo_name: isrlab/MaximumEntropyBasisFunctions

max_issues_repo_name: isrlab/MaximumEntropyBasisFunctions

max_forks_repo_name: isrlab/MaximumEntropyBasisFunctions


text:
# This file is a part of TextClassification.jl
# License is Apache 2.0: https://www.apache.org/licenses/LICENSE-2.0.txt

module TextClassification
using SimilaritySearch, KCenters, KNearestCenters, TextSearch, SearchModels
import SearchModels: combine, combine_select, mutate, config_type
using Parameters, CategoricalArrays

include("centerselection.jl")
include("textconfigspace.jl")
include("textmodelspace.jl")
include("knnclassifier.jl")
include("liblinearconfig.jl")
include("microtcconfig.jl")
include("microtc.jl")
end # module


text:
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

module TestRandom
using MXNet
using Test
using Statistics

function test_uniform()
  dims = (100, 100, 2)
  @info "random::uniform::dims = $dims"

  low = -10; high = 10
  seed = 123
  mx.seed!(seed)
  ret1 = mx.rand(dims..., low = low, high = high)

  mx.seed!(seed)
  ret2 = mx.empty(dims)
  mx.rand!(ret2, low = low, high = high)

  @test copy(ret1) == copy(ret2)
  @test abs(mean(copy(ret1)) - (high+low)/2) < 0.1
end

function test_gaussian()
  dims = (80, 80, 4)
  @info "random::gaussian::dims = $dims"

  μ = 10; σ = 2
  seed = 456
  mx.seed!(seed)
  ret1 = mx.randn(dims..., μ = μ, σ = σ)

  mx.seed!(seed)
  ret2 = mx.empty(dims)
  mx.randn!(ret2, μ = μ, σ = σ)

  @test copy(ret1) == copy(ret2)
  @test abs(mean(copy(ret1)) - μ) < 0.1
  @test abs(std(copy(ret1)) - σ) < 0.1
end

@testset "Random Test" begin
  test_uniform()
  test_gaussian()
end

end

max_stars_repo_name: hsali/incubator-mxnet

max_issues_repo_name: hsali/incubator-mxnet

max_forks_repo_name: hsali/incubator-mxnet


text:
const GENCODE_INDEX_VER = 2

immutable GencodeExon
    number::Int32
    start_pos::Int64
    end_pos::Int64
end

type GencodeTranscript
    id::ASCIIString
    start_pos::Int64
    end_pos::Int64
    attributes::OrderedDict{ASCIIString, ASCIIString}
    exons::Array{GencodeExon, 1}
end

type GencodeGene
    name::ASCIIString
    chr::ASCIIString
    id::ASCIIString
    start_pos::Int64
    end_pos::Int64
    strand::ASCIIString
    attributes::OrderedDict{ASCIIString, ASCIIString}
    transcripts::Array{GencodeTranscript, 1}
end

"""
reference->chromosome dict->gene list->transcript list->exon list
"""
function gencode_load(ref::ASCIIString)
    ref = lowercase(ref)
    if !haskey(gencode_releases, ref)
        error("$ref is not supported in current gencode releases, please use one of grch37/grch38, or hg19:")
    end
    source = gencode_releases[ref]["source"]
    localfile = gencode_releases[ref]["localfile"]
    if !isfile(localfile)
        println("# gencode dataset is not downloaded, download it now...")
        try
            download(source, localfile * ".part")
            mv(localfile * ".part", localfile)
        catch(e)
            error("Failed to download gencode reference from $source, please manually download it and put it at $localfile")
        end
    end
    return gencode_load_file(localfile)
end

function gencode_load_file(filename::AbstractString)
    cache_path = "$filename.v$GENCODE_INDEX_VER.idx"
    loaded = false
    # load the index from a cache file
    if isfile(cache_path)
        try
        io = open(cache_path)
        index = deserialize(io)
        if !isa(index, Dict)
            error("invalid index file, index should be a serialized Dict")
        end
        loaded = true
        return index
        catch(e)
            warn(e)
            warn("Failed to load the pre-built index ($cache_path), maybe it is not completed when saving it. Attemping to delete it now!")
            try
                rm(cache_path)
            catch(e)
                warn(e)
                warn("Failed to delete $cache_path, please do it manually")
            end
        end
    end

    if !loaded
        index = parse_gencode(filename)
        # save the index to a cache file
        try
            io = open(cache_path, "w")
            serialize(io, index)
        catch(e)
            warn("Unable to save index to $cache_path. Please check if the folder is writable for current user, if the index is not cached, it will be built every time you run FusionDirect, which is slow.")
        end
        return index
    end
end

function parse_gencode(filename::AbstractString)
    index = Dict()
    gtf, stream = gtf_read(filename, loaddata = false)
    gene = nothing
    transcript = nothing
    while (row = gtf_read_row(stream)) != false
        if row.feature == "gene"
            gene_id = strip(row.attributes["gene_id"], '"')
            gene_name = strip(row.attributes["gene_name"], '"')
            gene = GencodeGene(gene_name, row.seqname, gene_id, row.start_pos, row.end_pos, row.strand, row.attributes, Array{GencodeTranscript, 1}())
            if !haskey(index, row.seqname)
                index[row.seqname] = []
            end
            push!(index[row.seqname], gene)
        elseif row.feature == "transcript"
            transcript_id = strip(row.attributes["transcript_id"], '"')
            transcript = GencodeTranscript(transcript_id, row.start_pos, row.end_pos, row.attributes, Array{GencodeExon, 1}())
            if gene == nothing
                error("wrong format")
            end
            push!(gene.transcripts, transcript)
        elseif row.feature == "exon"
            exon_number = strip(row.attributes["exon_number"], '"')
            exon = GencodeExon(parse(Int32, exon_number), row.start_pos, row.end_pos)
            if transcript == nothing
                error("wrong format")
            end
            push!(transcript.exons, exon)
        end
    end
    return index
end


text:
module TestCodeInfoTools

using CodeInfoTools
using Test

include("canvas.jl")
include("pipe.jl")
include("misc.jl")

end # module