From a9b1baccaf4c6d850befb309da2ae1161c6462ec Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 1 Feb 2017 18:03:33 -0600 Subject: [PATCH 1/7] Turn off precompilation explicitly There's logic here that is incompatible with precompilation. Better to prevent attempts to use it. --- src/VideoIO.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/VideoIO.jl b/src/VideoIO.jl index cb9ce2c2..65e9ee14 100644 --- a/src/VideoIO.jl +++ b/src/VideoIO.jl @@ -1,3 +1,5 @@ +__precompile__(false) + module VideoIO using Compat From 54dcb064a03d16283bfe3334271e02202206e73f Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 1 Feb 2017 18:03:59 -0600 Subject: [PATCH 2/7] Update link for Annie Oakley --- src/testvideos.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testvideos.jl b/src/testvideos.jl index 14737af4..c4946edd 100644 --- a/src/testvideos.jl +++ b/src/testvideos.jl @@ -46,7 +46,7 @@ const videofiles = Dict( "pubic_domain (US)", "", "http://commons.wikimedia.org/wiki/File:Annie_Oakley_shooting_glass_balls,_1894.ogg", - "http://upload.wikimedia.org/wikipedia/commons/d/dd/Annie_Oakley_shooting_glass_balls%2C_1894.ogg"), + "https://upload.wikimedia.org/wikipedia/commons/8/87/Annie_Oakley_shooting_glass_balls%2C_1894.ogv"), "crescent-moon.ogv" => VideoFile("crescent-moon.ogv", "Moonset (time-lapse).", From 7667984c454947901a31b9243d30cb4e358e4bd8 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 1 Feb 2017 18:04:31 -0600 Subject: [PATCH 3/7] Update to the new Images (and decouple from anything more than ImageCore) --- REQUIRE | 10 +++++---- src/VideoIO.jl | 2 +- src/avio.jl | 56 ++++++++++++++------------------------------------ test/avio.jl | 32 +++++++++++++---------------- 4 files changed, 36 insertions(+), 64 deletions(-) diff --git a/REQUIRE b/REQUIRE index 171fece3..a6e515e0 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,7 +1,9 @@ -julia 0.4 -Compat 0.8.7 +julia 0.5 BinDeps 0.3.4 -Images 0.4.4 -ImageView 0.1.4 +FixedPointNumbers 0.3.0 +ColorTypes +FileIO +ImageCore +ImageView 0.3.0 @osx Homebrew @linux Glob diff --git a/src/VideoIO.jl b/src/VideoIO.jl index 65e9ee14..500dd9e9 100644 --- a/src/VideoIO.jl +++ b/src/VideoIO.jl @@ -2,7 +2,7 @@ __precompile__(false) module VideoIO -using Compat +using FixedPointNumbers, ColorTypes, ImageCore include("init.jl") diff --git a/src/avio.jl b/src/avio.jl index 992d3655..6ea12ebd 100644 --- a/src/avio.jl +++ b/src/avio.jl @@ -13,17 +13,12 @@ end abstract StreamContext -if isdefined(Main, :FixedPointNumbers) - UFixed8 = Main.FixedPointNumbers.UFixed8 -end +typealias EightBitTypes Union{UInt8, N0f8, Main.ColorTypes.RGB{N0f8}} +typealias PermutedArray{T,N,perm,iperm,AA<:Array} Base.PermutedDimsArrays.PermutedDimsArray{T,N,perm,iperm,AA} +typealias VidArray{T,N} Union{Array{T,N},PermutedArray{T,N}} -if isdefined(Main, :ColorTypes) - typealias EightBitTypes Union{UInt8, UFixed8, Main.ColorTypes.RGB{UFixed8}} -elseif isdefined(Main, :FixedPointNumbers) - typealias EightBitTypes Union{UInt8, UFixed8} -else - typealias EightBitTypes UInt8 -end +# TODO: move this to Base +Base.unsafe_convert{T}(::Type{Ptr{T}}, A::PermutedArray{T}) = Base.unsafe_convert(Ptr{T}, parent(A)) # An audio-visual input stream/file type AVInput{I} @@ -405,9 +400,9 @@ function retrieve(r::VideoReader{TRANSCODE}) # true=transcode end if t.target_bits_per_pixel == 8 - buf = Array(UInt8, r.width, r.height) + buf = permuteddimsview(Matrix{Gray{N0f8}}(r.width, r.height), (2,1)) else - buf = Array(UInt8, t.target_bits_per_pixel>>3, r.width, r.height) + buf = permuteddimsview(Matrix{RGB{N0f8}}(r.width, r.height), (2,1)) end retrieve!(r, buf) @@ -428,7 +423,7 @@ function retrieve(r::VideoReader{NO_TRANSCODE}) # false=don't transcode end # Converts a grabbed frame to the correct format (RGB by default) -function retrieve!{T<:EightBitTypes}(r::VideoReader{TRANSCODE}, buf::Array{T}) +function retrieve!{T<:EightBitTypes}(r::VideoReader{TRANSCODE}, buf::VidArray{T}) while !have_frame(r) idx = pump(r.avin) idx == r.stream_index0 && break @@ -471,7 +466,7 @@ function retrieve!{T<:EightBitTypes}(r::VideoReader{TRANSCODE}, buf::Array{T}) return buf end -function retrieve!{T<:EightBitTypes}(r::VideoReader{NO_TRANSCODE}, buf::Array{T}) +function retrieve!{T<:EightBitTypes}(r::VideoReader{NO_TRANSCODE}, buf::VidArray{T}) while !have_frame(r) idx = pump(r.avin) idx == r.stream_index0 && break @@ -496,9 +491,9 @@ isopen{I<:IO}(avin::AVInput{I}) = isopen(avin.io) isopen(avin::AVInput) = avin.isopen isopen(r::VideoReader) = isopen(r.avin) -bufsize_check{T<:EightBitTypes}(r::VideoReader{NO_TRANSCODE}, buf::Array{T}) = (length(buf)*sizeof(T) == avpicture_get_size(r.format, r.width, r.height)) -bufsize_check{T<:EightBitTypes}(r::VideoReader{TRANSCODE}, buf::Array{T}) = bufsize_check(r.transcodeContext, buf) -bufsize_check{T<:EightBitTypes}(t::VideoTranscodeContext, buf::Array{T}) = (length(buf)*sizeof(T) == avpicture_get_size(t.target_pix_fmt, t.width, t.height)) +bufsize_check{T<:EightBitTypes}(r::VideoReader{NO_TRANSCODE}, buf::VidArray{T}) = (length(buf)*sizeof(T) == avpicture_get_size(r.format, r.width, r.height)) +bufsize_check{T<:EightBitTypes}(r::VideoReader{TRANSCODE}, buf::VidArray{T}) = bufsize_check(r.transcodeContext, buf) +bufsize_check{T<:EightBitTypes}(t::VideoTranscodeContext, buf::VidArray{T}) = (length(buf)*sizeof(T) == avpicture_get_size(t.target_pix_fmt, t.width, t.height)) have_decoded_frame(r) = r.aFrameFinished[1] > 0 # TODO: make sure the last frame was made available have_frame(r::StreamContext) = !isempty(r.frame_queue) || have_decoded_frame(r) @@ -667,39 +662,18 @@ if have_avdevice() end end -try - if isa(Main.Images, Module) - # Define read and retrieve for Images - global retrieve, retrieve!, read!, read - for r in [:read, :retrieve] - r! = Symbol("$(r)!") - - @eval begin - # read!, retrieve! - $r!(c::VideoReader, img::Main.Images.Image) = ($r!(c, Main.Images.data(img)); img) - - # read, retrieve - function $r(c::VideoReader, ::Type{Main.Images.Image}, colorspace="RGB", colordim=1, spatialorder=["x","y"]) - img = Main.Images.colorim($r(c::VideoReader)) - end - end - end - end -end - try if isa(Main.ImageView, Module) # Define read and retrieve for Images global playvideo, viewcam, play function play(f, flip=false) - img = read(f, Main.Images.Image) - canvas, _ = Main.ImageView.view(img, flipx=flip, interactive=false) - buf = Main.Images.data(img) + buf = read(f) + canvas, _ = Main.ImageView.imshow(buf, flipx=flip, interactive=false) while !eof(f) read!(f, buf) - Main.ImageView.view(canvas, img, flipx=flip, interactive=false) + Main.ImageView.imshow(canvas, buf, flipx=flip, interactive=false) sleep(1/f.framerate) end end diff --git a/test/avio.jl b/test/avio.jl index 514916d8..0ec3a2fc 100644 --- a/test/avio.jl +++ b/test/avio.jl @@ -1,8 +1,6 @@ using Base.Test -using Compat -using FixedPointNumbers +using ColorTypes, FileIO, ImageCore -import Images: Image import VideoIO testdir = dirname(@__FILE__) @@ -15,18 +13,8 @@ swapext(f, new_ext) = "$(splitext(f)[1])$new_ext" println(STDERR, "Testing file reading...") -if !isdefined(Main, :UFixed8) - UFixed8 = Ufixed8 -end - function notblank(img) - all(Images.green(img) .== 0x00uf8) || all(Images.blue(img) .== 0x00uf8) || all(Images.red(img) .== 0x00uf8) || maximum(reinterpret(UFixed8, img)) < 0xcfuf8 -end - -if isdefined(Images, :load) - imload = Images.load -else - imload = Images.imread + all(c->green(c) == 0, img) || all(c->blue(c) == 0, img) || all(c->red(c) == 0, img) || maximum(rawview(channelview(img))) < 0xcf end for name in VideoIO.TestVideos.names() @@ -34,12 +22,16 @@ for name in VideoIO.TestVideos.names() println(STDERR, " Testing $name...") first_frame_file = joinpath(testdir, swapext(name, ".png")) - first_frame = imload(first_frame_file) # comment line when creating png files + first_frame = load(first_frame_file) # comment line when creating png files f = VideoIO.testvideo(name) v = VideoIO.openvideo(f) - img = read(v, Image) + if size(first_frame, 1) > v.height + first_frame = first_frame[1+size(first_frame,1)-v.height:end,:] + end + + img = read(v) # Find the first non-trivial image while notblank(img) @@ -76,12 +68,16 @@ for name in VideoIO.TestVideos.names() println(STDERR, " Testing $name...") first_frame_file = joinpath(testdir, swapext(name, ".png")) - first_frame = imload(first_frame_file) # comment line when creating png files + first_frame = load(first_frame_file) # comment line when creating png files filename = joinpath(videodir, name) v = VideoIO.openvideo(open(filename)) - img = read(v, Image) + if size(first_frame, 1) > v.height + first_frame = first_frame[1+size(first_frame,1)-v.height:end,:] + end + + img = read(v) # Find the first non-trivial image while notblank(img) From 079fafce7089ee5c889e026d37759c7ee16c4a0c Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 1 Feb 2017 18:05:12 -0600 Subject: [PATCH 4/7] gitignore videos/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4ce8e83c..79b267c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ deps/* !deps/build.jl .DS_Store +videos/* \ No newline at end of file From 576122d5db0b999c83d9145f521955d36057bff1 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 1 Feb 2017 18:10:48 -0600 Subject: [PATCH 5/7] Travis-test on julia 0.5 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 97e2875b..2edf6418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ os: - linux # - osx julia: - - 0.4 + - 0.5 - nightly notifications: email: false From 55217c51639857df56a6568bbeb0a667f6193787 Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Sat, 18 Feb 2017 21:50:21 -0800 Subject: [PATCH 6/7] Don't check bounds on travis * Needs to be examined further, but it was responsible for a timeout on Julia v0.5 --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2edf6418..2dcf94ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ julia: notifications: email: false # uncomment the following lines to override the default test script -#script: -# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi -# - julia -e 'Pkg.clone(pwd()); Pkg.build("VideoIO2"); Pkg.test("VideoIO2"; coverage=true)' +script: + - julia -e 'Pkg.clone(pwd())' + - julia -e 'Pkg.build("VideoIO")' + - if [ -f test/runtests.jl ]; then julia -e 'Pkg.test("VideoIO", coverage=true)'; fi From 1531d08c5fb2ca80781783fc4db6a065070f581b Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 21 Feb 2017 14:09:36 -0600 Subject: [PATCH 7/7] Prevent inlining in notblank and turn off coverage For reasons I don't understand, turning on coverage causes the tests to take much longer, specifically in notblank. Since we're not doing anything with the coverage data anyway, let's just turn it off. --- .travis.yml | 3 ++- test/avio.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2dcf94ee..ffa4a328 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,4 +26,5 @@ notifications: script: - julia -e 'Pkg.clone(pwd())' - julia -e 'Pkg.build("VideoIO")' - - if [ -f test/runtests.jl ]; then julia -e 'Pkg.test("VideoIO", coverage=true)'; fi + # coverage=true causes tests to hang, see pull request #92 + - if [ -f test/runtests.jl ]; then julia -e 'Pkg.test("VideoIO", coverage=false)'; fi diff --git a/test/avio.jl b/test/avio.jl index 0ec3a2fc..6da8fcc8 100644 --- a/test/avio.jl +++ b/test/avio.jl @@ -13,7 +13,7 @@ swapext(f, new_ext) = "$(splitext(f)[1])$new_ext" println(STDERR, "Testing file reading...") -function notblank(img) +@noinline function notblank(img) all(c->green(c) == 0, img) || all(c->blue(c) == 0, img) || all(c->red(c) == 0, img) || maximum(rawview(channelview(img))) < 0xcf end