-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbinToMP4.rb
executable file
·113 lines (113 loc) · 4.32 KB
/
binToMP4.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
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
#!/usr/bin/ruby
###############################################################################
# getopts
###############################################################################
def getopts (argv)
help() if argv.size != 2
for i in (0..argv.size) do
case argv[i]
when "-h" : help()
when "-dir" : $sourcePattern = argv[i+1]
end
end
end
###############################################################################
# help
###############################################################################
def help ()
puts "======================================================================"
puts "== binToMP options : =="
puts "== -h : help =="
puts "== -dir : pattern directory path =="
puts "======================================================================"
exit
end
###############################################################################
# getListFile
###############################################################################
def getListFile (subDir)
pwd = Dir.pwd
Dir.chdir("#{$sourcePattern}/#{subDir}")
list = Dir.glob("*.bin")
Dir.chdir(pwd)
return list
end
###############################################################################
# createSubDir
###############################################################################
def createSubDir (subDir)
pwd = Dir.pwd
Dir.chdir($sourcePattern)
if not File.exists?("#{$sourcePattern}/MP4") then
Dir.mkdir("#{$sourcePattern}/MP4")
end
if not File.exists?("#{$sourcePattern}/MP4/#{subDir}") then
Dir.mkdir("#{$sourcePattern}/MP4/#{subDir}")
end
Dir.chdir(pwd)
end
###############################################################################
# getListFile
###############################################################################
def getMaxSizeFileName (listFile)
maxSize = 0
listFile.each do |binFile|
maxSize = binFile.size if binFile.size > maxSize
end
return maxSize
end
###############################################################################
# printLine
###############################################################################
def printLine(sizeOfLineAll)
for i in 0 ... sizeOfLineAll-1 do print "=" end; puts "="
end
###############################################################################
# printSubDir
###############################################################################
def printSubDir(subDir, nbFile, maxSize)
sizeOfLine = "= ".size + nbFile.to_s.size*2 + 1 + " =".size
sizeOfLineAll = sizeOfLine + 1 + maxSize + " ok =".size
printLine(sizeOfLineAll)
for i in 0 ... sizeOfLine do print "=" end
print "#{subDir.center(sizeOfLineAll-2*sizeOfLine)}"
for i in 0 ... sizeOfLine-1 do print "=" end; puts "="
printLine(sizeOfLineAll)
end
###############################################################################
# getFrameRate
###############################################################################
def getFrameRate(binFile)
from = /.*_.*_([0-9]*)_.*/
return binFile.scan(from)
end
###############################################################################
# main
###############################################################################
def main (subDir, binFile , idxFile, nbFile, maxSize)
createSubDir(subDir)
pwd = Dir.pwd
Dir.chdir($sourcePattern)
puts "= #{idxFile.to_s.rjust(nbFile.to_s.size)}/#{nbFile} = #{binFile.ljust(maxSize)} = #{getFrameRate(binFile)} fps"
mp4File = "#{File.basename(binFile, File.extname(binFile))}.mp4"
cmd ="MP4Box -new -fps #{getFrameRate(binFile)} -add #{$sourcePattern}/#{subDir}/#{binFile}:fmt=HEVC #{$sourcePattern}/MP4/#{subDir}/#{mp4File} 2> log"
system(cmd)
Dir.chdir(pwd)
end
###############################################################################
# main
###############################################################################
getopts(ARGV)
subDirTab = []
subDirTab << "i_main"
subDirTab << "ld_main"
subDirTab << "lp_main"
subDirTab << "ra_main"
subDirTab.each do |subDir|
listFile = getListFile(subDir)
maxSize = getMaxSizeFileName(listFile)
printSubDir(subDir, listFile.length, maxSize)
listFile.each_with_index do |binFile,idxFile|
main(subDir,binFile, idxFile+1, listFile.length, maxSize)
end
end