wco_models 3.1.0.227 → 3.1.0.229

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b54b1e2999903675e6c6ed4c9b3286c2516dbfdfa1b62eef590a13f0b74a4ac
4
- data.tar.gz: dc4c3c977cf6818c67eeb07503286d25909676ac079b97f23bc6be31580f5cf3
3
+ metadata.gz: 35f0a2494dffe699ad7a91e1b2f2a08732a52f7a8cee5807e0692743b72304cc
4
+ data.tar.gz: c189c18f602662123f112cca121258942c35708eaf2804cec37744d2ccc781e5
5
5
  SHA512:
6
- metadata.gz: 4f2950744dcd8b1e99ea11227d7844b307a3638a39ba78818a2507b9fb7e948be47fd8ed667b13e786144ab814f1ba660199bc179199a8a6216015e6adc7767b
7
- data.tar.gz: ec0aa3d7d7db9c052d9f5b495f0ab83ceec8d5499d8e1c797038f7618bede52029ef53439a23d5be3d1a288579b2798499ee363dcf230b174615ee49e013bdb1
6
+ metadata.gz: c4abf1dcd6c75dad28c97c6557afcfccce94e08b5374f20e187f0d6fe25fa2cb400bba3b0e37ee65793e3e2f659e4ef6231ccf77effaeeeeb87d0b690d4a0f85
7
+ data.tar.gz: 969bbd295573b4c14214d30f237418de3c20f75540f4a0eef4644f48779981a0f84934ae9f21788962406ce915b4b9d0bdea07355dc4004870d4f7eb17bf1d7b
@@ -32,110 +32,11 @@ class Wco::NewsvideosController < Wco::ApplicationController
32
32
  @newsvideo = Wco::Newsvideo.unscoped.find params[:id]
33
33
  authorize! :edit, @newsvideo
34
34
 
35
+ Rails.env.production? ?
36
+ Wco::NewsvideoIllustrationJob.perform_async(@newsvideo.id.to_s) :
37
+ Wco::NewsvideoIllustrationJob.perform_sync( @newsvideo.id.to_s)
35
38
 
36
- ## put together config
37
- # cmd = "cd #{Rails.root.join('tmp')} ; mkdir -p #{@newsvideo.id} ; cd #{@newsvideo.id} ; rm -f videolist.txt audiolist.txt ; "
38
- # @newsvideo.newspartials.each_with_index do |part, idx|
39
- # cmd = "#{cmd} echo \"file 'newspartial_#{idx}.mp4' \" >> videolist.txt ; "
40
- # cmd = "#{cmd} echo \"file 'newspartial_#{idx}.wav' \" >> audiolist.txt ; "
41
- # cmd = "#{cmd} ffmpeg -i newspartial_#{idx}.webm newspartial_#{idx}.mp4 ; "
42
- # end
43
- # puts! cmd, 'cmd'
44
- # out = `#{cmd}`
45
- # puts! out, 'out'
46
-
47
- ## get base files locally
48
- # cmd = "cd #{Rails.root.join('tmp', @newsvideo.id)} ; "
49
- # @newsvideo.newspartials.each_with_index do |part, idx|
50
- # cmd = "#{cmd} wget -O newspartial_#{idx}.webm #{part.video.video.url} ; "
51
- # cmd = "#{cmd} wget -O newspartial_#{idx}.wav #{part.audio.url} ; "
52
- # end
53
- # puts! cmd, 'cmd'
54
- # out = `#{cmd}`
55
- # puts! out, 'out'
56
-
57
- ## get overlays
58
- # cmd = "cd #{Rails.root.join('tmp', @newsvideo.id)} ; "
59
- # @newsvideo.newsoverlays.each_with_index do |overlay, idx|
60
- # cmd = "#{cmd} wget -O overlay_#{idx}.mp4 #{overlay.video.video.url} ; "
61
- # end
62
- # puts! cmd, 'cmd'
63
- # out = `#{cmd}`
64
- # puts! out, 'out'
65
-
66
- ## video concat
67
- # cmd = <<AOL
68
- # cd #{Rails.root.join('tmp', @newsvideo.id)} ;
69
- # rm -f video_concat.mp4 ;
70
- # ffmpeg -f concat -safe 0 -i videolist.txt -c copy video_concat.mp4 ;
71
- # AOL
72
- # puts! cmd, 'cmd'
73
- # out = `#{cmd}`
74
- # puts! out, 'out'
75
-
76
- ## audio concat
77
- # audio_filenames = (0...@newsvideo.newspartials.length).map { |i| "newspartial_#{i}.wav" }.join("|")
78
- # cmd = <<AOL
79
- # cd #{Rails.root.join('tmp', @newsvideo.id)} ;
80
- # rm -f audio_concat.wav ;
81
- # ffmpeg -f concat -safe 0 -i audiolist.txt -c copy audio_concat.wav ;
82
- # AOL
83
- # puts! cmd, 'cmd'
84
- # out = `#{cmd}`
85
- # puts! out, 'out'
86
-
87
- ## combine base
88
- # cmd = <<AOL
89
- # cd #{Rails.root.join('tmp', @newsvideo.id)} ;
90
- # rm -f output.mp4 ;
91
- # ffmpeg -i video_concat.mp4 -i audio_concat.wav -c:v copy -c:a aac combined_base.mp4 ;
92
- # AOL
93
- # puts! cmd, 'cmd'
94
- # out = `#{cmd}`
95
- # puts! out, 'out'
96
-
97
- ## combine overlays
98
- # nn = @newsvideo.newsoverlays.map { |ol| ol.start_at_ms }
99
- # puts! nn, 'nn'
100
- # ffmpeg_cmd = [ "ffmpeg -i combined_base.mp4 \\ " ]
101
- # nn.each_with_index do |ms, idx|
102
- # ffmpeg_cmd.push " -i overlay_#{idx}.mp4 \\ "
103
- # end
104
- # ffmpeg_cmd.push "-filter_complex \" \\ "
105
- # #
106
- # nn.each_with_index do |ms, idx|
107
- # ffmpeg_cmd.push " [#{idx+1}:v]setpts=PTS-STARTPTS+#{ms.to_f/1000}/TB[v#{idx+1}]; \\ "
108
- # end
109
- # #
110
- # curr_s = "0:v"
111
- # n = nil
112
- # nn.each_with_index do |ms, idx|
113
- # n = idx+1
114
- # ffmpeg_cmd.push " [#{curr_s}][v#{n}]overlay=0:0:eof_action=pass[tmp#{n}]; \\ "
115
- # curr_s = "tmp#{n}"
116
- # end
117
- # ffmpeg_cmd.push " \" -map \"[#{curr_s}]\" -map 0:a? -c:v libx264 -c:a copy combined_fin.mp4 "
118
- # ffmpeg_cmd = ffmpeg_cmd.join("\n")
119
- # puts "+++ ffmpeg_cmd:"
120
- # puts ffmpeg_cmd
121
-
122
- # combine overlays 2
123
- # cmd = <<AOL
124
- # cd #{Rails.root.join('tmp', @newsvideo.id)} ;
125
- # rm -f combined_fin.mp4 ;
126
- # #{ffmpeg_cmd} ;
127
- # AOL
128
- # puts! cmd, 'cmd'
129
- # out = `#{cmd}`
130
- # puts! out, 'out'
131
-
132
- ## upload the video.
133
- @video = Wco::Video.new name: @newsvideo.title
134
- video_path = Rails.root.join("tmp", @newsvideo.id, "combined_fin.mp4")
135
- @video.video = File.open(video_path)
136
- @video.save!
137
-
138
- render json: { status: :ok }
39
+ render json: { status: :ok, message: 'Scheduled the generation' }
139
40
  end
