diff options
| author | AppleDash <[email protected]> | 2021-03-09 22:35:20 -0500 |
|---|---|---|
| committer | AppleDash <[email protected]> | 2021-03-09 22:35:20 -0500 |
| commit | dc3bc581222619054aaeda10c6860fbc570ca480 (patch) | |
| tree | bb23eef7f42b20f1e8ae8b4125da2e1c44904e56 /lib/booru/image_processing/webm_processor.rb | |
| parent | 296603cc669b1ca66ba575aba4bf8a74432ea31f (diff) | |
I dunno, mediatools or something.
Diffstat (limited to 'lib/booru/image_processing/webm_processor.rb')
| -rw-r--r-- | lib/booru/image_processing/webm_processor.rb | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/booru/image_processing/webm_processor.rb b/lib/booru/image_processing/webm_processor.rb index bf31b93..c07fb01 100644 --- a/lib/booru/image_processing/webm_processor.rb +++ b/lib/booru/image_processing/webm_processor.rb @@ -1,3 +1,4 @@ +require 'open3' require 'shellwords' module Booru @@ -5,8 +6,8 @@ module Booru class WebMProcessor < Processor include ShellHelper - def initialize(original_path, directory) - super(original_path, directory) + def initialize(original_path, directory, metadata) + super(original_path, directory, metadata) @rasterized = File.join(@directory, 'still.png') end @@ -16,8 +17,10 @@ module Booru def pre_process write_log "pre_process" - median_time = exec("ffprobe -i #{@original_path.shellescape} -show_entries format=duration -v quiet -of csv=\"p=0\"").to_f / 2 - exec "ffmpeg -loglevel error -n -i #{@original_path.shellescape} -ss #{median_time} -frames:v 1 #{@rasterized.shellescape}" + median_time = @metadata[:duration] / 2.0 + write_log "generate_thumb(\"#{@original_path}\", #{median_time}, \"#{@rasterized}\")" + result = Booru::MediaTools.generate_thumb(@original_path, median_time, @rasterized) + write_log("result: #{result}") end def generate_version(dimensions, destination_path) @@ -28,33 +31,32 @@ module Booru height &= 4_294_967_294 # generate webm thumb - exec "ffmpeg -loglevel warning -threads 0 -y -i #{@original_path.shellescape} -c:v libvpx -b:v 1M -crf 10 -speed 16 -vf \"scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease\" #{destination_path.shellescape}" - # generate mp4 thumb - # exec "ffmpeg -loglevel warning -threads 0 -y -i #{@original_path.shellescape} -vf \"scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease, scale=trunc(iw/2)*2:trunc(ih/2)*2\" -preset veryfast #{destination_path.gsub(/webm\z/, 'mp4').shellescape}" + ffmpeg '-threads', '0', + '-y', + '-i', @original_path, + '-c:v', 'libvpx', + '-b:v', '1M', + '-crf', '10', + '-speed', '16', + '-vf', "scale=w=#{width}:h=#{height}:force_original_aspect_ratio=decrease", + destination_path end def generate_full_version(destination_path) write_log "generate_full_version" - # mp4_path = File.join(File.dirname(destination_path), 'full.mp4') FileUtils.ln_sf(@original_path, destination_path) - - # generate full.mp4 from full.webm - # exec "ffmpeg -loglevel warning -threads 0 -y -i #{@original_path} -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" -preset veryfast #{mp4_path}" end def additional_process write_log "additional_process" + # generate gifs from webms; no idea why this is special-cased. - duration = exec("ffprobe -loglevel error -of 'compact=nokey=1:print_section=0' -show_format_entry duration #{@original_path.shellescape}").chomp.to_f / 10 + duration = @metadata[:duration] / 10 [[250, :thumb], [150, :thumb_small], [50, :thumb_tiny]].each do |w, n| exec "ffmpeg -loglevel warning -i #{@original_path.shellescape} -vf \"fps=1/#{duration},scale=w=#{w}:h=#{w}:force_original_aspect_ratio=decrease\" -vframes 10 -qscale:v 2 -f image2pipe -vcodec ppm - | convert -delay 50 -loop 0 - gif:- | gifsicle --no-warnings -O2 -o #{@directory}/#{n}.gif" end end - - def video_duration - exec("ffprobe -i #{@original_path.shellescape} -show_entries format=duration -v quiet -of csv=\"p=0\"").to_f - end end end end |
