ffsplitter 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9544a8a00210da89af516422706274002610c6eb
4
- data.tar.gz: 4d0f063c8deb2fd37ca5c697743a644f073626ea
3
+ metadata.gz: 06995073fdeefca7864c22bde674d1e8875dc8f9
4
+ data.tar.gz: 183886a0825bcf850fb4507a691fa9466c742bf6
5
5
  SHA512:
6
- metadata.gz: cbb8063f2907f1e776e7f95c09685e73f96642e216adb7a0247e964546fff7bc9e935e565d0795fc6e3c6bdfde7e10afa56db95eae197105eb947df8304d2cb1
7
- data.tar.gz: a0192b0d962f4ae8aee208dacf7a719db6b2852d8ae870858164ea431775abad24ac2d98398493f60eeedb2d000bb3a352dd8157ab89a919f09c87820597f119
6
+ metadata.gz: 8e4da0bc89ff46aafe84820de193c9b778a82c89d2a2959ee7b31e45d20cef6170e8506a62d9236b1a598c2bd57b5701065e67dbc22f19fab5c7c5c836eb9a70
7
+ data.tar.gz: f07368ae40a95c886faa05f4283725b71d0518b36eb02da939383ab761f2b1ec4d87c39252372050a05823fd6d6c286a56658e30d293a68529313f87dcc5fd73
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # FFSplitter
2
2
 
3
- TODO: Write a gem description
4
-
5
3
  ## Installation
6
4
 
5
+ brew install ffmpeg
7
6
  gem install ffsplitter
8
7
 
9
8
  ## Usage
@@ -1,26 +1,25 @@
1
1
  module FFSplitter
2
2
  class FFMpeg
3
- attr_accessor :filename, :runner
3
+ attr_accessor :filename, :output_directory, :runner
4
4
 
5
- def initialize(filename)
6
- self.filename = filename
7
- self.runner = CommandRunner
5
+ def initialize(filename, output_directory=nil)
6
+ @filename = filename
7
+ @output_directory = output_directory
8
+ @runner = CommandRunner
8
9
  end
9
10
 
10
11
  def encode(chapters)
11
- chapters.each do |chapter|
12
- runner.run(chapter_command(chapter))
13
- end
12
+ commands = chapters.collect { |c| chapter_command(c) }
13
+ runner.run("ffmpeg #{commands.join(" ")}")
14
14
  end
15
15
 
16
16
  def read_metadata
17
- runner.run("ffmpeg -i #{filename} -v quiet -f ffmetadata -")
17
+ runner.run("ffmpeg -i '#{filename}' -v quiet -f ffmetadata -")
18
18
  end
19
19
 
20
- private
21
-
22
20
  def chapter_command(chapter)
23
- "ffmpeg -ss #{chapter.start_time} -i #{filename} -to #{chapter.end_time} -c copy '#{chapter.filename}.mp4'"
21
+ output_file = File.expand_path(chapter.filename, output_directory)
22
+ "-i '#{filename}' -ss #{chapter.start_time} -to #{chapter.end_time} -c copy -v error '#{output_file}.mp4'"
24
23
  end
25
24
  end
26
25
  end
@@ -1,7 +1,7 @@
1
1
  module FFSplitter
2
2
  class Splitter
3
- def self.split_via_ffmpeg(filename)
4
- split(FFMpeg.new(filename))
3
+ def self.split_via_ffmpeg(filename, output_directory)
4
+ split(FFMpeg.new(filename, output_directory))
5
5
  end
6
6
 
7
7
  def self.split(codec)
@@ -1,3 +1,3 @@
1
1
  module FFSplitter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/ffsplitter.rb CHANGED
@@ -20,7 +20,7 @@ module FFSplitter
20
20
  puts "WTF mate?"
21
21
  exit(1)
22
22
  else
23
- Splitter.split_via_ffmpeg(@argv[0])
23
+ Splitter.split_via_ffmpeg(@argv[0], @argv[1])
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module FFSplitter
4
+ describe "End to end" do
5
+ before { Dir.mkdir("tmp") unless Dir.exist?("tmp") }
6
+
7
+ describe "split" do
8
+ before { `bundle exec ruby -Ilib bin/ffsplitter 'spec/fixtures/test video.mp4' tmp` }
9
+ let(:file_list) { Dir.glob("tmp/*") }
10
+ it "creates files" do
11
+ expect(file_list).to include("tmp/01 Chapter 1.mp4")
12
+ expect(file_list).to include("tmp/02 - Chapter 2.mp4")
13
+ expect(file_list).to include("tmp/03 Chapter 3.mp4")
14
+ end
15
+ end
16
+
17
+ after { FileUtils.rm(file_list) }
18
+ end
19
+ end
data/spec/ffmpeg_spec.rb CHANGED
@@ -2,23 +2,65 @@ require 'spec_helper'
2
2
 
