stack-encode 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -0
- data/lib/stack-encode/cli.rb +62 -14
- data/lib/stack-encode/profile.rb +51 -0
- data/lib/stack-encode/version.rb +1 -1
- data/lib/stack-encode.rb +1 -0
- data/test/profile.yml +15 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b424112450f9f17120772daec636dacc1e167dc
|
4
|
+
data.tar.gz: 74736aa088b738e4f9035abef8eae0706f790123
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0257cb3bebd3ea1508bdabe5ba9816da0a3bc0b54cf3e5380c782cee697142cade2f132aeb92e06355dcdd1abf51001078937ba43e2a42bc8cea1f1e1ac645ca
|
7
|
+
data.tar.gz: 2c52be8cf08ee68f0556c25e575f8e32e2a7d51f85dc4c12b2fc801adada2270879413f43a8e1e59a5798d7d1ddd6aec5d8340bcd8c47eab68139797dce4f8a0
|
data/README.md
CHANGED
@@ -31,6 +31,41 @@ Encoding 2011-05-31_0053_loaud4.mp2 to MP3: [#################################]
|
|
31
31
|
Encoding 2014-05-26_0010_lo.mp4 to MP4: [#################################] 100%
|
32
32
|
```
|
33
33
|
|
34
|
+
## Profiles
|
35
|
+
|
36
|
+
Stack Encode supports ffmpeg setting profiles in the form of YAML files.
|
37
|
+
There are 3 different hashes for the following settings:
|
38
|
+
|
39
|
+
- video settings - used for transcoding video files
|
40
|
+
- audio settings - used for transcoding audio files
|
41
|
+
- transcoder settings - general transcoder settings
|
42
|
+
|
43
|
+
This is an example profile file for stack-encode (my_profile.yml):
|
44
|
+
|
45
|
+
```YAML
|
46
|
+
---
|
47
|
+
video:
|
48
|
+
resolution: 320x480
|
49
|
+
frame_rate: 10
|
50
|
+
x264_vprofile: high
|
51
|
+
x264_preset: slow
|
52
|
+
audio_codec: libfaac
|
53
|
+
custom: -movflags +faststart
|
54
|
+
|
55
|
+
audio:
|
56
|
+
audio_channels: 1
|
57
|
+
custom: -ab 48k
|
58
|
+
|
59
|
+
transcoder:
|
60
|
+
preserve_aspect_ratio: :width
|
61
|
+
```
|
62
|
+
You can use the profile from above like this:
|
63
|
+
|
64
|
+
```bash
|
65
|
+
$ stack-encode encode --profile my_profile.yml audio_file.wma
|
66
|
+
```
|
67
|
+
|
68
|
+
|
34
69
|
## Contributing
|
35
70
|
|
36
71
|
1. Fork it
|
data/lib/stack-encode/cli.rb
CHANGED
@@ -29,11 +29,11 @@ module StackEncode
|
|
29
29
|
desc: "destination directory",
|
30
30
|
aliases: '-d'
|
31
31
|
option :video_format,
|
32
|
-
desc: "video format",
|
32
|
+
desc: "destination video format",
|
33
33
|
aliases: '-v',
|
34
34
|
default: 'mp4'
|
35
35
|
option :audio_format,
|
36
|
-
desc: "audio format",
|
36
|
+
desc: "destination audio format",
|
37
37
|
aliases: '-a',
|
38
38
|
default: 'mp3'
|
39
39
|
option :log_file,
|
@@ -44,35 +44,83 @@ module StackEncode
|
|
44
44
|
desc: "show encoding progress",
|
45
45
|
type: :boolean,
|
46
46
|
default: true
|
47
|
+
option :profile,
|
48
|
+
desc: "path to profile file (YAML)",
|
49
|
+
aliases: '-p',
|
50
|
+
default: ENV['STACKENCODE_PROFILE'] || nil
|
47
51
|
option :ffmpeg_options,
|
48
|
-
desc: "custom ffmpeg options",
|
52
|
+
desc: "custom ffmpeg options string",
|
49
53
|
aliases: '-o',
|
50
|
-
default: ENV['FFMPEG_OPTIONS'] ||
|
54
|
+
default: ENV['FFMPEG_OPTIONS'] || ""
|
51
55
|
def encode(*files)
|
52
56
|
FFMPEG.logger = Logger.new(options[:log_file])
|
57
|
+
profile = Profile.new(
|
58
|
+
profile_path: options[:profile],
|
59
|
+
custom_options: options[:ffmpeg_options]
|
60
|
+
)
|
53
61
|
files.each do |source|
|
54
62
|
unless File.file?(source)
|
55
63
|
puts "#{source} is not a valid file"
|
56
64
|
next
|
57
65
|
end
|
58
|
-
|
59
|
-
dest_format =
|
66
|
+
file = FFMPEG::Movie.new(source)
|
67
|
+
dest_format = file.video_stream ? options[:video_format] : options[:audio_format]
|
60
68
|
dest_dir = options[:destination] || File.dirname(source)
|
61
69
|
filename = File.basename(source, File.extname(source)) + ".#{dest_format}"
|
62
70
|
banner = "Encoding #{File.basename(source)} to #{dest_format.upcase} ==> #{filename}"
|
63
|
-
|
64
|
-
|
65
|
-
File.expand_path(
|
66
|
-
|
67
|
-
|
68
|
-
options[:ffmpeg_options]
|
71
|
+
say banner unless options[:progress]
|
72
|
+
transcoded_file = file.transcode(
|
73
|
+
File.expand_path(File.join(dest_dir, filename)),
|
74
|
+
file.video_stream ? profile.video_options : profile.audio_options,
|
75
|
+
profile.transcoder_options
|
69
76
|
) do |progress|
|
70
77
|
if options[:progress]
|
71
78
|
print_progress(progress * 100, banner)
|
72
79
|
end
|
73
80
|
end
|
74
|
-
|
75
|
-
|
81
|
+
say if options[:progress]
|
82
|
+
transcoded_file
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "info FILES", "Print information for a number video or audio files"
|
87
|
+
def info(*files)
|
88
|
+
files.each do |source|
|
89
|
+
unless File.file?(source)
|
90
|
+
puts "#{source} is not a valid file"
|
91
|
+
next
|
92
|
+
end
|
93
|
+
file = FFMPEG::Movie.new(source)
|
94
|
+
if file.valid?
|
95
|
+
say source, :green
|
96
|
+
table = [
|
97
|
+
["file type", file.video_stream ? "video" : "audio"],
|
98
|
+
["duration", file.duration.to_s + " sec"],
|
99
|
+
["bitrate", file.bitrate.to_s + " kb/s"],
|
100
|
+
["size", file.size.to_s + " bytes"]
|
101
|
+
]
|
102
|
+
table += if file.video_stream
|
103
|
+
[
|
104
|
+
["video_codec", file.video_codec],
|
105
|
+
["colorspace", file.colorspace],
|
106
|
+
["resolution", file.resolution],
|
107
|
+
["frame_rate", file.frame_rate.to_s + " fps"],
|
108
|
+
["audio_codec", file.audio_codec],
|
109
|
+
["audio_sample_rate", file.audio_sample_rate.to_s],
|
110
|
+
["audio_channels", file.audio_channels.to_s]
|
111
|
+
]
|
112
|
+
else
|
113
|
+
[
|
114
|
+
["audio_codec", file.audio_codec],
|
115
|
+
["audio_sample_rate", file.audio_sample_rate.to_s],
|
116
|
+
["audio_channels", file.audio_channels.to_s]
|
117
|
+
]
|
118
|
+
end
|
119
|
+
print_table table
|
120
|
+
puts
|
121
|
+
else
|
122
|
+
puts "Invalid source file"
|
123
|
+
end
|
76
124
|
end
|
77
125
|
end
|
78
126
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module StackEncode
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class Profile
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@profile_path = options[:profile_path] ? options[:profile_path] : nil
|
8
|
+
@custom_options = options[:custom_options] ? options[:custom_options] : nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def settings
|
12
|
+
@settings ||= if @profile_path
|
13
|
+
begin
|
14
|
+
YAML.load_file @profile_path
|
15
|
+
rescue SystemCallError
|
16
|
+
$stderr.puts "Can't find profile #{@profile_path}."
|
17
|
+
exit 1
|
18
|
+
rescue => e
|
19
|
+
$stderr.puts "Error parsing profile (#{@profile_path}):"
|
20
|
+
$stderr.puts e.message
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
else
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def video_options
|
29
|
+
video_options = settings['video'] ? settings['video'] : {}
|
30
|
+
merge_custom_options(video_options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def audio_options
|
34
|
+
audio_options = settings['audio'] ? settings['audio'] : {}
|
35
|
+
merge_custom_options(audio_options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def transcoder_options
|
39
|
+
@settings['transcoder'] ? @settings['transcoder'] : {}
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def merge_custom_options(options)
|
45
|
+
profile_options = options['custom'] ? options['custom'] : ''
|
46
|
+
options['custom'] = [profile_options, @custom_options].join(' ').strip || ''
|
47
|
+
options
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/lib/stack-encode/version.rb
CHANGED
data/lib/stack-encode.rb
CHANGED
data/test/profile.yml
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stack-encode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nik Wolfgramm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -82,8 +82,10 @@ files:
|
|
82
82
|
- bin/stack-encode
|
83
83
|
- lib/stack-encode.rb
|
84
84
|
- lib/stack-encode/cli.rb
|
85
|
+
- lib/stack-encode/profile.rb
|
85
86
|
- lib/stack-encode/version.rb
|
86
87
|
- stack-encode.gemspec
|
88
|
+
- test/profile.yml
|
87
89
|
homepage: https://github.com/swisstxt/stack-encode
|
88
90
|
licenses:
|
89
91
|
- MIT
|
@@ -108,4 +110,5 @@ rubygems_version: 2.2.2
|
|
108
110
|
signing_key:
|
109
111
|
specification_version: 4
|
110
112
|
summary: stack-encode - automating the encoding process with ffmpeg
|
111
|
-
test_files:
|
113
|
+
test_files:
|
114
|
+
- test/profile.yml
|