-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathinfo.jl
73 lines (62 loc) · 2.33 KB
/
info.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
# For reading information & metadata about the file
function _get_fc(file::String) # convenience function for `get_duration` and `get_start_time`
v = open(file)
return v.format_context, v
end
get_duration(fc::AVFormatContextPtr) = fc.duration / AV_TIME_BASE
"""
get_duration(file::String) -> Float64
Return the duration of the video `file` in seconds (float).
"""
function get_duration(file::String)
fc, v = _get_fc(file)
duration = get_duration(fc)
close(v)
return duration
end
get_start_time(fc::AVFormatContextPtr) = Dates.unix2datetime(fc.start_time_realtime)
"""
get_start_time(file::String) -> DateTime
Return the starting date & time of the video `file`. Note that if the starting date & time are missing, this function will return the Unix epoch (00:00 1st January 1970).
"""
function get_start_time(file::String)
fc, v = _get_fc(file)
starttime = get_start_time(fc)
close(v)
return starttime
end
get_time_duration(fc::AVFormatContextPtr) = (get_start_time(fc), get_duration(fc))
"""
get_time_duration(file::String) -> (DateTime, Microsecond)
Return the starting date & time as well as the duration of the video `file`. Note that if the starting date & time are missing, this function will return the Unix epoch (00:00 1st January 1970).
"""
function get_time_duration(file::String)
fc, v = _get_fc(file)
starttime, duration = get_time_duration(fc)
close(v)
return starttime, duration
end
"""
get_number_frames(file [, streamno])
Query the the container `file` for the number of frames in video stream
`streamno` if applicable, instead returning `nothing` if the container does not
report the number of frames. Will not decode the video to count the number of
frames in a video.
"""
function get_number_frames(file::AbstractString, streamno::Integer = 0)
streamno >= 0 || throw(ArgumentError("streamno must be non-negative"))
frame_strs = FFMPEG.exe(
`-v error -select_streams v:$(streamno) -show_entries
stream=nb_frames -of
default=nokey=1:noprint_wrappers=1 $file`,
command = FFMPEG.ffprobe,
collect = true,
)
frame_str = frame_strs[1]
if occursin("No such file or directory", frame_str)
error("Could not find file $file")
elseif occursin("N/A", frame_str)
return nothing
end
return parse(Int, frame_str)
end