-
Notifications
You must be signed in to change notification settings - Fork 52
/
testvideos.jl
230 lines (203 loc) · 7.18 KB
/
testvideos.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
"""
VideoIO.TestVideos
Tools for downloading test videos
* `VideoIO.TestVideos.available()` prints a list of all available test videos.
* `VideoIO.testvideo("annie_oakley")` returns an AVInput object for the
"annie_oakley" video. The video will be downloaded if it isn't available.
* `VideoIO.TestVideos.download_all()` downloads all test videos
* `VideoIO.TestVideos.remove_all()` removes all test videos
"""
module TestVideos
using VideoIO: VideoIO
import Base: show
import Downloads: download
using Scratch
export testvideo
videodir = ""
function __init__()
global videodir = @get_scratch!("videos")
end
mutable struct VideoFile{compression}
name::AbstractString
description::AbstractString
license::AbstractString
credit::AbstractString
source::AbstractString
download_url::AbstractString
numframes::Int
testframe::Int
summarysize::Int
fps::Union{Nothing,Rational}
VideoFile{compression}(
name::AbstractString,
description::AbstractString,
license::AbstractString,
credit::AbstractString,
source::AbstractString,
download_url::AbstractString,
numframes::Int,
testframe::Int,
summarysize::Int,
fps::Rational,
) where {compression} =
new(name, description, license, credit, source, download_url, numframes, testframe, summarysize, fps)
VideoFile{compression}(
name::AbstractString,
description::AbstractString,
license::AbstractString,
credit::AbstractString,
source::AbstractString,
download_url::AbstractString,
numframes::Int,
testframe::Int,
summarysize::Int,
) where {compression} =
new(name, description, license, credit, source, download_url, numframes, testframe, summarysize, nothing)
end
show(io::IO, v::VideoFile) = print(
io,
"""
VideoFile:
name: $(v.name) $(isfile(joinpath(videodir, v.name)) ? "(Downloaded)" : "")
description: $(v.description)
license: $(v.license)
credit: $(v.credit)
source: $(v.source)
download_url: $(v.download_url)
numframes: $(v.numframes)
summarysize: $(v.summarysize)
""",
)
VideoFile(name, description, license, credit, source, download_url, numframes, testframe, summarysize) =
VideoFile{:raw}(name, description, license, credit, source, download_url, numframes, testframe, summarysize)
VideoFile(name, description, license, credit, source, download_url, numframes, testframe, summarysize, fps) =
VideoFile{:raw}(name, description, license, credit, source, download_url, numframes, testframe, summarysize, fps)
# Standard test videos
const videofiles = Dict(
"ladybird.mp4" => VideoFile(
"ladybird.mp4",
"Ladybird opening wings (slow motion)",
"Creative Commons: By Attribution 3.0 Unported (http://creativecommons.org/licenses/by/3.0/deed)",
"CC-BY NatureClip (http://youtube.com/natureclip)",
"https://downloadnatureclip.blogspot.com/p/download-links.html",
"https://archive.org/download/LadybirdOpeningWingsCCBYNatureClip/Ladybird%20opening%20wings%20CC-BY%20NatureClip.mp4",
397,
13,
3216,
),
"annie_oakley.ogg" => VideoFile(
"annie_oakley.ogg",
"The \"Little Sure Shot\" of the \"Wild West,\" exhibition of rifle shooting at glass balls.",
"pubic_domain (US)",
"",
"https://commons.wikimedia.org/wiki/File:Annie_Oakley_shooting_glass_balls,_1894.ogg",
"https://upload.wikimedia.org/wikipedia/commons/8/87/Annie_Oakley_shooting_glass_balls%2C_1894.ogv",
726,
2,
167311096,
),
"crescent-moon.ogv" => VideoFile(
"crescent-moon.ogv",
"Moonset (time-lapse).",
"Creative Commons Attribution 2.0 Generic (http://creativecommons.org/licenses/by/2.0/deed)",
"Photo : Thomas Bresson",
"https://commons.wikimedia.org/wiki/File:2010-10-10-Lune.ogv",
"https://upload.wikimedia.org/wikipedia/commons/e/ef/2010-10-10-Lune.ogv",
1213,
1,
9744,
),
"black_hole.webm" => VideoFile(
"black_hole.webm",
"Artist’s impression of the black hole inside NGC 300 X-1 (ESO 1004c)",
"Creative Commons Attribution 3.0 Unported (http://creativecommons.org/licenses/by/3.0/deed)",
"Credit: ESO/L. Calçada",
"https://www.eso.org/public/videos/eso1004a/",
"https://upload.wikimedia.org/wikipedia/commons/1/13/Artist%E2%80%99s_impression_of_the_black_hole_inside_NGC_300_X-1_%28ESO_1004c%29.webm",
597,
1,
4816,
),
# # This has started HTTP 526 erroring
# "Big_Buck_Bunny_360_10s_1MB.mp4" => VideoFile(
# "Big_Buck_Bunny_360_10s_1MB.mp4",
# "Big Buck Bunny",
# "Creative Commons: By Attribution 3.0 Unported (http://creativecommons.org/licenses/by/3.0/deed)",
# "Credit: Blender Foundation | www.blender.org",
# "https://peach.blender.org/",
# "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4",
# 300,
# 2,
# 207376840,
# # Can be also 30000/1001
# 30 // 1,
# ),
)
"""
testvideo(name, ops...)
Returns an `AVInput` object for the given video name. The video will be downloaded if it isn't available.
"""
function testvideo(name, ops...)
videofile = joinpath(videodir, name)
if !isfile(videofile)
files = collect(keys(videofiles))
# Bool is needed here for Julia v0.3
ind = Bool[startswith(x, name) for x in files]
count = sum(ind)
if count == 1
name = files[ind][1]
videofile = joinpath(videodir, name)
!isfile(videofile) && download(videofiles[name])
!isfile(videofile) && throw(ErrorException("Error downloading test videofile \"$name\""))
elseif count == 0
throw(ErrorException("$name is not a known test videofile"))
else
throw(ErrorException("$name matches more than one test videofile"))
end
end
return VideoIO.open(videofile, ops...) # Returns an AVInput, which in turn must be opened with openvideo, openaudio, etc.
end
function write_info(v::VideoFile)
credit_file = joinpath(videodir, "$(v.name).txt")
Base.open(credit_file, "w") do f
return println(f, v)
end
end
function download(v::VideoFile)
write_info(v)
println(stderr, "Downloading $(v.name) to $videodir")
return download(v.download_url, joinpath(videodir, v.name))
end
"""
available()
Print a list of all available test videos.
"""
function available()
for v in values(videofiles)
println(v)
end
end
names() = collect(keys(videofiles))
"""
download_all()
Downloads all test videos.
"""
function download_all()
for (filename, v) in videofiles
videofile = joinpath(videodir, filename)
!isfile(videofile) && download(v)
infofile = joinpath(videodir, "$(v.name).txt")
!isfile(infofile) && write_info(v)
end
end
"""
remove_all()
Remove all test videos.
"""
function remove_all()
for filename in keys(videofiles)
videofile = joinpath(videodir, filename)
isfile(videofile) && rm(videofile)
end
end
end