140
41
 
141
42
  def generate_illustration
@@ -0,0 +1,14 @@
1
+
2
+ require 'sidekiq'
3
+
4
+ class Wco::NewsvideoGenerateJob
5
+ include Sidekiq::Job
6
+ sidekiq_options queue: 'default'
7
+
8
+ def perform id
9
+ puts! id, 'Newsvideo generate job...'
10
+ @newsvideo = Wco::Newsvideo.find id
11
+ @newsvideo.generate
12
+ end
13
+
14
+ end
@@ -100,7 +100,8 @@ class Wco::Newspartial
100
100
  --wco_origin=#{WCO_ORIGIN} \
101
101
  --newspartial_id=#{self[:id]} ";
102
102
 
103
- puts! cmd, 'cmd'
103
+ puts "+++ cmd:"
104
+ puts cmd
104
105
  begin
105
106
  out = `#{cmd}`
106
107
  rescue err
@@ -50,4 +50,110 @@ class Wco::Newsvideo
50
50
  Wco::Newsoverlay.where( newsvideo_id: self.id )
51
51
  end
52
52
 
53
+ def generate
54
+ @newsvideo = self
55
+
56
+ ## put together config
57
+ cmd = "cd #{Rails.root.join('tmp')} ; mkdir -p #{@newsvideo.id} ; cd #{@newsvideo.id} ; rm -f videolist.txt audiolist.txt ; "
58
+ @newsvideo.newspartials.each_with_index do |part, idx|
59
+ cmd = "#{cmd} echo \"file 'newspartial_#{idx}.mp4' \" >> videolist.txt ; "
60
+ cmd = "#{cmd} echo \"file 'newspartial_#{idx}.wav' \" >> audiolist.txt ; "
61
+ cmd = "#{cmd} ffmpeg -i newspartial_#{idx}.webm newspartial_#{idx}.mp4 ; "
62
+ end
63
+ puts! cmd, 'cmd'
64
+ out = `#{cmd}`
65
+ puts! out, 'out'
66
+
67
+ ## get base files locally
68
+ cmd = "cd #{Rails.root.join('tmp', @newsvideo.id)} ; "
69
+ @newsvideo.newspartials.each_with_index do |part, idx|
70
+ cmd = "#{cmd} wget -O newspartial_#{idx}.webm #{part.video.video.url} ; "
71
+ cmd = "#{cmd} wget -O newspartial_#{idx}.wav #{part.audio.url} ; "
72
+ end
73
+ puts! cmd, 'cmd'
74
+ out = `#{cmd}`
75
+ puts! out, 'out'
76
+
77
+ ## get overlays
78
+ cmd = "cd #{Rails.root.join('tmp', @newsvideo.id)} ; "
79
+ @newsvideo.newsoverlays.each_with_index do |overlay, idx|
80
+ cmd = "#{cmd} wget -O overlay_#{idx}.mp4 #{overlay.video.video.url} ; "
81
+ end
82
+ puts! cmd, 'cmd'
83
+ out = `#{cmd}`
84
+ puts! out, 'out'
85
+
86
+ ## video concat
87
+ cmd = <<AOL
88
+ cd #{Rails.root.join('tmp', @newsvideo.id)} ;
89
+ rm -f video_concat.mp4 ;
90
+ ffmpeg -f concat -safe 0 -i videolist.txt -c copy video_concat.mp4 ;
91
+ AOL
92
+ puts! cmd, 'cmd'
93
+ out = `#{cmd}`
94
+ puts! out, 'out'
95
+
96
+ ## audio concat
97
+ audio_filenames = (0...@newsvideo.newspartials.length).map { |i| "newspartial_#{i}.wav" }.join("|")
98
+ cmd = <<AOL
99
+ cd #{Rails.root.join('tmp', @newsvideo.id)} ;
100
+ rm -f audio_concat.wav ;
101
+ ffmpeg -f concat -safe 0 -i audiolist.txt -c copy audio_concat.wav ;
102
+ AOL
103
+ puts! cmd, 'cmd'
104
+ out = `#{cmd}`
105
+ puts! out, 'out'
106
+
107
+ ## combine base
108
+ cmd = <<AOL
109
+ cd #{Rails.root.join('tmp', @newsvideo.id)} ;
110
+ rm -f output.mp4 ;
111
+ ffmpeg -i video_concat.mp4 -i audio_concat.wav -c:v copy -c:a aac combined_base.mp4 ;
112
+ AOL
113
+ puts! cmd, 'cmd'
114
+ out = `#{cmd}`
115
+ puts! out, 'out'
116
+
117
+ ## combine overlays
118
+ nn = @newsvideo.newsoverlays.map { |ol| ol.start_at_ms }
119
+ puts! nn, 'nn'
120
+ ffmpeg_cmd = [ "ffmpeg -i combined_base.mp4 \\ " ]
121
+ nn.each_with_index do |ms, idx|
122
+ ffmpeg_cmd.push " -i overlay_#{idx}.mp4 \\ "
123
+ end
124
+ ffmpeg_cmd.push "-filter_complex \" \\ "
125
+ #
126
+ nn.each_with_index do |ms, idx|
127
+ ffmpeg_cmd.push " [#{idx+1}:v]setpts=PTS-STARTPTS+#{ms.to_f/1000}/TB[v#{idx+1}]; \\ "
128
+ end
129
+ #
130
+ curr_s = "0:v"
131
+ n = nil
132
+ nn.each_with_index do |ms, idx|
133
+ n = idx+1
134
+ ffmpeg_cmd.push " [#{curr_s}][v#{n}]overlay=0:0:eof_action=pass[tmp#{n}]; \\ "
135
+ curr_s = "tmp#{n}"
136
+ end
137
+ ffmpeg_cmd.push " \" -map \"[#{curr_s}]\" -map 0:a? -c:v libx264 -c:a copy combined_fin.mp4 "
138
+ ffmpeg_cmd = ffmpeg_cmd.join("\n")
139
+ puts "+++ ffmpeg_cmd:"
140
+ puts ffmpeg_cmd
141
+
142
+ # combine overlays 2
143
+ cmd = <<AOL
144
+ cd #{Rails.root.join('tmp', @newsvideo.id)} ;
145
+ rm -f combined_fin.mp4 ;
146
+ #{ffmpeg_cmd} ;
147
+ AOL
148
+ puts! cmd, 'cmd'
149
+ out = `#{cmd}`
150
+ puts! out, 'out'
151
+
152
+ ## upload the video.
153
+ @video = Wco::Video.new name: @newsvideo.title
154
+ video_path = Rails.root.join("tmp", @newsvideo.id, "combined_fin.mp4")
155
+ @video.video = File.open(video_path)
156
+ @video.save!
157
+ end
158
+
53
159
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wco_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.227
4
+ version: 3.1.0.229
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Pudeyev
@@ -463,6 +463,7 @@ files:
463
463
  - app/controllers/wco/videos_controller.rb
464
464
  - app/helpers/wco/application_helper.rb
465
465
  - app/jobs/wco/newspartial_video_job.rb
466
+ - app/jobs/wco/newsvideo_generate_job.rb
466
467
  - app/jobs/wco/newsvideo_illustration_job.rb
467
468
  - app/jobs/wco_hosting/certbot_job.rb
468
469
  - app/mailers/wco_email/application_mailer.rb