Skip to content

Commit fef25db

Browse files
authored
Merge pull request #28 from mutablelogic/ffmpeg61
Mostly fixed resampling
2 parents 7ea948e + 7128226 commit fef25db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1768
-743
lines changed

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,22 @@ docker-push: docker-dep
4343
test: go-dep
4444
@echo Test
4545
@${GO} mod tidy
46+
@echo ... test sys/ffmpeg61
4647
@${GO} test ./sys/ffmpeg61
48+
@echo ... test pkg/ffmpeg
49+
@${GO} test -v ./pkg/ffmpeg
50+
@echo ... test sys/chromaprint
4751
@${GO} test ./sys/chromaprint
52+
@echo ... test pkg/chromaprint
53+
@${GO} test ./pkg/chromaprint
54+
@echo ... test pkg/file
55+
@${GO} test ./pkg/file
56+
@echo ... test pkg/generator
57+
@${GO} test ./pkg/generator
58+
@echo ... test pkg/image
59+
@${GO} test ./pkg/image
60+
@echo ... test pkg
4861
@${GO} test ./pkg/...
49-
@${GO} test .
5062

5163
container-test: go-dep
5264
@echo Test
@@ -56,8 +68,6 @@ container-test: go-dep
5668
@${GO} test --tags=container ./pkg/...
5769
@${GO} test --tags=container .
5870

59-
60-
6171
cli: go-dep mkdir
6272
@echo Build media tool
6373
@${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR}/media ./cmd/cli

README.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func main() {
104104
}
105105
```
106106

107-
### Decoding - Video Frames
107+
### Decoding - Video
108108

109109
This example shows you how to decode video frames from a media file into images.
110110

@@ -156,9 +156,75 @@ func main() {
156156
}
157157
```
158158

159-
### Encoding
159+
### Encoding - Audio and Video
160160

161-
TODO
161+
This example shows you how to encode video and audio frames into a media file.
162+
163+
```go
164+
package main
165+
166+
import (
167+
"io"
168+
"log"
169+
"os"
170+
"time"
171+
172+
media "github.com/mutablelogic/go-media"
173+
ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg"
174+
generator "github.com/mutablelogic/go-media/pkg/generator"
175+
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
176+
)
177+
178+
func main() {
179+
// Create a new file with an audio and video stream
180+
// 30fps and 22050Hz mono audio
181+
file, err := ffmpeg.Create(os.Args[1],
182+
ffmpeg.OptStream(1, ffmpeg.VideoPar("yuv420p", "640x480", 30)),
183+
ffmpeg.OptStream(2, ffmpeg.AudioPar("fltp", "mono", 22050)),
184+
)
185+
if err != nil {
186+
log.Fatal(err)
187+
}
188+
defer file.Close()
189+
190+
// Make an video generator which can generate YUV420P frames
191+
// with the same parameters as the video stream
192+
video, err := generator.NewYUV420P(file.Stream(1).Par())
193+
if err != nil {
194+
log.Fatal(err)
195+
}
196+
defer video.Close()
197+
198+
// Make an audio generator which can generate a 440Hz tone
199+
// at -5dB with the same parameters as the audio stream
200+
audio, err := generator.NewSine(440, -5, file.Stream(2).Par())
201+
if err != nil {
202+
log.Fatal(err)
203+
}
204+
defer audio.Close()
205+
206+
// Write 1 min of frames, passing video and audio frames to the encoder
207+
// and returning io.EOF when the duration is reached
208+
duration := time.Minute
209+
if err := file.Encode(func(stream int) (*ff.AVFrame, error) {
210+
var frame media.Frame
211+
switch stream {
212+
case 1:
213+
frame = video.Frame()
214+
case 2:
215+
frame = audio.Frame()
216+
}
217+
if frame.Time() >= duration {
218+
return nil, io.EOF
219+
} else {
220+
log.Println("Frame", stream, "=>", frame.Time().Truncate(time.Millisecond))
221+
return frame.(*ffmpeg.Frame).AVFrame(), nil
222+
}
223+
}, nil); err != nil {
224+
log.Fatal(err)
225+
}
226+
}
227+
```
162228

163229
### Multiplexing
164230

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)