diff options
| author | AppleDash <[email protected]> | 2020-09-25 23:13:15 -0400 |
|---|---|---|
| committer | AppleDash <[email protected]> | 2020-09-25 23:13:15 -0400 |
| commit | 90feaa87abbd61178df8d3481fd66ee5e0bc8738 (patch) | |
| tree | 013c24e4b9432833c0dcc14501056c64e22d53e6 /lib/booru/image_processing/mp4_processor.rb | |
| parent | db3a4525ad4dbf5c88dee61c50143e43a426b349 (diff) | |
Incorporate logging into new image processing pipeline.
Diffstat (limited to 'lib/booru/image_processing/mp4_processor.rb')
| -rw-r--r-- | lib/booru/image_processing/mp4_processor.rb | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/booru/image_processing/mp4_processor.rb b/lib/booru/image_processing/mp4_processor.rb index b4989b1..d0f49a9 100644 --- a/lib/booru/image_processing/mp4_processor.rb +++ b/lib/booru/image_processing/mp4_processor.rb @@ -16,36 +16,42 @@ module Booru end def pre_process + write_log "pre_process" # generate still image - median_time = `ffprobe -i #{@original_path.shellescape} -show_entries format=duration -v quiet -of csv="p=0"`.to_f / 2 - `ffmpeg -loglevel quiet -n -i #{@original_path.shellescape} -ss #{median_time} -frames:v 1 #{@rasterized.shellescape}` + median_time = exec("ffprobe -i #{@original_path.shellescape} -show_entries format=duration -v quiet -of csv=\"p=0\"").to_f / 2 + exec "ffmpeg -loglevel quiet -n -i #{@original_path.shellescape} -ss #{median_time} -frames:v 1 #{@rasterized.shellescape}" end def generate_version(dimensions, destination_path) + write_log "generate_version #{dimensions} #{destination_path}" + width, height = dimensions width &= 4_294_967_294 height &= 4_294_967_294 # generate webm version - `ffmpeg -loglevel 0 -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.gsub(/mp4\z/, 'webm').shellescape}` + 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.gsub(/mp4\z/, 'webm').shellescape}" # generate mp4 version - `ffmpeg -loglevel 0 -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.shellescape}` + 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.shellescape}" end def generate_full_version(destination_path) + write_log "generate_full_version" + webm_path = File.join(File.dirname(destination_path), 'full.webm') FileUtils.ln_sf(@original_path, destination_path) # generate full.webm from full.mp4 - `ffmpeg -loglevel 0 -threads 0 -y -i #{@original_path} -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -preset veryfast #{webm_path}` + exec "ffmpeg -loglevel warning -threads 0 -y -i #{@original_path} -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" -preset veryfast #{webm_path}" end def additional_process + write_log "additional_process" # generate gifs from mp4s; no idea why this is special-cased. - duration = `ffprobe -loglevel quiet -of 'compact=nokey=1:print_section=0' -show_format_entry duration #{@original_path.shellescape}`.chomp.to_f / 10 + duration = exec("ffprobe -loglevel quiet -of 'compact=nokey=1:print_section=0' -show_format_entry duration #{@original_path.shellescape}").chomp.to_f / 10 [[250, :thumb], [150, :thumb_small], [50, :thumb_tiny]].each do |w, n| - `ffmpeg -loglevel 0 -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 -O2 > #{@directory}/#{n}.gif` + 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 -O2 > #{@directory}/#{n}.gif") end end end |
