staugaard-transcoding_machine 0.1.5 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 5
2
+ :patch: 2
3
3
  :major: 0
4
- :minor: 1
4
+ :minor: 2
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../lib/transcoding_machine/server/worker', File.dirname(__FILE__))
3
+
4
+ if ARGV.size >= 1
5
+ log = File.new(ARGV[0], "a")
6
+ end
7
+ log = log || STDERR
8
+
9
+ begin
10
+ TranscodingMachine::Server::Ec2Environment.logger = log
11
+ TranscodingMachine::Server::Ec2Environment.load
12
+
13
+ if TranscodingMachine::Server::Ec2Environment.updated_gem
14
+ `wget -O /tmp/transcoding_machine.gem #{TranscodingMachine::Server::Ec2Environment.updated_gem}`
15
+ `gem install /tmp/transcoding_machine.gem`
16
+ end
17
+ rescue
18
+ log.puts "error #{$!}"
19
+ pp "#{$@}"
20
+ exit 1
21
+ end
@@ -9,6 +9,7 @@ module TranscodingMachine
9
9
  options[:key] = key
10
10
  options[:media_players] = media_player_ids
11
11
  options[:result_queue] = result_queue_name
12
+ options[:action] = :analyze
12
13
  RightAws::SqsGen2.new.queue(queue_name).push(options.to_yaml)
13
14
  end
14
15
  end
@@ -74,6 +74,10 @@ module TranscodingMachine
74
74
  def self.status_queue_name
75
75
  data[:user_data][:status_queue_name]
76
76
  end
77
+
78
+ def self.updated_gem
79
+ data[:user_data][:updated_gem]
80
+ end
77
81
  end
78
82
  end
79
83
  end
@@ -17,10 +17,9 @@ module TranscodingMachine
17
17
  self.class.options[:storage]
18
18
  end
19
19
 
20
- def initialize(source_file_name, media_players, media_formats, event_handler = nil, storage_options = {})
20
+ def initialize(source_file_name, media_formats, event_handler = nil, storage_options = {})
21
21
  @source_file_name = source_file_name
22
22
  @event_handler = event_handler
23
- @media_players = media_players
24
23
  @media_formats = media_formats
25
24
  @storage_options = storage_options
26
25
  end
@@ -40,20 +39,9 @@ module TranscodingMachine
40
39
  def destination_file_path(media_format)
41
40
  File.expand_path(destination_file_name(media_format), work_directory)
42
41
  end
43
-
44
- def start
45
- prepare_working_directory
46
- get_source_file
47
- source_file_attributes, source_media_format, target_media_formats = analyze_source_file
48
-
49
- thumbnail_file_path = generate_thumbnail(source_file_attributes)
50
- storage.put_thumbnail_file(thumbnail_file_path, @source_file_name, @storage_options) if thumbnail_file_path
51
-
52
- target_media_formats.each do |media_format|
53
- destination_file_path = transcode(source_file_attributes, media_format)
54
- put_destination_file(destination_file_path, media_format)
55
- end
56
- clear
42
+
43
+ def has_source_file?
44
+ File.exist?(source_file_path)
57
45
  end
58
46
 
59
47
  def prepare_working_directory
@@ -64,22 +52,30 @@ module TranscodingMachine
64
52
  end
65
53
 
66
54
  def get_source_file
67
- @event_handler.getting_source_file if @event_handler
68
- storage.get_file(@source_file_name, source_file_path, @storage_options)
69
- @event_handler.got_source_file if @event_handler
55
+ unless has_source_file?
56
+ prepare_working_directory
57
+ @event_handler.getting_source_file if @event_handler
58
+ storage.get_file(@source_file_name, source_file_path, @storage_options)
59
+ @event_handler.got_source_file if @event_handler
60
+ end
70
61
  end
71
62
 
72
- def analyze_source_file
63
+ def analyze_source_file(media_players)
64
+ get_source_file
73
65
  @event_handler.analyzing_source_file if @event_handler
74
66
 
75
67
  source_file_attributes = MediaFileAttributes.new(source_file_path)
76
68
 
77
69
  source_media_format = @media_formats.find {|mf| mf.matches(source_file_attributes)}
78
70
 
79
- target_media_formats = @media_players.map {|mp| mp.best_format_for(source_file_attributes)}.compact.uniq
71
+ target_media_formats = media_players.map {|mp| mp.best_format_for(source_file_attributes)}.compact.uniq
80
72
  target_media_formats -= [source_media_format]
81
-
73
+
82
74
  @event_handler.analyzed_source_file(source_file_attributes, source_media_format, target_media_formats) if @event_handler
75
+
76
+ thumbnail_file_path = generate_thumbnail(source_file_attributes)
77
+ storage.put_thumbnail_file(thumbnail_file_path, @source_file_name, @storage_options) if thumbnail_file_path
78
+
83
79
  [source_file_attributes, source_media_format, target_media_formats]
84
80
  end
85
81
 
@@ -95,6 +91,8 @@ module TranscodingMachine
95
91
  end
96
92
 
97
93
  def transcode(source_file_attributes, media_format)
94
+ get_source_file
95
+ media_format = @media_formats[media_format] unless media_format.is_a?(MediaFormat)
98
96
  @event_handler.transcoding(media_format) if @event_handler
99
97
 
100
98
  dst_file_path = destination_file_path(media_format)
