moshy 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b0c17c458da7a8ea731db28eaf6a919469107b9d
4
- data.tar.gz: fa5b4eea8ca1538790eaf989e77e40b058fcf01c
2
+ SHA256:
3
+ metadata.gz: edf65fecfa904ea31534e576836c26e9e044bd98f1366effca7547202c099ac3
4
+ data.tar.gz: c5d56088d7a9c84c55720ee6fe839e88cbb1cd9af3eef7ba0f712496af867e85
5
5
  SHA512:
6
- metadata.gz: a2692be61ccc6e9088d6d3ab9ad75af55b2c7ce0d9fa8d67dc20562b6ec2f7731f36424ce430a7cb6ccf17bea958cb19fcf116e2267981853e81043b812f81fa
7
- data.tar.gz: aa247fc3c2115fb4a5ebaaf6b69ee25c33735311ef7a0a10a8ab26993a4d62322b5b546f3c2ee3440fc639be7e7c935c59a148aab2c5f7c87dd485cab69f9ab2
6
+ metadata.gz: 38e68fc229fb0e00cafb669bb2239ac24ec982aef442dabbeba00c2647bf81270627c36eae86664f39e252dbba8e407f9427661a8f4201765c43bff6f2cb2ee3
7
+ data.tar.gz: a3656dfab4e713f695d443f825e46c92b3b3c4e6f93593b35034cb9118820c48b2370733b1c2ccfe3479650e517f89267050f8793116585537b91badb9aca310
data/.gitignore CHANGED
@@ -1,22 +1,22 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/DEVNOTES.md ADDED
@@ -0,0 +1,7 @@
1
+ # Running on Windows 10
2
+
3
+ Need to have PATH set up properly with ffmpeg
4
+
5
+ ```
6
+ ruby -Ilib ./bin/moshy -m prep -i i.mp4 -o o.avi
7
+ ```
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in moshy.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in moshy.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2015 Way Spurr-Chen <wayspurrchen@gmail.com> <http://wayspurrchen.com/>
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2015 Way Spurr-Chen <wayspurrchen@gmail.com> <http://wayspurrchen.com/>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,71 +1,94 @@
1
- # moshy
2
-
3
- moshy is a command line datamoshing utility kit for AVI files, based heavily on [aviglitch](https://github.com/ucnv/aviglitch).
4
- It's designed to make common datamoshing tasks easier without having to open avidemux or other GUI tools. It lets you do stuff like:
5
-
6
- - Convert video files into AVI video files with minimal I-Frames and no B-frames for ultimate moshability
7
- - Create P-Frame duplication effects quickly
8
- - Split a long video file into multiple clips based on its I-Frames
9
- - "Bake" your datamoshed video, encoding the corruption as actual video content for uploading to video services or moshing even further!
10
- - Identifying keyframe and deltaframe indexes in any AVI file
11
- - ...and more!
12
-
13
- If you don't know how to use the command line, this is a great opportunity to learn:
14
-
15
- - Mac OS X Tutorial: http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line
16
- - Windows Tutorial: http://lifehacker.com/5633909/who-needs-a-mouse-learn-to-use-the-command-line-for-almost-anything
17
-
18
- ## Get it!
19
-
20
- You'll need to install [Ruby](https://www.ruby-lang.org/en/). If you're on Mac OS X, you probably already have a local version of Ruby installed. Once that's done, you will need Bundler, a Ruby dependency manager, which you can install with the following command:
21
-
22
- ```
23
- gem install bundler
24
- ```
25
-
26
- Then you can use Bundler to install moshy:
27
-
28
- ```
29
- bundle install moshy
30
- ```
31
-
32
- From there, you can use `moshy` from the command line.
33
-
34
- ## What's it do?
35
-
36
- Moshy currently has six different modes:
37
-
38
- - `prep` - Preps a video file for datamoshing with moshy by converting it
39
- into an AVI with no B-Frames (they're not good for moshing), and placing as
40
- few I-Frames as possible. Requires ffmpeg be installed locally.
41
- - `isplit` - Extracts individual clips from an AVI where each clip is
42
- separated by I-frames in the original AVI. Great for getting specific
43
- clips out of a larger video and later doing I-frame moshing.
44
- - `inspect` - Reads an .avi file and prints which video frames are keyframes
45
- (I-Frames) and which frames are delta frames (P-frames or B-frames). moshy
46
- cannot tell the difference between a P-frame or a B-frame, so you will want
47
- to use avidemux or another program if you need to know.
48
- - `pdupe` - Duplicates a P-frame at a given frame a certain amount. To find
49
- out which frames are P-frames, use software like avidemux to look at the
50
- frame type. WARNING: This mode is a little glitchy. You may need to set
51
- the interval 1 or 2 above or below the frame number you actually want to
52
- duplicate. I'm not sure why this happens, but try it with a small
53
- duplication amount first. NOTE: This can mode take a while to process
54
- over 60-90 frame dupes.
55
- - `ppulse` - Takes c number of frames and every n frames and duplicates them a
56
- given amount, resulting in a consistent P-duplication datamosh that's
57
- good for creating rhythmic effects. This was originally created to
58
- create mosh effects in sync with a beat for a music video.
59
- - `bake` - "Bakes" your datamosh by creating a new video file from your
60
- datamoshed .avi, causing the datamosh effects to be treated as the actual
61
- content of the new video instead of an error. Requires ffmpeg to be
62
- installed locally.
63
-
64
- You can access detailed info on how to use each of them from the command line with
65
- the command `moshy -m <mode> --help`.
66
-
67
- ## Cool!
68
-
69
- If you think this is cool, you'll probably find my list of [glitch art resources](http://www.glitchet.com/resources)
70
- useful as well as the [Glitchet newsletter](http://www.glitchet.com/), a free weekly futuristic
71
- news and glitch aesthetic e-zine.
1
+ # moshy
2
+
3
+ ![](http://imgur.com/OMLTr26.gif)
4
+ created with moshy's pdupe options
5
+
6
+ **moshy** is a command line datamoshing utility kit for AVI files, based heavily on [aviglitch](https://github.com/ucnv/aviglitch).
7
+ It's designed to make common datamoshing tasks easier without having to open avidemux or other GUI tools. It lets you do stuff like:
8
+
9
+ - Convert video files into AVI video files with minimal I-Frames and no B-frames for ultimate moshability
10
+ - Create P-Frame duplication effects quickly
11
+ - Split a long video file into multiple clips based on its I-Frames
12
+ - "Bake" your datamoshed video, encoding the corruption as actual video content for uploading to video services or moshing even further!
13
+ - Identifying keyframe and deltaframe indexes in any AVI file
14
+ - ...and more!
15
+
16
+ If you don't know how to use the command line, this is a great opportunity to learn:
17
+
18
+ - Mac OS X Tutorial: http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line
19
+ - Windows Tutorial: http://lifehacker.com/5633909/who-needs-a-mouse-learn-to-use-the-command-line-for-almost-anything
20
+
21
+ ## Get it!
22
+
23
+ You'll need to install [Ruby](https://www.ruby-lang.org/en/). If you're on Mac OS X, you probably already have a local version of Ruby installed. Once that's done, you can use Rubygems (which comes with Ruby) to install moshy:
24
+
25
+ ```
26
+ gem install moshy
27
+ ```
28
+
29
+ From there, you can use `moshy` from the command line.
30
+
31
+ For a couple commands (`prep` and `bake`), you need to have ffmpeg installed locally.
32
+ [You can get it for your OS here.](https://www.ffmpeg.org/download.html)
33
+
34
+ ## What's it do?
35
+
36
+ Moshy currently has six different modes:
37
+
38
+ - `prep` - Preps a video file for datamoshing with moshy by converting it
39
+ into an AVI with no B-Frames (they're not good for moshing), and placing as
40
+ few I-Frames as possible. Requires ffmpeg be installed locally.
41
+ - `isplit` - Extracts individual clips from an AVI where each clip is
42
+ separated by I-frames in the original AVI. Great for getting specific
43
+ clips out of a larger video and later doing I-frame moshing.
44
+ - `inspect` - Reads an .avi file and prints which video frames are keyframes
45
+ (I-Frames) and which frames are delta frames (P-frames or B-frames). moshy
46
+ cannot tell the difference between a P-frame or a B-frame, so you will want
47
+ to use avidemux or another program if you need to know.
48
+ - `pdupe` - Duplicates a P-frame at a given frame a certain amount. To find
49
+ out which frames are P-frames, use software like avidemux to look at the
50
+ frame type. WARNING: This mode is a little glitchy. You may need to set
51
+ the interval 1 or 2 above or below the frame number you actually want to
52
+ duplicate. I'm not sure why this happens, but try it with a small
53
+ duplication amount first. NOTE: This can mode take a while to process
54
+ over 60-90 frame dupes.
55
+ - `ppulse` - Takes c number of frames and every n frames and duplicates them a
56
+ given amount, resulting in a consistent P-duplication datamosh that's
57
+ good for creating rhythmic effects. This was originally created to
58
+ create mosh effects in sync with a beat for a music video.
59
+ - `bake` - "Bakes" your datamosh by creating a new video file from your
60
+ datamoshed .avi, causing the datamosh effects to be treated as the actual
61
+ content of the new video instead of an error. Requires ffmpeg to be
62
+ installed locally.
63
+
64
+ You can access detailed info on how to use each of them from the command line with
65
+ the command `moshy -m <mode> --help`.
66
+
67
+ ## Cool!
68
+
69
+ If you think this is cool, you'll probably find my list of [glitch art resources](http://www.glitchet.com/resources)
70
+ useful as well as the [Glitchet newsletter](http://www.glitchet.com/), a free weekly futuristic
71
+ news and glitch aesthetic e-zine.
72
+
73
+ ## Quick tutorial
74
+
75
+ Here's a short example of how you might use moshy to create a P-dupe mosh:
76
+
77
+ 1. Choose a YouTube video you want to mosh (I'll use "Charlie bit my finger": <https://www.youtube.com/watch?v=bnRVheEpJG4>)
78
+ 2. Download it with KeepVid (<http://keepvid.com/?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbnRVheEpJG4>)
79
+ 3. "Prep" it with moshy to turn it into an .AVI with minimal I-Frames and all P-frames (because B-frames don't mosh well):
80
+ `moshy -m prep -i charlie.mp4 -o charlie.avi`
81
+ 4. Open charlie.avi in avidemux and clip it down to the segment I want (moshy will soon be able to do this with a "clip" command): ![](http://i.imgur.com/OBy8pbB.png)
82
+ 5. Open charlie_clip.avi and find the frame I want to P-dupe mosh (here, frame 196): ![](http://i.imgur.com/aZsZIx6.png)
83
+ 6. Use moshy in pdupe mode to dupe frame 196 60 times:
84
+ `moshy -m pdupe -i charlie_clip.avi -f 196 -d 60 -o charlie_clip-dupe.avi`
85
+ Open it in a video player (I use VLC) and see if it looks good.
86
+ 7. Awesome, I love it, but I want to clip it down to size. However, since it has so few I-frames, if I just clip it anywhere, the beginning of the video will become corrupted because of lack of pixel data. Let's use moshy to bake the mosh:
87
+ `moshy -m bake -i charlie_clip-dupe.avi -o charlie_clip-dupe-bake.avi`
88
+ 8. Done. Let's open it back up in avidemux, clip it down to size, and save our final result: ![](http://i.imgur.com/07abIqT.png)
89
+ 9. Looks good to me. Let's save it as an MP4 so that I can upload it to Giphy, which will convert it into a .gif for me. (I'm hoping to add modes to moshy that convert videos to .gif and .mp4 directly, too.)
90
+ 10. Done! ![](https://media.giphy.com/media/3o85xoWYyG1HEVs8Vy/giphy.gif)
91
+
92
+ ## Trouble?
93
+
94
+ Having issues? Please [file an issue](https://github.com/wayspurrchen/moshy/issues/new)!
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require "bundler/gem_tasks"
2
+
data/bin/moshy CHANGED
@@ -1,105 +1,107 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'slop'
5
- require 'moshy'
6
-
7
- module Moshy
8
- def self.top_level_help
9
- $options = {
10
-
11
- }
12
- opts = OptionParser.new do |opts|
13
- opts.banner = "
14
- moshy, a Ruby utility for making it easier to datamosh AVI files. It has
15
- multiple modes that can be run with the -m or --mode option.
16
-
17
- MODES DETAILS
18
- -------------
19
-
20
- \"prep\"
21
- ------
22
- Preps a video file for datamoshing with moshy by converting it
23
- into an AVI with no B-Frames (they're not good for moshing), and placing as
24
- few I-Frames as possible. Requires ffmpeg be installed locally.
25
-
26
- \"isplit\"
27
- --------
28
- Extracts individual clips from an AVI where each clip is
29
- separated by I-frames in the original AVI. Great for getting specific
30
- clips out of a larger video and later doing I-frame moshing.
31
-
32
- \"pdupe\"
33
- -------
34
- Duplicates a P-frame at a given frame a certain amount. To find
35
- out which frames are P-frames, use software like avidemux to look at the
36
- frame type. WARNING: This mode is a little glitchy. You may need to set
37
- the interval 1 or 2 above or below the frame number you actually want to
38
- duplicate. I'm not sure why this happens, but try it with a small
39
- duplication amount first. NOTE: This can mode take a while to process
40
- over 60-90 frame dupes.
41
-
42
- \"ppulse\"
43
- --------
44
- Takes c number of frames and every n frames and duplicates them a
45
- given amount, resulting in a consistent P-duplication datamosh that's
46
- good for creating rhythmic effects. This was originally created to
47
- create mosh effects in sync with a beat for a music video.
48
-
49
- \"bake\"
50
- ------
51
- \"Bakes\" your datamosh by creating a new video file from your
52
- datamoshed .avi, causing the datamosh effects to be treated as the actual
53
- content of the new video instead of an error. Requires ffmpeg to be
54
- installed locally.
55
-
56
- \"inspect\"
57
- ---------
58
- Reads an .avi file and prints which video frames are keyframes
59
- (I-Frames) and which frames are delta frames (P-frames or B-frames). moshy
60
- cannot tell the difference between a P-frame or a B-frame, so you will want
61
- to use avidemux or another program if you need to know.
62
-
63
- Run moshy with mode -m <mode> --help to see options for individual modes.
64
- "
65
- end
66
-
67
- begin
68
- opts.parse
69
- rescue OptionParser::InvalidOption, OptionParser::InvalidArgument
70
- end
71
-
72
- puts opts
73
- end
74
- end
75
-
76
- # Because we have multiple modes, we do some initial basic arg checking
77
- # to see if they specified a mode. If not, we show the top-level help menu.
78
- result = Slop.parse suppress_errors: true do |o|
79
- o.string '-m', '--mode'
80
- end
81
-
82
- mode_classes = {
83
- "inspect" => Moshy::Inspect,
84
- "isplit" => Moshy::ISplit,
85
- "pdupe" => Moshy::PDupe,
86
- "ppulse" => Moshy::PPulse,
87
- "prep" => Moshy::Prep,
88
- "bake" => Moshy::Bake
89
- }
90
-
91
- if mode_classes.has_key? result[:m]
92
- # We need to strip out the "m" otherwise our other arg parsers
93
- # will choke on the extra parameter
94
- ARGV.each_with_index do |o, i|
95
- if o == "-m" || o == "--m"
96
- ARGV.delete_at(i + 1)
97
- ARGV.delete_at(i)
98
- break
99
- end
100
- end
101
-
102
- mode_classes[result[:m]].new.cli ARGV
103
- else
104
- Moshy.top_level_help
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'slop'
5
+ require 'moshy'
6
+
7
+ module Moshy
8
+ def self.top_level_help
9
+ $options = {
10
+
11
+ }
12
+ opts = OptionParser.new do |opts|
13
+ opts.banner = "
14
+ moshy, a Ruby utility for making it easier to datamosh AVI files. It has
15
+ multiple modes that can be run with the -m or --mode option.
16
+
17
+ MODES DETAILS
18
+ -------------
19
+
20
+ \"prep\"
21
+ ------
22
+ Preps a video file for datamoshing with moshy by converting it
23
+ into an AVI with no B-Frames (they're not good for moshing), and placing as
24
+ few I-Frames as possible. Requires ffmpeg be installed locally.
25
+
26
+ \"isplit\"
27
+ --------
28
+ Extracts individual clips from an AVI where each clip is
29
+ separated by I-frames in the original AVI. Great for getting specific
30
+ clips out of a larger video and later doing I-frame moshing.
31
+
32
+ \"pdupe\"
33
+ -------
34
+ Duplicates a P-frame at a given frame a certain amount. To find
35
+ out which frames are P-frames, use software like avidemux to look at the
36
+ frame type. WARNING: This mode is a little glitchy. You may need to set
37
+ the interval 1 or 2 above or below the frame number you actually want to
38
+ duplicate. I'm not sure why this happens, but try it with a small
39
+ duplication amount first. NOTE: This can mode take a while to process
40
+ over 60-90 frame dupes.
41
+
42
+ \"ppulse\"
43
+ --------
44
+ Takes c number of frames and every n frames and duplicates them a
45
+ given amount, resulting in a consistent P-duplication datamosh that's
46
+ good for creating rhythmic effects. This was originally created to
47
+ create mosh effects in sync with a beat for a music video.
48
+
49
+ \"bake\"
50
+ ------
51
+ \"Bakes\" your datamosh by creating a new video file from your
52
+ datamoshed .avi, causing the datamosh effects to be treated as the actual
53
+ content of the new video instead of an error. Requires ffmpeg to be
54
+ installed locally.
55
+
56
+ \"inspect\"
57
+ ---------
58
+ Reads an .avi file and prints which video frames are keyframes
59
+ (I-Frames) and which frames are delta frames (P-frames or B-frames). moshy
60
+ cannot tell the difference between a P-frame or a B-frame, so you will want
61
+ to use avidemux or another program if you need to know.
62
+
63
+ Run moshy with mode -m <mode> --help to see options for individual modes.
64
+ "
65
+ end
66
+
67
+ begin
68
+ opts.parse
69
+ rescue OptionParser::InvalidOption, OptionParser::InvalidArgument
70
+ end
71
+
72
+ puts opts
73
+ end
74
+ end
75
+
76
+ # Because we have multiple modes, we do some initial basic arg checking
77
+ # to see if they specified a mode. If not, we show the top-level help menu.
78
+ result = Slop.parse suppress_errors: true do |o|
79
+ o.string '-m', '--mode'
80
+ end
81
+
82
+ puts result
83
+
84
+ mode_classes = {
85
+ "inspect" => Moshy::Inspect,
86
+ "isplit" => Moshy::ISplit,
87
+ "pdupe" => Moshy::PDupe,
88
+ "ppulse" => Moshy::PPulse,
89
+ "prep" => Moshy::Prep,
90
+ "bake" => Moshy::Bake
91
+ }
92
+
93
+ if mode_classes.has_key? result[:m]
94
+ # We need to strip out the "m" otherwise our other arg parsers
95
+ # will choke on the extra parameter
96
+ ARGV.each_with_index do |o, i|
97
+ if o == "-m" || o == "--m"
98
+ ARGV.delete_at(i + 1)
99
+ ARGV.delete_at(i)
100
+ break
101
+ end
102
+ end
103
+
104
+ mode_classes[result[:m]].new.cli ARGV
105
+ else
106
+ Moshy.top_level_help
105
107
  end
data/lib/moshy/bake.rb CHANGED
@@ -1,68 +1,68 @@
1
- module Moshy
2
- class Bake
3
- def cli(args)
4
- opts = Slop::Options.new
5
- opts.separator 'Required Parameters:'
6
- opts.string '-i', '--input', 'Input file path - can be anything that ffmpeg supports.'
7
- opts.string '-o', '--output', 'File output path - should end in .avi.'
8
- opts.separator 'Optional Parameters:'
9
- opts.integer '-b', '--bitrate', 'Bitrate amount (kb/s). Defaults to 4196. Larger number means higher quality, but larger size.'
10
- opts.string '-p', '--pframes', 'Makes sure that there are only P-Frames (no B-Frames). Set this true if you plan to mosh your baked file again. Defaults false.'
11
- opts.integer '-n', '--iframe-interval', 'Ideal interval for I-Frames to be distributed. Set this to a high number (600) if you plan to mosh your baked file again.'
12
-
13
- default = {
14
- :bitrate => 4196
15
- }
16
-
17
- parser = Slop::Parser.new(opts)
18
- slop_options = parser.parse(ARGV)
19
- @options = default.merge(slop_options) { |key, oldval, newval|
20
- if newval.nil?
21
- oldval
22
- else
23
- newval
24
- end
25
- }
26
-
27
- if @options[:pframes] == "false"
28
- @options[:pframes] = false
29
- else
30
- @options[:pframes] = true
31
- end
32
-
33
- # Check mandatory params
34
- mandatory = [:input, :output]
35
- missing = mandatory.select{ |param| @options[param].nil? }
36
- unless missing.empty?
37
- puts "Missing options: #{missing.join(', ')}"
38
- puts slop_options
39
- exit
40
- end
41
-
42
- prep @options[:input], @options[:output], @options[:pframes], @options[:'iframe-interval'], @options[:bitrate]
43
- end
44
-
45
- def prep(file, output, pframes, iframe_interval, bitrate)
46
- ffmpeg = Av::Commands::Ffmpeg.new
47
- ffmpeg.add_source file
48
- ffmpeg.add_destination output
49
-
50
- # Ensures all frames come out as P-frames, B-frames don't
51
- # dupe or mosh properly
52
- if pframes
53
- ffmpeg.add_output_param ['bf', 0]
54
- end
55
-
56
- # Keyframe interval, sets as few I-frames as possible.
57
- # ffmpeg will complain about anything over 600 and cap it.
58
- if iframe_interval
59
- ffmpeg.add_output_param ['g', iframe_interval.to_s]
60
- end
61
-
62
- # Bitrate
63
- ffmpeg.add_output_param ['b:v', bitrate.to_s + 'k']
64
-
65
- ffmpeg.run
66
- end
67
- end
68
- end
1
+ module Moshy
2
+ class Bake
3
+ def cli(args)
4
+ opts = Slop::Options.new
5
+ opts.separator 'Required Parameters:'
6
+ opts.string '-i', '--input', 'Input file path - can be anything that ffmpeg supports.'
7
+ opts.string '-o', '--output', 'File output path - should end in .avi.'
8
+ opts.separator 'Optional Parameters:'
9
+ opts.integer '-b', '--bitrate', 'Bitrate amount (kb/s). Defaults to 4196. Larger number means higher quality, but larger size.'
10
+ opts.string '-p', '--pframes', 'Makes sure that there are only P-Frames (no B-Frames). Set this true if you plan to mosh your baked file again. Defaults false.'
11
+ opts.integer '-n', '--iframe-interval', 'Ideal interval for I-Frames to be distributed. Set this to a high number (600) if you plan to mosh your baked file again.'
12
+
13
+ default = {
14
+ :bitrate => 4196
15
+ }
16
+
17
+ parser = Slop::Parser.new(opts)
18
+ slop_options = parser.parse(ARGV)
19
+ @options = default.merge(slop_options) { |key, oldval, newval|
20
+ if newval.nil?
21
+ oldval
22
+ else
23
+ newval
24
+ end
25
+ }
26
+
27
+ if @options[:pframes] == "false"
28
+ @options[:pframes] = false
29
+ else
30
+ @options[:pframes] = true
31
+ end
32
+
33
+ # Check mandatory params
34
+ mandatory = [:input, :output]
35
+ missing = mandatory.select{ |param| @options[param].nil? }
36
+ unless missing.empty?
37
+ puts "Missing options: #{missing.join(', ')}"
38
+ puts slop_options
39
+ exit
40
+ end
41
+
42
+ prep @options[:input], @options[:output], @options[:pframes], @options[:'iframe-interval'], @options[:bitrate]
43
+ end
44
+
45
+ def prep(file, output, pframes, iframe_interval, bitrate)
46
+ ffmpeg = Av::Commands::Ffmpeg.new
47
+ ffmpeg.add_source file
48
+ ffmpeg.add_destination output
49
+
50
+ # Ensures all frames come out as P-frames, B-frames don't
51
+ # dupe or mosh properly
52
+ if pframes
53
+ ffmpeg.add_output_param ['bf', 0]
54
+ end
55
+
56
+ # Keyframe interval, sets as few I-frames as possible.
57
+ # ffmpeg will complain about anything over 600 and cap it.
58
+ if iframe_interval
59
+ ffmpeg.add_output_param ['g', iframe_interval.to_s]
60
+ end
61
+
62
+ # Bitrate
63
+ ffmpeg.add_output_param ['b:v', bitrate.to_s + 'k']
64
+
65
+ ffmpeg.run
66
+ end
67
+ end
68
+ end