3
3
  module FFSplitter
4
4
  describe FFMpeg do
5
- let(:ffmpeg){ FFMpeg.new("test.mp4") }
5
+ let(:filename) { "test.mp4" }
6
+ let(:output_directory) { nil }
7
+ let(:ffmpeg){ FFMpeg.new(filename, output_directory) }
6
8
  let(:runner) { double("runner") }
7
9
  before { ffmpeg.runner = runner }
8
10
 
9
11
  describe "#encode" do
10
12
  let(:chapter_list) { ChapterList.new }
11
- let(:chapter) { Chapter.new(start_frames: 10, end_frames: 20, timebase: 1, title: "title") }
12
- before { chapter_list.add(chapter) }
13
- it "encodes the chapters" do
14
- expect(runner).to receive(:run).with "ffmpeg -ss 10.0 -i test.mp4 -to 20.0 -c copy '01 title.mp4'"
15
- ffmpeg.encode(chapter_list)
13
+ let(:chapter1) { Chapter.new(title: "Chapter 1") }
14
+ let(:chapter2) { Chapter.new(title: "Chapter 2") }
15
+
16
+ context "with a single chapter" do
17
+ before { chapter_list.add(chapter1) }
18
+ it "encodes the chapter" do
19
+ expect(runner).to receive(:run).with("ffmpeg #{ffmpeg.chapter_command(chapter1)}")
20
+ ffmpeg.encode(chapter_list)
21
+ end
22
+ end
23
+
24
+ context "with multiple chapters" do
25
+ before do
26
+ chapter_list.add(chapter1)
27
+ chapter_list.add(chapter2)
28
+ end
29
+ it "encodes the chapters with a single ffmpeg command" do
30
+ commands = "#{ffmpeg.chapter_command(chapter1)} #{ffmpeg.chapter_command(chapter2)}"
31
+ expect(runner).to receive(:run).once.with("ffmpeg #{commands}")
32
+ ffmpeg.encode(chapter_list)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#chapter_command" do
38
+ let(:command) { ffmpeg.chapter_command(chapter) }
39
+ let(:chapter) { Chapter.new(start_frames: 10, end_frames: 20, timebase: 1, title: "test title") }
40
+
41
+ context "without an output directory" do
42
+ let(:output_directory) { nil }
43
+ it "creates a chapter command" do
44
+ expect(command).to match("-i 'test.mp4'")
45
+ expect(command).to match("-ss 10.0")
46
+ expect(command).to match("-to 20.0")
47
+ expect(command).to match("-c copy")
48
+ expect(command).to match("-v error")
49
+ expect(command).to match("#{File.expand_path(chapter.filename)}")
50
+ end
51
+ end
52
+
53
+ context "with an output directory" do
54
+ let(:output_directory) { "test_dir" }
55
+ it "creates returns the path to that directory" do
56
+ expect(command).to match("#{File.expand_path(chapter.filename, "test_dir")}")
57
+ end
16
58
  end
17
59
  end
18
60
 
19
61
  describe "#read_metadata" do
20
62
  it "reads the metadata" do
21
- expect(runner).to receive(:run).with("ffmpeg -i test.mp4 -v quiet -f ffmetadata -")
63
+ expect(runner).to receive(:run).with("ffmpeg -i 'test.mp4' -v quiet -f ffmetadata -")
22
64
  ffmpeg.read_metadata
23
65
  end
24
66
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffsplitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rockwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-12 00:00:00.000000000 Z
11
+ date: 2013-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -89,8 +89,10 @@ files:
89
89
  - lib/ffsplitter/splitter.rb
90
90
  - lib/ffsplitter/version.rb
91
91
  - spec/chapter_spec.rb
92
+ - spec/end_to_end_spec.rb
92
93
  - spec/ffmpeg_spec.rb
93
94
  - spec/fixtures/metadata_fixtures.rb
95
+ - spec/fixtures/test video.mp4
94
96
  - spec/metadata_parser_spec.rb
95
97
  - spec/spec_helper.rb
96
98
  - spec/splitter_spec.rb
@@ -120,8 +122,10 @@ specification_version: 4
120
122
  summary: ffsplitter will split a video file by its chapters
121
123
  test_files:
122
124
  - spec/chapter_spec.rb
125
+ - spec/end_to_end_spec.rb
123
126
  - spec/ffmpeg_spec.rb
124
127
  - spec/fixtures/metadata_fixtures.rb
128
+ - spec/fixtures/test video.mp4
125
129
  - spec/metadata_parser_spec.rb
126
130
  - spec/spec_helper.rb
127
131
  - spec/splitter_spec.rb