Skip to content

Commit 1436b17

Browse files
authored
Merge pull request #14 from mutablelogic/ffmpeg61
Updates for media manager and cli
2 parents 11196fe + 6e24c54 commit 1436b17

26 files changed

+503
-157
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ test: go-dep
4444
@echo Test
4545
@${GO} mod tidy
4646
@${GO} test ./sys/ffmpeg61
47+
@${GO} test ./pkg/...
48+
@${GO} test .
4749

4850
$(CMD_DIR): go-dep mkdir
4951
@echo Build cmd $(notdir $@)

cmd/cli/decode.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package main
22

33
import (
4-
5-
// Packages
6-
74
"encoding/json"
85
"fmt"
96

7+
// Packages
108
"github.com/mutablelogic/go-media"
119
)
1210

1311
type DecodeCmd struct {
14-
Path string `arg required help:"Media file" type:"path"`
12+
Path string `arg:"" required:"" help:"Media file" type:"path"`
1513
}
1614

1715
func (cmd *DecodeCmd) Run(globals *Globals) error {

cmd/cli/demuxers.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
// Packages
8+
"github.com/djthorpe/go-tablewriter"
9+
"github.com/mutablelogic/go-media"
10+
)
11+
12+
type DemuxersCmd struct {
13+
Filter string `arg:"" optional:"" help:"Filter by mimetype, name or .ext" type:"string"`
14+
}
15+
16+
func (cmd *DemuxersCmd) Run(globals *Globals) error {
17+
manager := media.NewManager()
18+
formats := manager.InputFormats(cmd.Filter)
19+
writer := tablewriter.New(os.Stdout, tablewriter.OptHeader(), tablewriter.OptOutputText())
20+
if len(formats) == 0 {
21+
fmt.Printf("No demuxers found for %q\n", cmd.Filter)
22+
return nil
23+
} else {
24+
return writer.Write(formats)
25+
}
26+
}

cmd/cli/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type Globals struct {
1515
type CLI struct {
1616
Globals
1717
Version VersionCmd `cmd:"version" help:"Print version information"`
18+
Demuxers DemuxersCmd `cmd:"demuxers" help:"List media demultiplex (input) formats"`
19+
Muxers MuxersCmd `cmd:"muxers" help:"List media multiplex (output) formats"`
1820
Metadata MetadataCmd `cmd:"metadata" help:"Display media metadata information"`
1921
Decode DecodeCmd `cmd:"decode" help:"Decode media"`
2022
}

cmd/cli/muxers.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
// Packages
8+
"github.com/djthorpe/go-tablewriter"
9+
"github.com/mutablelogic/go-media"
10+
)
11+
12+
type MuxersCmd struct {
13+
Filter string `arg:"" optional:"" help:"Filter by mimetype, name or .ext" type:"string"`
14+
}
15+
16+
func (cmd *MuxersCmd) Run(globals *Globals) error {
17+
manager := media.NewManager()
18+
formats := manager.OutputFormats(cmd.Filter)
19+
writer := tablewriter.New(os.Stdout, tablewriter.OptHeader(), tablewriter.OptOutputText())
20+
if len(formats) == 0 {
21+
fmt.Printf("No muxers found for %q\n", cmd.Filter)
22+
return nil
23+
} else {
24+
return writer.Write(formats)
25+
}
26+
}

cmd/ffmpeg/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using the low-level golang bindings.
1515
Generate a synthetic audio signal and encode it to an output MP2 file.
1616
* [encode_video](encode_video) - libavcodec encoding video API usage example.
1717
Generate synthetic video data and encode it to an output file.
18-
* [mux](mux) - Muxing - libavformat/libavcodec muxing API usage example.
18+
* [mux](mux) - Muxing - libavformat/libavcodec muxing API usage example - NOT COMPLETED
1919
Generate a synthetic audio signal and mux it into a container format.
2020
* [remux](remux) - Remuxing - libavformat/libavcodec demuxing and muxing API usage example.
2121
Remux streams from one container format to another. Data is copied from the input to the output

cmd/ffmpeg/encode_audio/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func main() {
8383
}
8484

8585
// Allocate the data buffers
86-
if err := ff.AVUtil_frame_get_buffer(frame, 0); err != nil {
86+
if err := ff.AVUtil_frame_get_buffer(frame, false); err != nil {
8787
log.Fatal(err)
8888
}
8989

cmd/ffmpeg/encode_video/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func main() {
9292
frame.SetHeight(ctx.Height())
9393

9494
// Allocate the data buffers
95-
if err := ff.AVUtil_frame_get_buffer(frame, 0); err != nil {
95+
if err := ff.AVUtil_frame_get_buffer(frame, false); err != nil {
9696
log.Fatal(err)
9797
}
9898

cmd/ffmpeg/mux/generate.go renamed to cmd/ffmpeg/mux/generate.go_old

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func write_video_frame(ctx *ff.AVFormatContext, stream *Stream) bool {
6767

6868

6969

70-
70+
/*
7171
static int write_audio_frame(AVFormatContext *oc, OutputStream *ost)
7272
{
7373
AVCodecContext *c;
@@ -80,8 +80,8 @@ func write_video_frame(ctx *ff.AVFormatContext, stream *Stream) bool {
8080
frame = get_audio_frame(ost);
8181

8282
if (frame) {
83-
/* convert samples from native format to destination codec format, using the resampler */
84-
/* compute destination number of samples */
83+
/* convert samples from native format to destination codec format, using the resampler
84+
/* compute destination number of samples
8585
dst_nb_samples = av_rescale_rnd(swr_get_delay(ost->swr_ctx, c->sample_rate) + frame->nb_samples,
8686
c->sample_rate, c->sample_rate, AV_ROUND_UP);
8787
av_assert0(dst_nb_samples == frame->nb_samples);
@@ -94,7 +94,7 @@ func write_video_frame(ctx *ff.AVFormatContext, stream *Stream) bool {
9494
if (ret < 0)
9595
exit(1);
9696

97-
/* convert to destination format */
97+
/* convert to destination format
9898
ret = swr_convert(ost->swr_ctx,
9999
ost->frame->data, dst_nb_samples,
100100
(const uint8_t **)frame->data, frame->nb_samples);
@@ -109,4 +109,5 @@ func write_video_frame(ctx *ff.AVFormatContext, stream *Stream) bool {
109109
}
110110

111111
return write_frame(oc, c, ost->st, frame, ost->tmp_pkt);
112-
}
112+
}
113+
*/

cmd/ffmpeg/mux/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ func main() {
9090
for encode_audio || encode_video {
9191
// Choose video if both are available, and video is earlier than audio
9292
if (encode_video && !encode_audio) || (encode_video && ff.AVUtil_compare_ts(video.next_pts, video.Encoder.TimeBase(), audio.next_pts, audio.Encoder.TimeBase()) <= 0) {
93-
encode_video = !write_video_frame(ctx, video)
93+
fmt.Println("TODO: Write video frame")
94+
encode_video = false
95+
// encode_video = !write_video_frame(ctx, video)
9496
} else {
95-
encode_audio = !write_audio_frame(ctx, audio)
97+
fmt.Println("TODO: Write audio frame")
98+
encode_audio = false
99+
// encode_audio = !write_audio_frame(ctx, audio)
96100
}
97101
}
98102

0 commit comments

Comments
 (0)