-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathffmpeg.go
328 lines (281 loc) · 7.63 KB
/
ffmpeg.go
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package gompeg
import (
"fmt"
"strconv"
"strings"
)
type Media struct {
inputPath string
aspect string
resolution string
videoBitRate int
videoBitRateTolerance int
videoMaxBitrate int
videoMinBitrate int
videoCodec string
vFrames int
frameRate int
audioRate int
maxKeyframe int
minKeyframe int
keyframeInterval int
audioCodec string
audioBitrate int
audioChannels int
bufferSize int
preset string
quality int
outputFormat string
nativeFramerateInput bool
pixelFormat string
outputPath string
//threads int
//tune string
//audioProfile string
//videoProfile string
//target string
//duration string
//durationInput string
//seekTime string
//strict int
//muxDelay string
//seekUsingTsInput bool
//seekTimeInput string
//hideBanner bool
//copyTs bool
//inputInitialOffset string
//rtmpLive string
//hlsPlaylistType string
//hlsListSize int
//hlsSegmentDuration int
//httpMethod string
//httpKeepAlive bool
//streamIds map[int]string
//filter string
//skipVideo bool
//skipAudio bool
}
////////////////////////////////////////////////////////
/////////////////////Getters///////////////////////////
//////////////////////////////////////////////////////
//video aspect ratio like "4:3" , "16:9"
//aspect ratio describe image width and height relationship
func (m *Media) SetAspect(v string) {
m.aspect = v
}
//set resolution ex: "100x100"
func (m *Media) SetResolution(v string) {
m.resolution = v
}
//number of bits can processed in a unit of time
func (m *Media) SetVideoBitRate(v int) {
m.videoBitRate = v
}
func (m *Media) SetVideoMaxBitrate(v int) {
m.videoMaxBitrate = v
}
func (m *Media) SetVideoMinBitrate(v int) {
m.videoMinBitrate = v
}
func (m *Media) SetVideoBitRateTolerance(v int) {
m.videoBitRateTolerance = v
}
//for compress and decompress videos, it convert decompress video to compress video
func (m *Media) SetVideoCodec(v string) {
m.videoCodec = v
}
//number of video frames to output
//frame are number of sequence pictures that published in a second
//ex : for example 24 FPS is 24 picture in a second
func (m *Media) SetVFrames(v int) {
m.vFrames = v
}
func (m *Media) SetFrameRate(v int) {
m.frameRate = v
}
func (m *Media) SetAudioRate(v int) {
m.audioRate = v
}
func (m *Media) SetAudioBitRate(v int) {
m.audioRate = v
}
func (m *Media) SetMaxKeyframe(v int) {
m.maxKeyframe = v
}
func (m *Media) SetNativeFramerateInput(v bool) {
m.nativeFramerateInput = v
}
func (m *Media) SetInputPath(v string) {
m.inputPath = v
}
func (m *Media) SetPreset(v string) {
m.preset = v
}
func (m *Media) SetBufferSize(v int) {
m.bufferSize = v
}
//Videos, images and other visual media contain a value called Pixel Format.
// It describes the layout of each and every pixel in the image data of a picture or video. ...
// Usually, the value given for the Pixel Format in a file includes the bits per pixel (bpp) and the color channel or model.
func (m *Media) SetPixelFormat(v string) {
m.pixelFormat = v
}
//The shorter the Interval, the better chance you have of video being of better quality.
// This is a very subjective subject for many reasons. These cameras use compression.
// Basically, a "Key Frame" is an entire and complete and total image,
// that is used as a reference for other frames ("images") that the camera generates.
func (m *Media) SetKeyframeInterval(v int) {
m.keyframeInterval = v
}
func (m *Media) SetAudioCodec(v string) {
m.audioCodec = v
}
//Sound Channel refers to the independent audio signal which is collected or playback when the sound is recording or playback in different spatial position.
// Therefore, the number of channel is the amount of sound source when the sound is recording or the relevant speaker number when it is playback.
func (m *Media) SetAudioChannels(v int) {
m.audioChannels = v
}
func (m *Media) SetOutputFormat(v string) {
m.outputFormat = v
}
func (m *Media) SetQuality(v int) {
m.quality = v
}
func (m *Media) SetOutputPath(v string) {
m.outputPath = v
}
////////////////////////////////////////////////////////
/////////////////////Getters///////////////////////////
//////////////////////////////////////////////////////
func (m *Media) Aspect() []string {
if m.resolution != "" {
resolution := strings.Split(m.resolution, "x")
if len(resolution) != 0 {
width, _ := strconv.ParseFloat(resolution[0], 64)
height, _ := strconv.ParseFloat(resolution[1], 64)
return []string{"-aspect", fmt.Sprintf("%f", width/height)}
}
}
if m.aspect != "" {
return []string{"-aspect", m.aspect}
}
return nil
}
func (m *Media) VideoBitRate() []string {
if m.videoBitRate != 0 {
return []string{"-b:v", fmt.Sprintf("%d", m.videoBitRate)}
}
return nil
}
func (m *Media) VideoMaxBitRate() []string {
if m.videoMaxBitrate != 0 {
return []string{"-maxrate", fmt.Sprintf("%dk", m.videoMaxBitrate)}
}
return nil
}
func (m *Media) VideoMinBitRate() []string {
if m.videoMinBitrate != 0 {
return []string{"-minrate", fmt.Sprintf("%dk", m.videoMinBitrate)}
}
return nil
}
func (m *Media) VideoBitRateTolerance() []string {
if m.videoBitRateTolerance != 0 {
return []string{"-bt", fmt.Sprintf("%dk", m.videoBitRateTolerance)}
}
return nil
}
func (m *Media) VideoCodec() []string {
if m.videoCodec != "" {
return []string{"-c:v", m.videoCodec}
}
return nil
}
func (m *Media) VFrames() []string {
if m.vFrames != 0 {
return []string{"-frames:v", fmt.Sprintf("%d", m.vFrames)}
}
return nil
}
func (m *Media) FrameRate() []string {
if m.frameRate != 0 {
return []string{"-r", fmt.Sprintf("%d", m.frameRate)}
}
return nil
}
func (m *Media) AudioRate() []string {
if m.audioRate != 0 {
return []string{"-ar", fmt.Sprintf("%d", m.audioRate)}
}
return nil
}
func (m *Media) AudioBitrate() []string {
if m.audioRate != 0 {
return []string{"-b:a", fmt.Sprintf("%d", m.audioRate)}
}
return nil
}
func (m *Media) InputPath() []string {
if m.inputPath != "" {
if m.nativeFramerateInput {
return []string{"-re", "-i", m.inputPath}
} else {
return []string{"-i", m.inputPath}
}
}
return nil
}
func (m *Media) Preset() []string {
if m.preset != "" {
return []string{"-preset", m.preset}
}
return nil
}
func (m *Media) BufferSize() []string {
if m.bufferSize != 0 {
return []string{"-bufsize", fmt.Sprintf("%dk", m.bufferSize)}
}
return nil
}
func (m *Media) PixelFormat() []string {
if m.pixelFormat != "" {
return []string{"-pix_fmt", m.pixelFormat}
}
return nil
}
func (m *Media) KeyFrameInterval() []string {
if m.keyframeInterval != 0 {
return []string{"-g", fmt.Sprintf("%d", m.keyframeInterval)}
}
return nil
}
func (m *Media) AudioCodec() []string {
if m.audioCodec != "" {
return []string{"-c:a", m.audioCodec}
}
return nil
}
func (m *Media) AudioChannels() []string {
if m.audioChannels != 0 {
return []string{"-ac", fmt.Sprintf("%d", m.audioChannels)}
}
return nil
}
func (m *Media) OutputFormat() []string {
if m.outputFormat != "" {
return []string{"-f", m.outputFormat}
}
return nil
}
func (m *Media) Quality() []string {
if m.quality != 0 {
return []string{"-crf", fmt.Sprintf("%d", m.quality)}
}
return nil
}
func (m *Media) OutputPath() []string {
if m.outputPath != "" {
return []string{m.outputPath}
}
return nil
}