-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapptivate_transcode.rb
executable file
·88 lines (68 loc) · 2.13 KB
/
capptivate_transcode.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
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
#!/usr/bin/env ruby
#Convert existing videos to compressed format and gracefully replace existing video
require 'find'
require 'rubygems'
require 'streamio-ffmpeg'
require 'csv'
$conversionInfo = Array.new
$options = "-c:v libx264 -profile:v main -level 4.0 -preset veryfast -crf 22 -an"
baseDir = Dir.pwd
level1Dirs = Dir.entries(baseDir).select {|entry| File.directory? File.join(baseDir,entry) and !(entry =='.' || entry == '..') }
###Functions###
def transcode(movie)
theMovie = FFMPEG::Movie.new(movie)
out = theMovie.transcode("out.mov", $options) { |progress| puts progress }
info = [movie, theMovie.size, out.size]
$conversionInfo.push(info)
end
def swap_videos(movie)
#NB: File.rename will not work across partitions or devices.
#1. Move the original video out of the way to a predictable location.
File.rename(movie, "original.mov")
#2. Move the new video into position of the original video
File.rename("out.mov", movie)
end
###Main Loop###
if __FILE__==$0
level1Dirs.each do |i|
#Reset to Base Directory, init variables
Dir.chdir(baseDir)
movie_file = ""
movie_destination = ""
#Get path and search terms ready
path = File.join(baseDir, i)
hypeFolderName = i + ".hyperesources"
#Move to the post directory
Dir.chdir(path)
puts path
if File.directory?(hypeFolderName)
hypePath = File.join(path, hypeFolderName)
puts hypePath
Find.find(hypePath) do |f|
if f.match(/\.mov\Z/) && !f.match(/video.mov/) && !f.match(/original.mov/)
puts "Video path: #{f}"
movie_file = f
transcode(movie_file)
swap_videos(movie_file)
puts "pong"
end
end
else
Find.find(path) do |f|
if f.match(/\.mov\Z/) && !f.match(/video.mov/) && !f.match(/original.mov/)
puts "Video path: #{f}"
movie_file = f
transcode(movie_file)
swap_videos(movie_file)
puts "ping"
end
end
end
end
###Write stats to file###
CSV.open("stats.csv", "w") do |csv|
$conversionInfo.each do |row|
csv << row
end
end
end