Multimedia scripts for windows
Last update
2020-03-04
2020
03-04
«scripts per organizzare i files multimediali ai suoceri»

comprimi_media (jpe*g, mp4, mov, avi, mpeg)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/env ruby
%w{ shellwords FileUtils }.each{|l| require l }
%w{ foto video done }.each{|d| FileUtils.mkdir_p d }

Dir['*'].grep(/\.jpe*g$/i).sort.each do |f|
  puts f
  fout = f.sub(/jpe*g$/i, 'jpg')
  system %Q| convert -quality 80 #{f.shellescape} foto/#{fout.shellescape} |
  FileUtils.mv f, "done/#{f}" if $?.to_i == 0
end

Dir['*'].grep(/\.(mp4|mov|avi|mpeg)$/i).each do |f|
  puts "----- #{f} --------------------------"
  fout = f.sub(/(mp4|mov|avi|mpeg)$/i, 'mp4')
  system %Q| ffmpeg -i #{f.shellescape} -c:v libx264 -c:a libmp3lame -b:a 128k video/#{fout.shellescape} |
  FileUtils.mv f, "done/#{f}" if $?.to_i == 0
end

ffmpeg for windows

enumerate files

1
Dir['*'].sort.each_with_index{|f, i| File.rename f, "#{'%04d' % (i+1)}.mp4"}; nil

misc

1
2
3
4
5
# PDF to JPG
ls *.pdf | sed -r 's/(.+).pdf/pdftoppm -jpeg \0 \L\1.jpg/' | sh

# lossless rotate JPG
jpegtran -rotate 90 in.jpg > out.jpg