-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaac.rb
More file actions
120 lines (111 loc) · 3.08 KB
/
aac.rb
File metadata and controls
120 lines (111 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# frozen_string_literal: true
require_relative '../preset'
module FFMPEG
# rubocop:disable Style/Documentation
module Presets
# rubocop:enable Style/Documentation
class << self
def aac_128k(
name: 'AAC 128k',
filename: '%<basename>s.m4a',
metadata: nil,
threads: FFMPEG.threads,
audio_sample_rate: 48_000,
audio_channels: 2,
&
)
AAC.new(
name:,
filename:,
metadata:,
threads:,
audio_sample_rate:,
audio_channels:,
audio_bit_rate: '128k',
&
)
end
def aac_192k(
name: 'AAC 192k',
filename: '%<basename>s.m4a',
metadata: nil,
threads: FFMPEG.threads,
audio_sample_rate: 48_000,
audio_channels: 2,
&
)
AAC.new(
name:,
filename:,
metadata:,
threads:,
audio_sample_rate:,
audio_channels:,
audio_bit_rate: '192k',
&
)
end
def aac_320k(
name: 'AAC 320k',
filename: '%<basename>s.m4a',
metadata: nil,
threads: FFMPEG.threads,
audio_sample_rate: 48_000,
audio_channels: 2,
&
)
AAC.new(
name:,
filename:,
metadata:,
threads:,
audio_sample_rate:,
audio_channels:,
audio_bit_rate: '320k',
&
)
end
end
# Preset to encode AAC audio files.
class AAC < Preset
attr_reader :threads, :audio_bit_rate, :audio_sample_rate, :audio_channels
# @param name [String] The name of the preset.
# @param filename [String] The filename format of the output.
# @param metadata [Object] The metadata to associate with the preset.
# @param audio_bit_rate [String] The audio bit rate to use.
# @param audio_sample_rate [Integer] The audio sample rate to use.
# @param audio_channels [Integer, nil] The number of audio channels to use (nil to preserve source).
# @yield The block to execute to compose the command arguments.
def initialize(
name: nil,
filename: nil,
metadata: nil,
threads: FFMPEG.threads,
audio_bit_rate: '128k',
audio_sample_rate: 48_000,
audio_channels: 2,
&
)
@threads = threads
@audio_bit_rate = audio_bit_rate
@audio_sample_rate = audio_sample_rate
@audio_channels = audio_channels
preset = self
super(name:, filename:, metadata:) do
threads preset.threads if preset.threads
format_name 'mp4'
brand 'M4A '
muxing_flags '+faststart'
map_chapters '-1'
audio_codec_name 'aac'
instance_exec(&) if block_given?
map media.audio_mapping_id do
audio_bit_rate preset.audio_bit_rate
audio_sample_rate preset.audio_sample_rate
audio_channels preset.audio_channels if preset.audio_channels
end
end
end
end
end
end