@@ -114,6 +112,7 @@ module TranscodingMachine
114
112
  end
115
113
 
116
114
  @event_handler.transcoded(media_format) if @event_handler
115
+ put_destination_file(dst_file_path, media_format)
117
116
  dst_file_path
118
117
  end
119
118
 
@@ -74,38 +74,66 @@ module TranscodingMachine
74
74
 
75
75
  start_time = Time.now
76
76
 
77
- send_log_message "Transcoding: BLA BLA BLA"
78
-
79
77
  message_properties = YAML.load(msg.body)
80
78
  puts "consuming message #{message_properties.inspect}"
81
- selected_media_players = find_media_players(message_properties[:media_players])
82
- if selected_media_players.any?
83
- if bucket = @s3.bucket(message_properties[:bucket].to_s)
84
- key = bucket.key(message_properties[:key].to_s)
85
- if key.exists?
86
- transcoder = Transcoder.new(key.name,
87
- selected_media_players,
88
- @media_formats,
89
- TranscodingEventListener.new(message_properties),
90
- :bucket => bucket.name)
91
- transcoder.start
79
+
80
+ if bucket = @s3.bucket(message_properties[:bucket].to_s)
81
+ key = bucket.key(message_properties[:key].to_s)
82
+ if key.exists?
83
+
84
+ transcoder = Transcoder.new(key.name,
85
+ @media_formats,
86
+ TranscodingEventListener.new(message_properties),
87
+ :bucket => bucket.name)
88
+
89
+ case message_properties[:action]
90
+ when :transcode
91
+ handle_transcode(transcoder, message_properties)
92
92
  else
93
- send_log_message "Input file not found (bucket: #{message_properties[:bucket]} key: #{message_properties[:key]})"
93
+ handle_analyze(transcoder, message_properties)
94
94
  end
95
+
95
96
  else
96
- send_log_message "Input bucket not found (bucket: #{message_properties[:bucket]})"
97
+ send_log_message "Input file not found (bucket: #{message_properties[:bucket]} key: #{message_properties[:key]})"
97
98
  end
98
99
  else
99
- send_log_message "No media players found #{message_properties[:media_players].inspect}"
100
+ send_log_message "Input bucket not found (bucket: #{message_properties[:bucket]})"
100
101
  end
101
-
102
+
102
103
  end_time = Time.now
103
104
 
104
105
  if true #test if transcode was successful
105
106
  msg.delete
106
- send_log_message "Transcoded: BLA BLA BLA"
107
107
  end
108
108
  end
109
+
110
+ def handle_analyze(transcoder, message_properties)
111
+ send_log_message "Analyzing: #{message_properties[:bucket]}/#{message_properties[:key]}"
112
+ selected_media_players = find_media_players(message_properties[:media_players])
113
+ if selected_media_players.any?
114
+
115
+ source_file_attributes, source_media_format, target_media_formats = transcoder.analyze_source_file(selected_media_players)
116
+
117
+ message_properties.delete(:media_players)
118
+ message_properties[:action] = :transcode
119
+ message_properties[:file_attributes] = source_file_attributes
120
+
121
+ target_media_formats.each do |media_format|
122
+ message_properties[:media_format] = media_format
123
+ @work_queue.push(message_properties.to_yaml)
124
+ end
125
+
126
+ else
127
+ send_log_message "No media players found #{message_properties[:media_players].inspect}"
128
+ end
129
+ send_log_message "Analyzed: #{message_properties[:bucket]}/#{message_properties[:key]}"
130
+ end
131
+
132
+ def handle_transcode(transcoder, message_properties)
133
+ send_log_message "Transcoding: #{message_properties[:bucket]}/#{message_properties[:key]} to format #{message_properties[:media_format]}"
134
+ transcoder.transcode(message_properties[:file_attributes], message_properties[:media_format])
135
+ send_log_message "Transcoded: #{message_properties[:bucket]}/#{message_properties[:key]} to format #{message_properties[:media_format]}"
136
+ end
109
137
 
110
138
  def find_media_players(media_player_ids)
111
139
  @media_players.slice(*media_player_ids).values
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staugaard-transcoding_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-08 00:00:00 -07:00
12
+ date: 2009-04-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,16 +47,17 @@ email: mick@staugaard.com
47
47
  executables:
48
48
  - transcoding_machine
49
49
  - transcoding_machine_ec2_server
50
+ - update_transcoding_machine_ec2_server
50
51
  extensions: []
51
52
 
52
53
  extra_rdoc_files:
53
54
  - README
54
55
  - LICENSE
55
56
  files:
56
- - NOTES.txt
57
57
  - VERSION.yml
58
58
  - bin/transcoding_machine
59
59
  - bin/transcoding_machine_ec2_server
60
+ - bin/update_transcoding_machine_ec2_server
60
61
  - lib/transcoding_machine
61
62
  - lib/transcoding_machine/client
62
63
  - lib/transcoding_machine/client/job_queue.rb
@@ -75,7 +76,6 @@ files:
75
76
  - lib/transcoding_machine/server.rb
76
77
  - lib/transcoding_machine.rb
77
78
  - test/deserialze_test.rb
78
- - test/dummy_server_mananager.rb
79
79
  - test/fixtures
80
80
  - test/fixtures/serialized_models.json
81
81
  - test/media_format_criterium_test.rb