-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_properties.rb
executable file
·59 lines (53 loc) · 1.55 KB
/
video_properties.rb
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
#!/usr/bin/env ruby1.9
# coding: utf-8
# vim: shiftwidth=2:expandtab
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
require 'shellwords'
require File.dirname(__FILE__) + "/utils.rb"
class VideoProperties
attr_reader :fps, :w, :h, :fps_s, :ok
def initialize video
if File.exists? video
io = IO.popen %(mplayer -slave -quiet -vo null -ao null #{video.shellescape}), "r+", :encoding => "BINARY"
io.puts "get_property fps"
io.puts "get_video_resolution"
io.puts "quit"
while io.gets
if $_ =~ /^ANS_fps=\d+\.\d+/
@fps_s = $_[/\d+\.\d+/]
elsif $_ =~ /^ANS_VIDEO_RESOLUTION='\d+ x \d+'/
@w, @h = $_.scan(/(\d+) x (\d+)/)[0]
end
end
else
$stderr.puts "FILE NOT FOUND: #{video}"
exit 1
end
if @fps_s
@fps = @fps_s.to_f
@ok = true
else
$stderr.puts "WARNING: Framerate not found, set to 25fps for file #{video}"
@fps = 25.0
@ok = false
end
if @w and @h
@w = @w.to_f
@h = @h.to_f
else
$stderr.puts "WARNING: Resolution not found, set to 800x600 for file #{video}"
@w = 800
@h = 600
end
end
end
if $PROGRAM_NAME == __FILE__
properties = VideoProperties.new(ARGV[0])
puts properties.fps_s
exit 1 if not properties.ok
end