Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

finally this is ruby 1.9.2 compatible

  • Loading branch information...
commit d0b1cb994cba569e1aba3162f2d1ba480aa146ac 1 parent a2629c1
Sascha Wessel authored January 23, 2011
28  hs_encoder.rb
@@ -22,6 +22,7 @@
22 22
 require 'fileutils'
23 23
 require 'open3'
24 24
 
  25
+
25 26
 class HSEncoder
26 27
   
27 28
   class CommandExecutionException < ::StandardError; end
@@ -57,18 +58,18 @@ def stop_encoding
57 58
   private 
58 59
 
59 60
   def process_master_encoding(encoding_pipes)
60  
-    command = "#{@config['source_command']} #{@config['input_location']}"
  61
+    command = @config['source_command'] % [@config['input_location']]
61 62
 
62 63
     @log.debug("Executing: #{command}")
63 64
 
64 65
     stderr_thread = nil
65  
-
66  
-    Open3.popen3(command) do |stdin, stdout, stderr|
  66
+    exit_code = -1
  67
+    Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
67 68
       @stop_stdin = stdin
68 69
       stderr_thread = Thread.new do
69 70
         stderr.each("\r") do |line|
70 71
           if line =~ /ffmpeg/i 
71  
-            @log.debug("Master encoder: #{line}")
  72
+            @log.info("Master encoder: #{line}")
72 73
           end
73 74
 
74 75
           if line =~ /error/i
@@ -83,23 +84,25 @@ def process_master_encoding(encoding_pipes)
83 84
           out.print output
84 85
         end
85 86
       end
  87
+      exit_code = wait_thr.value.exitstatus
86 88
     end
87 89
 
88 90
     stderr_thread.join
89 91
 
90  
-    @log.debug("Return code from master encoding: #{$?}")
91  
-
  92
+    @log.info("Return code from master encoding: #{exit_code}")
  93
+    
92 94
     encoding_pipes.each do |out|
93 95
       out.close
94 96
     end
95 97
 
96  
-    raise CommandExecutionException if $?.nil?
  98
+    raise CommandExecutionException if exit_code != 0
97 99
   end
98 100
 
99 101
   def execute_ffmpeg_and_segmenter(command, encoding_profile, encoding_pipes)
100 102
     @log.debug("Executing: #{command}")
101 103
 
102  
-    Open3.popen3(command) do |stdin, stdout, stderr|
  104
+    exit_code = -1
  105
+    Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
103 106
       if encoding_pipes != nil
104 107
         encoding_pipes << stdin
105 108
       else
@@ -120,11 +123,12 @@ def execute_ffmpeg_and_segmenter(command, encoding_profile, encoding_pipes)
120 123
           @log.error("Encoder #{encoding_profile}: #{line}")
121 124
         end
122 125
       end
  126
+      exit_code = wait_thr.value.exitstatus
123 127
     end
124 128
 
125  
-    @log.debug("Return code from #{encoding_profile}: #{$?}")
126  
-
127  
-    raise CommandExecutionException if $?.nil?
  129
+    @log.debug("Return code from #{encoding_profile}: #{exit_code}")
  130
+    
  131
+    raise CommandExecutionException if exit_code != 0
128 132
   end
129 133
 
130 134
   def process_encoding(encoding_profile, input_location, encoding_pipes)
@@ -163,7 +167,7 @@ def run_multirate_encoding( encoding_threads )
163 167
       begin
164 168
         process_master_encoding(encoding_pipes)
165 169
       rescue
166  
-        @log.error("Master encoding error: #{$!}")
  170
+        @log.error("Master encoding error: #{$!}: #{$@}")
167 171
 
168 172
         encoding_pipes.each do |out|
169 173
           begin
2  hs_transfer.rb
@@ -58,7 +58,7 @@ def start_transfer_thread
58 58
           begin
59 59
             create_index_and_run_transfer(value)
60 60
           rescue
61  
-            @log.error("Error running transfer: #{$!}")
  61
+            @log.error("Error running transfer: #{$!}: #{$@}")
62 62
           end
63 63
         end
64 64
 

0 notes on commit d0b1cb9

Please sign in to comment.
Something went wrong with that request. Please try again.