Multimedia scripts for windows
mouse 246 · person cloud · link
Last update
2020-08-16
2020
08-16
«scripts per organizzare i files multimediali ai suoceri»

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

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

files = Dir['*'].grep(/\.(jpe*g|png)$/i).sort
files.each_with_index do |f, i|
  puts "----- #{ '%6.2f' % ((i+1).to_f/files.size*100) }%  #{f} ".ljust(79, '-')
  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

files = Dir['*'].grep(/\.(mp4|mov|avi|mpeg)$/i)
files.each_with_index do |f, i|
  puts "----- #{ '%6.2f' % ((i+1).to_f/files.size*100) }%  #{f} ".ljust(79, '-')
  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
1
2
# run script on every subfolder:
%x[find -type d].split("\n")[1..-1].each{|d| puts d; Dir.chdir(d){ system 'comprimi_media' } }; nil

External tools: ffmpeg for windows, CloneSpy file duplicate finder, WinDirStat folder tree size

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