-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new filters and cut / concat API
- Loading branch information
1 parent
e64bc1c
commit a27becd
Showing
13 changed files
with
353 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module FFMPEG | ||
module Filters | ||
# The Filter module is the base "interface" for all filters. | ||
module Filter | ||
def to_s | ||
raise NotImplementedError | ||
end | ||
|
||
def to_a | ||
raise NotImplementedError | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module FFMPEG | ||
module Filters | ||
# The Grayscale class uses the format filter | ||
# to convert a multimedia file to grayscale. | ||
class Grayscale | ||
include Filter | ||
|
||
def to_s | ||
'format=gray' | ||
end | ||
|
||
def to_a | ||
['-vf', to_s] | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module FFMPEG | ||
module Filters | ||
# The SilenceDetect class is uses the silencedetect filter | ||
# to detect silent parts in a multimedia file. | ||
class SilenceDetect | ||
Range = Struct.new(:start, :end, :duration) | ||
|
||
include Filter | ||
|
||
attr_reader :threshold, :duration, :mono | ||
|
||
def initialize(threshold: nil, duration: nil, mono: false) | ||
if !threshold.nil? && !threshold.is_a?(Numeric) && !threshold.is_a?(String) | ||
raise ArgumentError, 'Unknown threshold format, should be either Numeric or String' | ||
end | ||
|
||
raise ArgumentError, 'Unknown duration format, should be Numeric' if !duration.nil? && !duration.is_a?(Numeric) | ||
|
||
@threshold = threshold | ||
@duration = duration | ||
@mono = mono | ||
end | ||
|
||
def self.scan(output) | ||
result = [] | ||
|
||
output.scan(/silence_end: (\d+\.\d+) \| silence_duration: (\d+\.\d+)/) do | ||
e = Regexp.last_match(1).to_f | ||
d = Regexp.last_match(2).to_f | ||
result << Range.new(e - d, e, d) | ||
end | ||
|
||
result | ||
end | ||
|
||
def to_s | ||
args = [] | ||
args << "n=#{@threshold}" if @threshold | ||
args << "d=#{@duration}" if @duration | ||
args << 'm=true' if @mono | ||
args.empty? ? 'silencedetect' : "silencedetect=#{args.join(':')}" | ||
end | ||
|
||
def to_a | ||
['-af', to_s] | ||
end | ||
|
||
def scan(output) | ||
self.class.scan(output) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module FFMPEG | ||
VERSION = '4.1.0' | ||
VERSION = '4.2.0' | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../spec_helper' | ||
|
||
module FFMPEG | ||
module Filters | ||
describe Grayscale do | ||
subject { described_class.new } | ||
|
||
describe '#to_s' do | ||
it 'returns the filter as a string' do | ||
expect(subject.to_s).to eq('format=gray') | ||
end | ||
end | ||
|
||
describe '#to_a' do | ||
it 'returns the filter as an array' do | ||
expect(subject.to_a).to eq(['-vf', subject.to_s]) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.