From 7bc5cf9ddbec811c6402c8943c71a769a18825d9 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 28 Oct 2014 11:15:46 -0700 Subject: [PATCH] support for running ugoira conversion manually from console --- app/logical/pixiv_ugoira_converter.rb | 6 ++++-- app/logical/pixiv_ugoira_service.rb | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/logical/pixiv_ugoira_converter.rb b/app/logical/pixiv_ugoira_converter.rb index 6d6915763..263b542aa 100644 --- a/app/logical/pixiv_ugoira_converter.rb +++ b/app/logical/pixiv_ugoira_converter.rb @@ -38,8 +38,10 @@ class PixivUgoiraConverter end ext = folder.first.name.match(/\.(\w{,4})$/)[1] - system("ffmpeg -loglevel quiet -i #{tmpdir}/images/%06d.#{ext} -codec:v libvpx -crf 4 -b:v 5000k -an #{tmpdir}/tmp.webm") - system("mkvmerge -q -o #{write_path} --webm --timecodes 0:#{tmpdir}/timecodes.tc #{tmpdir}/tmp.webm") + # system("ffmpeg -loglevel quiet -i #{tmpdir}/images/%06d.#{ext} -codec:v libvpx -crf 4 -b:v 5000k -an #{tmpdir}/tmp.webm") + # system("mkvmerge -q -o #{write_path} --webm --timecodes 0:#{tmpdir}/timecodes.tc #{tmpdir}/tmp.webm") + system("ffmpeg -i #{tmpdir}/images/%06d.#{ext} -codec:v libvpx -crf 4 -b:v 5000k -an #{tmpdir}/tmp.webm") + system("mkvmerge -o #{write_path} --webm --timecodes 0:#{tmpdir}/timecodes.tc #{tmpdir}/tmp.webm") end end diff --git a/app/logical/pixiv_ugoira_service.rb b/app/logical/pixiv_ugoira_service.rb index 2657ceb93..831418b20 100644 --- a/app/logical/pixiv_ugoira_service.rb +++ b/app/logical/pixiv_ugoira_service.rb @@ -1,6 +1,17 @@ class PixivUgoiraService attr_reader :width, :height, :frame_data, :content_type + def self.regen(post) + service = new() + service.load( + :is_ugoira => true, + :ugoira_width => post.image_width, + :ugoira_height => post.image_height, + :ugoira_frame_data => post.pixiv_ugoira_frame_data.data + ) + service.generate_resizes(post.file_path, post.large_file_path, post.preview_file_path, false) + end + def process(post) save_frame_data(post) end @@ -9,9 +20,13 @@ class PixivUgoiraService PixivUgoiraFrameData.create(:data => @frame_data, :content_type => @content_type, :post_id => post.id) end - def generate_resizes(source_path, output_path, preview_path) + def generate_resizes(source_path, output_path, preview_path, delay = true) # Run this a bit in the future to give the upload process time to move the file - PixivUgoiraConverter.delay(:queue => Socket.gethostname, :run_at => 2.seconds.from_now).convert(source_path, output_path, preview_path, @frame_data) + if delay + PixivUgoiraConverter.delay(:queue => Socket.gethostname, :run_at => 2.seconds.from_now).convert(source_path, output_path, preview_path, @frame_data) + else + PixivUgoiraConverter.convert(source_path, output_path, preview_path, @frame_data) + end # since the resizes will be delayed, just touch the output file so the # file distribution wont break