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 +4 -4
- data/README.md +1 -2
- data/lib/ffsplitter/ffmpeg.rb +10 -11
- data/lib/ffsplitter/splitter.rb +2 -2
- data/lib/ffsplitter/version.rb +1 -1
- data/lib/ffsplitter.rb +1 -1
- data/spec/end_to_end_spec.rb +19 -0
- data/spec/ffmpeg_spec.rb +49 -7
- data/spec/fixtures/test video.mp4 +0 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06995073fdeefca7864c22bde674d1e8875dc8f9
|
4
|
+
data.tar.gz: 183886a0825bcf850fb4507a691fa9466c742bf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e4da0bc89ff46aafe84820de193c9b778a82c89d2a2959ee7b31e45d20cef6170e8506a62d9236b1a598c2bd57b5701065e67dbc22f19fab5c7c5c836eb9a70
|
7
|
+
data.tar.gz: f07368ae40a95c886faa05f4283725b71d0518b36eb02da939383ab761f2b1ec4d87c39252372050a05823fd6d6c286a56658e30d293a68529313f87dcc5fd73
|
data/README.md
CHANGED
data/lib/ffsplitter/ffmpeg.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
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.
|
12
|
-
|
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
|
-
|
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
|
data/lib/ffsplitter/splitter.rb
CHANGED
data/lib/ffsplitter/version.rb
CHANGED
data/lib/ffsplitter.rb
CHANGED
@@ -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(:
|
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(:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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.
|
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-
|
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
|