Skip to content

Commit 7183adf

Browse files
committed
Added EBU generator test card
1 parent 25ee9bd commit 7183adf

27 files changed

+619
-124
lines changed

README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,68 +159,67 @@ func main() {
159159
### Encoding - Audio and Video
160160

161161
This example shows you how to encode video and audio frames into a media file.
162+
It creates a testcard signal overlayed with a timestamp, and a 1KHz tone at -5dB
162163

163164
```go
164165
package main
165166

166167
import (
168+
"fmt"
167169
"io"
168170
"log"
169171
"os"
170-
"time"
171172

172-
media "github.com/mutablelogic/go-media"
173+
// Packages
173174
ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg"
174175
generator "github.com/mutablelogic/go-media/pkg/generator"
175-
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
176176
)
177177

178+
// This example encodes an audio an video stream to a file
178179
func main() {
179180
// Create a new file with an audio and video stream
180-
// 30fps and 22050Hz mono audio
181181
file, err := ffmpeg.Create(os.Args[1],
182-
ffmpeg.OptStream(1, ffmpeg.VideoPar("yuv420p", "640x480", 30)),
182+
ffmpeg.OptStream(1, ffmpeg.VideoPar("yuv420p", "1024x720", 30)),
183183
ffmpeg.OptStream(2, ffmpeg.AudioPar("fltp", "mono", 22050)),
184184
)
185185
if err != nil {
186186
log.Fatal(err)
187187
}
188188
defer file.Close()
189189

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())
190+
// Make an video generator which can generate frames with the same
191+
// parameters as the video stream
192+
video, err := generator.NewEBU(file.Stream(1).Par())
193193
if err != nil {
194194
log.Fatal(err)
195195
}
196196
defer video.Close()
197197

198-
// Make an audio generator which can generate a 440Hz tone
198+
// Make an audio generator which can generate a 1KHz tone
199199
// at -5dB with the same parameters as the audio stream
200-
audio, err := generator.NewSine(440, -5, file.Stream(2).Par())
200+
audio, err := generator.NewSine(1000, -5, file.Stream(2).Par())
201201
if err != nil {
202202
log.Fatal(err)
203203
}
204204
defer audio.Close()
205205

206-
// Write 1 min of frames, passing video and audio frames to the encoder
206+
// Write 90 seconds, passing video and audio frames to the encoder
207207
// 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
208+
duration := float64(90)
209+
err = file.Encode(func(stream int) (*ffmpeg.Frame, error) {
210+
var frame *ffmpeg.Frame
211211
switch stream {
212212
case 1:
213213
frame = video.Frame()
214214
case 2:
215215
frame = audio.Frame()
216216
}
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
217+
if frame != nil && frame.Ts() < duration {
218+
return frame, nil
222219
}
223-
}, nil); err != nil {
220+
return nil, io.EOF
221+
}, nil)
222+
if err != nil {
224223
log.Fatal(err)
225224
}
226225
}

cmd/examples/encode/main.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,63 @@
11
package main
22

33
import (
4+
"fmt"
45
"io"
56
"log"
67
"os"
7-
"time"
88

9-
media "github.com/mutablelogic/go-media"
9+
// Packages
1010
ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg"
1111
generator "github.com/mutablelogic/go-media/pkg/generator"
12-
ff "github.com/mutablelogic/go-media/sys/ffmpeg61"
1312
)
1413

14+
// This example encodes an audio an video stream to a file
1515
func main() {
1616
// Create a new file with an audio and video stream
1717
file, err := ffmpeg.Create(os.Args[1],
18-
ffmpeg.OptStream(1, ffmpeg.VideoPar("yuv420p", "640x480", 30)),
18+
ffmpeg.OptStream(1, ffmpeg.VideoPar("yuv420p", "1280x720", 30)),
1919
ffmpeg.OptStream(2, ffmpeg.AudioPar("fltp", "mono", 22050)),
2020
)
2121
if err != nil {
2222
log.Fatal(err)
2323
}
2424
defer file.Close()
2525

26-
// Make an video generator which can generate YUV420P frames
27-
// with the same parameters as the video stream
28-
video, err := generator.NewYUV420P(file.Stream(1).Par())
26+
// Make an video generator which can generate frames with the same
27+
// parameters as the video stream
28+
video, err := generator.NewEBU(file.Stream(1).Par())
2929
if err != nil {
3030
log.Fatal(err)
3131
}
3232
defer video.Close()
3333

34-
// Make an audio generator which can generate a 440Hz tone
34+
// Make an audio generator which can generate a 1KHz tone
3535
// at -5dB with the same parameters as the audio stream
36-
audio, err := generator.NewSine(440, -5, file.Stream(2).Par())
36+
audio, err := generator.NewSine(1000, -5, file.Stream(2).Par())
3737
if err != nil {
3838
log.Fatal(err)
3939
}
4040
defer audio.Close()
4141

42-
// Write 1 min of frames, passing video and audio frames to the encoder
42+
// Write 90 seconds, passing video and audio frames to the encoder
4343
// and returning io.EOF when the duration is reached
44-
duration := time.Minute
45-
if err := file.Encode(func(stream int) (*ff.AVFrame, error) {
46-
var frame media.Frame
44+
duration := float64(90)
45+
err = file.Encode(func(stream int) (*ffmpeg.Frame, error) {
46+
var frame *ffmpeg.Frame
4747
switch stream {
4848
case 1:
4949
frame = video.Frame()
5050
case 2:
5151
frame = audio.Frame()
5252
}
53-
if frame.Time() >= duration {
54-
return nil, io.EOF
55-
} else {
56-
log.Println("Frame", stream, "=>", frame.Time().Truncate(time.Millisecond))
57-
return frame.(*ffmpeg.Frame).AVFrame(), nil
53+
if frame != nil && frame.Ts() < duration {
54+
fmt.Print(".")
55+
return frame, nil
5856
}
59-
}, nil); err != nil {
57+
return nil, io.EOF
58+
}, nil)
59+
if err != nil {
6060
log.Fatal(err)
6161
}
62+
fmt.Print("\n")
6263
}
133 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
139 KB
Binary file not shown.
130 KB
Binary file not shown.
Binary file not shown.
132 KB
Binary file not shown.

0 commit comments

Comments
 (0)