Created
June 16, 2014 01:00
-
-
Save ikeisuke/47f97a216075168fdfb6 to your computer and use it in GitHub Desktop.
rubyで動画ファイルを作成日のディレクトリに移動する ref: http://qiita.com/ikeisuke/items/aafd96e69c2c5feb23d8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% brew install ffmpeg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ffmpeg -i ***.MOV |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffmpeg_video_info' | |
require 'time' | |
require 'fileutils' | |
Dir.glob(%w(*.avi *.AVI *.mov *.MOV *.mp4 *.MP4 *.3gp)) do |file| | |
info = FFmpegVideoInfo.get(file) | |
info['metadata'] ||= {} | |
creation_at = info['metadata']['date'] || info['metadata']['creation_time'] || File.mtime(file).inspect | |
time = Time.parse(creation_at) | |
year = time.year | |
month = time.month | |
day = time.day | |
dir = File.join("#{year}", "#{year}-#{format("%02d", month)}", "#{year}-#{format("%02d", month)}-#{format("%02d", day)}") | |
unless File.exists?(dir) | |
FileUtils.mkdir_p(dir) | |
end | |
if File.exists?(File.join(dir, file)) | |
puts "#{File.join(dir, file)} already exists." | |
next | |
end | |
FileUtils.mv(file, dir) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '***.MOV': | |
Metadata: | |
major_brand : qt | |
minor_version : 0 | |
compatible_brands: qt | |
creation_time : 2014-06-11 22:17:44 | |
encoder : 7.1.1 | |
encoder-jpn : 7.1.1 | |
date : 2014-06-12T07:17:44+0900 | |
date-jpn : 2014-06-12T07:17:44+0900 | |
location : *** | |
location-jpn : *** | |
model : iPhone 5s | |
model-jpn : iPhone 5s | |
make : Apple | |
make-jpn : Apple | |
Duration: 00:00:18.74, start: 0.000000, bitrate: 16993 kb/s | |
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 16912 kb/s, 29.98 fps, 29.97 tbr, 600 tbn, 1200 tbc (default) | |
Metadata: | |
rotate : 90 | |
creation_time : 2014-06-11 22:17:44 | |
handler_name : Core Media Data Handler | |
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 62 kb/s (default) | |
Metadata: | |
creation_time : 2014-06-11 22:17:44 | |
handler_name : Core Media Data Handler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '***.mp4': | |
Metadata: | |
major_brand : mp42 | |
minor_version : 1 | |
compatible_brands: mp41mp42isom | |
creation_time : 2014-06-10 11:17:21 | |
Duration: 00:00:36.40, start: 0.000023, bitrate: 3014 kb/s | |
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default) | |
Metadata: | |
creation_time : 2014-06-10 11:17:21 | |
handler_name : Core Media Audio | |
Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x1280, 2943 kb/s, 29.98 fps, 29.97 tbr, 600 tbn, 1200 tbc (default) | |
Metadata: | |
creation_time : 2014-06-10 11:17:21 | |
handler_name : Core Media Video |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment