rqtrotate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +202 -0
- data/README.rdoc +48 -0
- data/Rakefile +2 -0
- data/bin/qtrotate_get +32 -0
- data/bin/qtrotate_set +32 -0
- data/lib/rqtrotate/extensions.rb +61 -0
- data/lib/rqtrotate/movie.rb +47 -0
- data/lib/rqtrotate/rqtrotate.rb +170 -0
- data/lib/rqtrotate/version.rb +17 -0
- data/lib/rqtrotate.rb +20 -0
- data/rqtrotate.gemspec +23 -0
- data/test.rb +13 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= rqtrotate
|
2
|
+
|
3
|
+
Pure ruby library to detect and affect rotation of ISO Base Media Format files
|
4
|
+
such as Apple QuickTime and 3gp.
|
5
|
+
|
6
|
+
== Credits
|
7
|
+
|
8
|
+
The logical core of this library is a port of Daniel G. Taylor's qtrotate python
|
9
|
+
library(https://github.com/danielgtaylor/qtrotate). Many, MANY thanks to him!
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
=== Ruby
|
14
|
+
require 'rubygems'
|
15
|
+
require 'rqtrotate'
|
16
|
+
|
17
|
+
include RQTRotate
|
18
|
+
|
19
|
+
# block style
|
20
|
+
Movie.open(:file_name => ARGV[0]) do |movie|
|
21
|
+
degrees = movie.rotation
|
22
|
+
puts "rotation is #{degrees}"
|
23
|
+
|
24
|
+
movie.rotation = degrees + 90
|
25
|
+
end
|
26
|
+
|
27
|
+
# stream style
|
28
|
+
File.open(ARGV[0], File::RDWR) do |f|
|
29
|
+
movie = Movie.new(f)
|
30
|
+
|
31
|
+
degrees = movie.rotation
|
32
|
+
puts "rotation is #{degrees}"
|
33
|
+
|
34
|
+
f.seek(0, IO::SEEK_SET)
|
35
|
+
movie.rotation = degrees + 90
|
36
|
+
end
|
37
|
+
|
38
|
+
=== Command Line
|
39
|
+
# see if a file is rotated
|
40
|
+
$ qtrotate_get ./test.mov
|
41
|
+
90
|
42
|
+
|
43
|
+
# rotate to 0 degrees
|
44
|
+
$ qtrotate_set ./test.mov 0
|
45
|
+
|
46
|
+
== Copyright
|
47
|
+
|
48
|
+
Copyright 2011 The Skunkworx.
|
data/Rakefile
ADDED
data/bin/qtrotate_get
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2011 The Skunkworx.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'rqtrotate'
|
19
|
+
|
20
|
+
include RQTRotate
|
21
|
+
|
22
|
+
if ARGV.length == 0
|
23
|
+
puts "Usage: qtrotate_get [path]"
|
24
|
+
else
|
25
|
+
begin
|
26
|
+
Movie.open(ARGV[0]) do |movie|
|
27
|
+
puts movie.rotation
|
28
|
+
end
|
29
|
+
rescue
|
30
|
+
puts "Unable to process #{ARGV[0]}"
|
31
|
+
end
|
32
|
+
end
|
data/bin/qtrotate_set
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2011 The Skunkworx.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'rqtrotate'
|
19
|
+
|
20
|
+
include RQTRotate
|
21
|
+
|
22
|
+
if ARGV.length < 2
|
23
|
+
puts "Usage: qtrotate_set [path] [degrees]"
|
24
|
+
else
|
25
|
+
begin
|
26
|
+
Movie.open(ARGV[0]) do |movie|
|
27
|
+
movie.rotation = ARGV[1].to_i
|
28
|
+
end
|
29
|
+
rescue
|
30
|
+
puts "Unable to process #{ARGV[0]}"
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright 2011 The Skunkworx.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# ruby's unpack can't extract signed big-endian longs
|
16
|
+
# (although I'm going to submit a patch to ruby-core to do so).
|
17
|
+
# this method compensates for that.
|
18
|
+
class String
|
19
|
+
def signed_bigendian_unpack()
|
20
|
+
arr = self.unpack("C*")
|
21
|
+
result = []
|
22
|
+
|
23
|
+
# the data is big-endian (netowrk order). if we're on a
|
24
|
+
# little endian platform we'll have to reverse the bytes
|
25
|
+
if [1, 0].pack("N*") == [1, 0].pack("L*")
|
26
|
+
result = arr
|
27
|
+
else
|
28
|
+
arr.each_slice(4) do |slice|
|
29
|
+
result += slice.reverse
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
result.pack('c*').unpack("l*")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# ruby's pack can't build signed big-endian longs
|
38
|
+
# (although I'm going to submit a patch to ruby-core to do so).
|
39
|
+
# this method compensates for that.
|
40
|
+
class Array
|
41
|
+
def signed_bigendian_pack()
|
42
|
+
if [1, 0].pack("N*") == [1, 0].pack("L*")
|
43
|
+
pack('c*')
|
44
|
+
else
|
45
|
+
result = ''
|
46
|
+
|
47
|
+
each do |i|
|
48
|
+
br = ''
|
49
|
+
|
50
|
+
4.times do
|
51
|
+
br << (i & 0xFF)
|
52
|
+
i >>= 8
|
53
|
+
end
|
54
|
+
|
55
|
+
result << br.reverse!
|
56
|
+
end
|
57
|
+
|
58
|
+
result
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
# Copyright 2011 The Skunkworx.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module RQTRotate
|
17
|
+
class Movie
|
18
|
+
attr_accessor :stream
|
19
|
+
|
20
|
+
def rotation=(value)
|
21
|
+
set_rotation @stream, value
|
22
|
+
reset_stream
|
23
|
+
end
|
24
|
+
|
25
|
+
def rotation
|
26
|
+
rotation = get_rotation @stream
|
27
|
+
reset_stream
|
28
|
+
rotation
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.open(file_name, &block)
|
32
|
+
movie = Movie.new(File.open(file_name, File::RDWR), true)
|
33
|
+
block.call movie
|
34
|
+
movie.stream.close
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(stream, owns_stream = false)
|
38
|
+
@stream = stream
|
39
|
+
@owns_stream = owns_stream
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def reset_stream
|
44
|
+
@stream.seek(0, IO::SEEK_SET) if @owns_stream
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# Copyright 2011 The Skunkworx.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module RQTRotate
|
16
|
+
# Read a single atom and return an array of [size, type].
|
17
|
+
def read_atom(stream)
|
18
|
+
stream.read(8).unpack("NA4")
|
19
|
+
end
|
20
|
+
|
21
|
+
# return a list of top-level atoms and their absolute
|
22
|
+
# positions
|
23
|
+
def get_index(stream)
|
24
|
+
index = []
|
25
|
+
|
26
|
+
while not stream.eof?
|
27
|
+
atom_size, atom_type = read_atom(stream)
|
28
|
+
index << [atom_type, stream.pos - 8, atom_size]
|
29
|
+
|
30
|
+
if atom_size < 8
|
31
|
+
break
|
32
|
+
else
|
33
|
+
stream.seek(atom_size - 8 , IO::SEEK_CUR)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
top_level_atoms = index.collect{|atom| atom[0]}
|
38
|
+
|
39
|
+
['ftyp', 'moov', 'mdat'].each do |atom_type|
|
40
|
+
if not top_level_atoms.include?(atom_type)
|
41
|
+
print "#{atom_type} atom not found, is this a valid MOV/MP4 file?"
|
42
|
+
exit(1)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
index
|
47
|
+
end
|
48
|
+
|
49
|
+
# read through the stream and yield each atom to the
|
50
|
+
# specified block
|
51
|
+
def find_atoms(size, stream, &block)
|
52
|
+
stop = stream.pos + size
|
53
|
+
|
54
|
+
while stream.pos < stop
|
55
|
+
atom_size, atom_type = read_atom(stream)
|
56
|
+
|
57
|
+
exit(1) if atom_size == 0
|
58
|
+
|
59
|
+
# 'trak's contiain child atoms
|
60
|
+
if atom_type == 'trak'
|
61
|
+
find_atoms(atom_size - 8, stream) do |sub_atom_type|
|
62
|
+
block.call sub_atom_type
|
63
|
+
end
|
64
|
+
elsif ['mvhd', 'tkhd'].include?(atom_type)
|
65
|
+
block.call atom_type
|
66
|
+
else
|
67
|
+
stream.seek(atom_size - 8, IO::SEEK_CUR)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# determine if an existing stream is rotated
|
73
|
+
def get_rotation(stream)
|
74
|
+
degrees = []
|
75
|
+
|
76
|
+
process_stream(stream) do |atom_type, matrix|
|
77
|
+
9.times do |i|
|
78
|
+
if (i + 1) % 3 == 0
|
79
|
+
matrix[i] = matrix[i].to_f / (1 << 30)
|
80
|
+
else
|
81
|
+
matrix[i] = matrix[i].to_f / (1 << 16)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if ['mvhd', 'tkhd'].include?(atom_type)
|
86
|
+
# convert radians to degrees
|
87
|
+
deg = -(Math::asin(matrix[3]) * (180.0 / Math::PI)) % 360
|
88
|
+
deg = (Math::acos(matrix[0]) * (180.0 / Math::PI)) if deg == 0
|
89
|
+
degrees << deg if deg != 0
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
if degrees.count == 0
|
94
|
+
0
|
95
|
+
elsif degrees.uniq.count == 1
|
96
|
+
degrees.pop
|
97
|
+
else
|
98
|
+
-1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# take an existing stream and rotate it
|
103
|
+
def set_rotation(stream, rotation)
|
104
|
+
process_stream(stream) do |atom_type, matrix|
|
105
|
+
if atom_type == 'tkhd'
|
106
|
+
# degrees to radians
|
107
|
+
rad = rotation * Math::PI / 180.0
|
108
|
+
# rotate
|
109
|
+
cos_deg = ((1 << 16) * Math::cos(rad)).to_i
|
110
|
+
sin_deg = ((1 << 16) * Math::sin(rad)).to_i
|
111
|
+
|
112
|
+
# pending patch acceptance to pack.c
|
113
|
+
# value = [cos_deg, sin_deg, 0, -sin_deg, cos_deg, 0, 0, 0, (1 << 30)].pack("O9")
|
114
|
+
# build data to write back into stream
|
115
|
+
value = [cos_deg, sin_deg, 0, -sin_deg, cos_deg, 0, 0, 0, (1 << 30)].signed_bigendian_pack()
|
116
|
+
|
117
|
+
stream.seek(-36, IO::SEEK_CUR)
|
118
|
+
stream.write(value)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# core of the whole thing. find all relevant atoms
|
124
|
+
# and yield to consumers
|
125
|
+
def process_stream(stream, &block)
|
126
|
+
index = get_index(stream)
|
127
|
+
moov_size = -1
|
128
|
+
|
129
|
+
index.each do |atom, pos, size|
|
130
|
+
if atom == 'moov'
|
131
|
+
moov_size = size
|
132
|
+
stream.seek(pos + 8)
|
133
|
+
break
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
find_atoms(moov_size - 8, stream) do |atom_type|
|
138
|
+
vf = stream.read(4)
|
139
|
+
version = vf.unpack("C4")[0]
|
140
|
+
flags = vf.unpack("N")[0] & 0x00ffffff
|
141
|
+
|
142
|
+
if version == 1
|
143
|
+
if atom_type == 'mvhd'
|
144
|
+
stream.read(28)
|
145
|
+
elsif atom_type == 'tkhd'
|
146
|
+
stream.read(32)
|
147
|
+
end
|
148
|
+
elsif version == 0
|
149
|
+
if atom_type == 'mvhd'
|
150
|
+
stream.read(16)
|
151
|
+
elsif atom_type == 'tkhd'
|
152
|
+
stream.read(20)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
stream.read(16)
|
157
|
+
raw = stream.read(36)
|
158
|
+
# matrix = raw.unpack('O*') # pending patch acceptance to pack.c
|
159
|
+
matrix = raw.signed_bigendian_unpack
|
160
|
+
|
161
|
+
block.call atom_type, matrix
|
162
|
+
|
163
|
+
if atom_type == 'mvhd'
|
164
|
+
stream.read(28)
|
165
|
+
elsif atom_type == 'tkhd'
|
166
|
+
stream.read(8)
|
167
|
+
end
|
168
|
+
end # find_atoms
|
169
|
+
end # process_stream
|
170
|
+
end # module
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright 2011 The Skunkworx.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Rqtrotate
|
16
|
+
VERSION = "0.1.0"
|
17
|
+
end
|
data/lib/rqtrotate.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Copyright 2011 The Skunkworx.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
Dir[File.join(File.dirname(__FILE__), 'rqtrotate', '*.rb')].each do |file|
|
16
|
+
require file
|
17
|
+
end
|
18
|
+
|
19
|
+
module RQTRotate
|
20
|
+
end
|
data/rqtrotate.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
|
4
|
+
$:.push File.expand_path("../lib", __FILE__)
|
5
|
+
require "rqtrotate/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "rqtrotate"
|
9
|
+
s.version = Rqtrotate::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = ["Chris Umbel"]
|
12
|
+
s.email = ["chrisu@dvdempire.com"]
|
13
|
+
s.homepage = "https://github.com/TheSkunkworx/rqtrotate"
|
14
|
+
s.summary = %q{Pure ruby library toe detect and affect rotation of QuickTime movies}
|
15
|
+
s.description = %q{Pure ruby library toe detect and affect rotation of QuickTime movies}
|
16
|
+
|
17
|
+
s.rubyforge_project = "rqtrotate"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
data/test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rqtrotate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Umbel
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-14 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Pure ruby library toe detect and affect rotation of QuickTime movies
|
23
|
+
email:
|
24
|
+
- chrisu@dvdempire.com
|
25
|
+
executables:
|
26
|
+
- qtrotate_get
|
27
|
+
- qtrotate_set
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE.txt
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- bin/qtrotate_get
|
39
|
+
- bin/qtrotate_set
|
40
|
+
- lib/rqtrotate.rb
|
41
|
+
- lib/rqtrotate/extensions.rb
|
42
|
+
- lib/rqtrotate/movie.rb
|
43
|
+
- lib/rqtrotate/rqtrotate.rb
|
44
|
+
- lib/rqtrotate/version.rb
|
45
|
+
- rqtrotate.gemspec
|
46
|
+
- test.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: https://github.com/TheSkunkworx/rqtrotate
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project: rqtrotate
|
77
|
+
rubygems_version: 1.3.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Pure ruby library toe detect and affect rotation of QuickTime movies
|
81
|
+
test_files: []
|
82
|
+
|