Integrated Clipping object into existing code (removed lots of code from Video)
This commit is contained in:
Родитель
32ad89fbf2
Коммит
7e3b778d5d
|
@ -15,3 +15,4 @@ config/panda_init_*.rb
|
|||
panda_all_staging_nginx.conf
|
||||
public/images/tmp/*jpg
|
||||
public/store
|
||||
public/tmp
|
||||
|
|
|
@ -39,7 +39,7 @@ class Thumbnail < Application
|
|||
@video.save
|
||||
|
||||
@video.successful_encodings.each do | video |
|
||||
video.upload_thumbnail_to_s3
|
||||
video.clipping.upload_to_store
|
||||
end
|
||||
|
||||
redirect url(:video, @video.key)
|
||||
|
|
|
@ -18,6 +18,10 @@ class Video < SimpleDB::Base
|
|||
'videos'
|
||||
end
|
||||
|
||||
def clipping
|
||||
Clipping.new(self)
|
||||
end
|
||||
|
||||
# Classification
|
||||
# ==============
|
||||
|
||||
|
@ -90,7 +94,7 @@ class Video < SimpleDB::Base
|
|||
|
||||
# Location to store video file fetched from S3 for encoding
|
||||
def tmp_filepath
|
||||
Panda::Config[:tmp_video_dir] / self.filename
|
||||
Panda::Config[:private_tmp_path] / self.filename
|
||||
end
|
||||
|
||||
# Has the actual video file been uploaded for encoding?
|
||||
|
@ -123,22 +127,6 @@ class Video < SimpleDB::Base
|
|||
self.audio_bitrate.to_i * 1024
|
||||
end
|
||||
|
||||
def screenshot
|
||||
self.filename + ".jpg"
|
||||
end
|
||||
|
||||
def thumbnail
|
||||
self.filename + "_thumb.jpg"
|
||||
end
|
||||
|
||||
def screenshot_url
|
||||
Store.url(self.screenshot)
|
||||
end
|
||||
|
||||
def thumbnail_url
|
||||
Store.url(self.thumbnail)
|
||||
end
|
||||
|
||||
# Encding attr helpers
|
||||
# ====================
|
||||
|
||||
|
@ -148,7 +136,7 @@ class Video < SimpleDB::Base
|
|||
|
||||
def embed_html
|
||||
return nil unless self.encoding?
|
||||
%(<embed src="#{Store.url('flvplayer.swf')}" width="#{self.width}" height="#{self.height}" allowfullscreen="true" allowscriptaccess="always" flashvars="&displayheight=#{self.height}&file=#{self.url}&width=#{self.width}&height=#{self.height}&image=#{self.screenshot_url}" />)
|
||||
%(<embed src="#{Store.url('flvplayer.swf')}" width="#{self.width}" height="#{self.height}" allowfullscreen="true" allowscriptaccess="always" flashvars="&displayheight=#{self.height}&file=#{self.url}&width=#{self.width}&height=#{self.height}&image=#{self.clipping.url(:screenshot)}" />)
|
||||
end
|
||||
|
||||
def embed_js
|
||||
|
@ -159,7 +147,7 @@ class Video < SimpleDB::Base
|
|||
var flashvars = {};
|
||||
|
||||
flashvars.file = "#{self.url}";
|
||||
flashvars.image = "#{self.screenshot_url}";
|
||||
flashvars.image = "#{self.clipping.url(:screenshot)}";
|
||||
flashvars.width = "#{self.width}";
|
||||
flashvars.height = "#{self.height}";
|
||||
flashvars.fullscreen = "true";
|
||||
|
@ -191,62 +179,22 @@ class Video < SimpleDB::Base
|
|||
false
|
||||
end
|
||||
|
||||
def upload_thumbnail_to_s3
|
||||
percentage = (self.parent_video.thumbnail_position || self.default_thumbnail_position)
|
||||
Store.set(self.screenshot, self.screenshot_tmp_filepath(percentage))
|
||||
Store.set(self.thumbnail, self.thumbnail_tmp_filepath(percentage))
|
||||
end
|
||||
|
||||
def capture_and_resize_thumbnail(percentage)
|
||||
raise RuntimeError, "You may not call capture_and_resize_thumbnail unless the video is available locally" unless File.exists?(self.tmp_filepath)
|
||||
|
||||
t = RVideo::Inspector.new(:file => self.tmp_filepath)
|
||||
t.capture_frame("#{percentage}%", screenshot_tmp_filepath(percentage))
|
||||
|
||||
constrain_to_height = Panda::Config[:thumbnail_height_constrain].to_f
|
||||
width = (self.width.to_f/(self.height.to_f/constrain_to_height)).to_i
|
||||
height = constrain_to_height.to_i
|
||||
|
||||
GDResize.new.resize(self.screenshot_tmp_filepath(percentage), self.thumbnail_tmp_filepath(percentage), [width,height])
|
||||
end
|
||||
|
||||
def screenshot_tmp_filepath(percentage)
|
||||
"public" + tmp_images_dir / "#{self.filename}_#{percentage}.jpg"
|
||||
end
|
||||
|
||||
def thumbnail_tmp_filepath(percentage)
|
||||
"public" + tmp_images_dir / "#{self.filename}_#{percentage}_thumb.jpg"
|
||||
end
|
||||
|
||||
def thumbnail_tmp_url(percentage)
|
||||
tmp_images_dir / "#{self.filename}_#{percentage}_thumb.jpg"
|
||||
end
|
||||
|
||||
def tmp_images_dir
|
||||
"/images/tmp"
|
||||
end
|
||||
|
||||
def default_thumbnail_position
|
||||
50.0
|
||||
end
|
||||
|
||||
def thumbnail_percentages
|
||||
return [self.default_thumbnail_position] if Panda::Config[:choose_thumbnail] == false
|
||||
divider = 100.0 / (Panda::Config[:choose_thumbnail] + 2).to_f
|
||||
percentages = (1..Panda::Config[:choose_thumbnail]).map {|i| i * divider }
|
||||
choose_thumbnail = Panda::Config[:choose_thumbnail]
|
||||
|
||||
return [self.default_thumbnail_position] if choose_thumbnail == false
|
||||
|
||||
divider = 100.0 / (choose_thumbnail + 2).to_f
|
||||
percentages = (1..choose_thumbnail).map {|i| i * divider }
|
||||
end
|
||||
|
||||
def generate_thumbnail_selection
|
||||
self.thumbnail_percentages.each do |percentage|
|
||||
capture_and_resize_thumbnail(percentage)
|
||||
self.clipping.capture(percentage)
|
||||
self.clipping.resize(percentage)
|
||||
end
|
||||
end
|
||||
|
||||
# def cleanup_thumbnail_selection
|
||||
# FileUtils.rm Dir.glob("public/images/tmp/#{self.filename}*.jpg")
|
||||
# end
|
||||
|
||||
|
||||
# Uploads
|
||||
# =======
|
||||
|
||||
|
@ -594,8 +542,8 @@ RESPONSE
|
|||
end
|
||||
|
||||
self.upload_to_s3
|
||||
self.generate_thumbnail_selection # Generate thumbnails for all percentage options
|
||||
self.upload_thumbnail_to_s3
|
||||
self.generate_thumbnail_selection
|
||||
self.clipping.upload_to_store
|
||||
|
||||
self.notification = 0
|
||||
self.status = "success"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
</tr>
|
||||
<% encodings.each do |v| %>
|
||||
<tr>
|
||||
<td><div class="thumb"><a href="/videos/<%= v.key %>"><img src="<%= v.thumbnail_url %>" /></a></div></td>
|
||||
<td><div class="thumb"><a href="/videos/<%= v.key %>"><img src="<%= v.clipping.url(:thumbnail) %>" /></a></div></td>
|
||||
<td>
|
||||
<a href="/videos/<%= v.key %>" class="filename"><%= v.original_filename || "No filename" %></a>
|
||||
<span><%= v.duration_str %></span>
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
<ul id="screenshots">
|
||||
<% @percentages.each do | percentage |%>
|
||||
<li><%= link_to image_tag(@video.thumbnail_tmp_url(percentage)), "/videos/#{@video.key}/thumbnail/update?percentage=#{percentage}&iframe=#{params[:iframe]}" %></li>
|
||||
<li><%= link_to image_tag(@video.clipping.tmp_url(:thumbnail)), "/videos/#{@video.key}/thumbnail/update?percentage=#{percentage}&iframe=#{params[:iframe]}" %></li>
|
||||
<% end %>
|
||||
</ul>
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
<ul id="screenshots">
|
||||
<% @percentages.each do | percentage |%>
|
||||
<li><%= link_to image_tag(@video.thumbnail_tmp_url(percentage)), "/videos/#{@video.key}/thumbnail/create?percentage=#{percentage}&iframe=#{params[:iframe]}" %></li>
|
||||
<li><%= link_to image_tag(@video.clipping.tmp_url(:thumbnail, percentage)), "/videos/#{@video.key}/thumbnail/create?percentage=#{percentage}&iframe=#{params[:iframe]}" %></li>
|
||||
<% end %>
|
||||
</ul>
|
|
@ -16,6 +16,12 @@ describe Video do
|
|||
Store.stub!(:delete).and_return(true)
|
||||
end
|
||||
|
||||
describe "clipping" do
|
||||
it "should return a clipping" do
|
||||
@video.clipping.should be_kind_of(Clipping)
|
||||
end
|
||||
end
|
||||
|
||||
# Classification
|
||||
# ==============
|
||||
|
||||
|
@ -128,25 +134,6 @@ describe Video do
|
|||
@video.resolution.should be_nil
|
||||
end
|
||||
|
||||
# def video_bitrate_in_bits
|
||||
# def audio_bitrate_in_bits
|
||||
|
||||
it "screenshot" do
|
||||
@video.screenshot.should == 'abc.mov.jpg'
|
||||
end
|
||||
|
||||
it "thumbnail" do
|
||||
@video.thumbnail.should == 'abc.mov_thumb.jpg'
|
||||
end
|
||||
|
||||
it "screenshot_url" do
|
||||
@video.screenshot_url.should == "http://videos.pandastream.com/abc.mov.jpg"
|
||||
end
|
||||
|
||||
it "thumbnail_url" do
|
||||
@video.thumbnail_url.should == "http://videos.pandastream.com/abc.mov_thumb.jpg"
|
||||
end
|
||||
|
||||
# def set_encoded_at
|
||||
|
||||
# Encding attr helpers
|
||||
|
@ -173,25 +160,7 @@ describe Video do
|
|||
it "should upload_to_s3"
|
||||
|
||||
it "should fetch_from_s3"
|
||||
|
||||
it "should capture_thumbnail_and_upload_to_s3" do
|
||||
inspector = mock(RVideo::Inspector)
|
||||
inspector.should_receive(:capture_frame).with('50%', '/tmp/abc.mov.jpg')
|
||||
RVideo::Inspector.should_receive(:new).with(:file => '/tmp/abc.mov').and_return(inspector)
|
||||
|
||||
gd = mock(GDResize)
|
||||
gd.should_receive(:resize).with('/tmp/abc.mov.jpg', '/tmp/abc.mov_thumb.jpg', [168,126]) # Dimensions based on thumbnail_height_constrain of 126
|
||||
GDResize.should_receive(:new).and_return(gd)
|
||||
|
||||
Store.should_receive(:set).with('abc.mov.jpg', '/tmp/abc.mov.jpg').and_return(true)
|
||||
Store.should_receive(:set).with('abc.mov_thumb.jpg', '/tmp/abc.mov_thumb.jpg').and_return(true)
|
||||
|
||||
parent_video = mock (Video)
|
||||
parent_video.should_receive(:thumbnail_position).and_return(false)
|
||||
@video.should_receive(:parent_video).and_return(parent_video)
|
||||
@video.capture_thumbnail_and_upload_to_s3.should be_true
|
||||
end
|
||||
|
||||
# Uploads
|
||||
# =======
|
||||
|
||||
|
@ -294,9 +263,6 @@ describe Video do
|
|||
lambda {@video.send_notification}.should raise_error(StandardError)
|
||||
end
|
||||
|
||||
# it "should send_status_update_to_client" do
|
||||
|
||||
|
||||
# Encoding
|
||||
# ========
|
||||
|
||||
|
@ -357,7 +323,11 @@ describe Video do
|
|||
encoding.should_receive(:encode_flv_flash)
|
||||
|
||||
encoding.should_receive(:upload_to_s3)
|
||||
encoding.should_receive(:capture_thumbnail_and_upload_to_s3)
|
||||
encoding.should_receive(:generate_thumbnail_selection)
|
||||
clipping = returning(mock(Clipping)) do |c|
|
||||
c.should_receive(:upload_to_store)
|
||||
end
|
||||
encoding.should_receive(:clipping).and_return(clipping)
|
||||
|
||||
encoding.should_receive(:notification=).with(0)
|
||||
encoding.should_receive(:status=).with("success")
|
||||
|
|
Загрузка…
Ссылка в новой задаче