Created
August 27, 2012 14:52
-
-
Save skord/3489199 to your computer and use it in GitHub Desktop.
Deletes X frames from mplayer jpeg output
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
| #!/usr/bin/env ruby | |
| def discard_x_frames(number) | |
| files = Dir.glob('*.jpg') | |
| files.in_groups_of(number + 1).each do |files| | |
| files[1..-1].each do |file| | |
| File.unlink(file) | |
| end | |
| end | |
| end | |
| class Array | |
| def in_groups_of(number, fill_with = nil) | |
| if fill_with == false | |
| collection = self | |
| else | |
| # size % number gives how many extra we have; | |
| # subtracting from number gives how many to add; | |
| # modulo number ensures we don't add group of just fill. | |
| padding = (number - size % number) % number | |
| collection = dup.concat([fill_with] * padding) | |
| end | |
| if block_given? | |
| collection.each_slice(number) { |slice| yield(slice) } | |
| else | |
| groups = [] | |
| collection.each_slice(number) { |group| groups << group } | |
| groups | |
| end | |
| end | |
| end | |
| discard_x_frames ARGV[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment