Skip to content

Commit

Permalink
Merge pull request #14 from mutablelogic/ffmpeg61
Browse files Browse the repository at this point in the history
Updates for media manager and cli
  • Loading branch information
djthorpe committed Jun 18, 2024
2 parents 11196fe + 6e24c54 commit 1436b17
Show file tree
Hide file tree
Showing 26 changed files with 503 additions and 157 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ test: go-dep
@echo Test
@${GO} mod tidy
@${GO} test ./sys/ffmpeg61
@${GO} test ./pkg/...
@${GO} test .

$(CMD_DIR): go-dep mkdir
@echo Build cmd $(notdir $@)
Expand Down
6 changes: 2 additions & 4 deletions cmd/cli/decode.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package main

import (

// Packages

"encoding/json"
"fmt"

// Packages
"github.com/mutablelogic/go-media"
)

type DecodeCmd struct {
Path string `arg required help:"Media file" type:"path"`
Path string `arg:"" required:"" help:"Media file" type:"path"`
}

func (cmd *DecodeCmd) Run(globals *Globals) error {
Expand Down
26 changes: 26 additions & 0 deletions cmd/cli/demuxers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"os"

// Packages
"github.com/djthorpe/go-tablewriter"
"github.com/mutablelogic/go-media"
)

type DemuxersCmd struct {
Filter string `arg:"" optional:"" help:"Filter by mimetype, name or .ext" type:"string"`
}

func (cmd *DemuxersCmd) Run(globals *Globals) error {
manager := media.NewManager()
formats := manager.InputFormats(cmd.Filter)
writer := tablewriter.New(os.Stdout, tablewriter.OptHeader(), tablewriter.OptOutputText())
if len(formats) == 0 {
fmt.Printf("No demuxers found for %q\n", cmd.Filter)
return nil
} else {
return writer.Write(formats)
}
}
2 changes: 2 additions & 0 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type Globals struct {
type CLI struct {
Globals
Version VersionCmd `cmd:"version" help:"Print version information"`
Demuxers DemuxersCmd `cmd:"demuxers" help:"List media demultiplex (input) formats"`
Muxers MuxersCmd `cmd:"muxers" help:"List media multiplex (output) formats"`
Metadata MetadataCmd `cmd:"metadata" help:"Display media metadata information"`
Decode DecodeCmd `cmd:"decode" help:"Decode media"`
}
Expand Down
26 changes: 26 additions & 0 deletions cmd/cli/muxers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"os"

// Packages
"github.com/djthorpe/go-tablewriter"
"github.com/mutablelogic/go-media"
)

type MuxersCmd struct {
Filter string `arg:"" optional:"" help:"Filter by mimetype, name or .ext" type:"string"`
}

func (cmd *MuxersCmd) Run(globals *Globals) error {
manager := media.NewManager()
formats := manager.OutputFormats(cmd.Filter)
writer := tablewriter.New(os.Stdout, tablewriter.OptHeader(), tablewriter.OptOutputText())
if len(formats) == 0 {
fmt.Printf("No muxers found for %q\n", cmd.Filter)
return nil
} else {
return writer.Write(formats)
}
}
2 changes: 1 addition & 1 deletion cmd/ffmpeg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using the low-level golang bindings.
Generate a synthetic audio signal and encode it to an output MP2 file.
* [encode_video](encode_video) - libavcodec encoding video API usage example.
Generate synthetic video data and encode it to an output file.
* [mux](mux) - Muxing - libavformat/libavcodec muxing API usage example.
* [mux](mux) - Muxing - libavformat/libavcodec muxing API usage example - NOT COMPLETED
Generate a synthetic audio signal and mux it into a container format.
* [remux](remux) - Remuxing - libavformat/libavcodec demuxing and muxing API usage example.
Remux streams from one container format to another. Data is copied from the input to the output
Expand Down
2 changes: 1 addition & 1 deletion cmd/ffmpeg/encode_audio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func main() {
}

// Allocate the data buffers
if err := ff.AVUtil_frame_get_buffer(frame, 0); err != nil {
if err := ff.AVUtil_frame_get_buffer(frame, false); err != nil {
log.Fatal(err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/ffmpeg/encode_video/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func main() {
frame.SetHeight(ctx.Height())

// Allocate the data buffers
if err := ff.AVUtil_frame_get_buffer(frame, 0); err != nil {
if err := ff.AVUtil_frame_get_buffer(frame, false); err != nil {
log.Fatal(err)
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/ffmpeg/mux/generate.go → cmd/ffmpeg/mux/generate.go_old
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func write_video_frame(ctx *ff.AVFormatContext, stream *Stream) bool {




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

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

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

return write_frame(oc, c, ost->st, frame, ost->tmp_pkt);
}
}
*/
8 changes: 6 additions & 2 deletions cmd/ffmpeg/mux/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ func main() {
for encode_audio || encode_video {
// Choose video if both are available, and video is earlier than audio
if (encode_video && !encode_audio) || (encode_video && ff.AVUtil_compare_ts(video.next_pts, video.Encoder.TimeBase(), audio.next_pts, audio.Encoder.TimeBase()) <= 0) {
encode_video = !write_video_frame(ctx, video)
fmt.Println("TODO: Write video frame")
encode_video = false
// encode_video = !write_video_frame(ctx, video)
} else {
encode_audio = !write_audio_frame(ctx, audio)
fmt.Println("TODO: Write audio frame")
encode_audio = false
// encode_audio = !write_audio_frame(ctx, audio)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/ffmpeg/mux/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func alloc_video_frame(pix_fmt ff.AVPixelFormat, width, height int) (*ff.AVFrame
frame.SetPixFmt(pix_fmt)

// allocate the buffers for the frame data
if err := ff.AVUtil_frame_get_buffer(frame, 0); err != nil {
if err := ff.AVUtil_frame_get_buffer(frame, false); err != nil {
ff.AVUtil_frame_free(frame)
return nil, err
}
Expand All @@ -246,7 +246,7 @@ func alloc_audio_frame(sample_fmt ff.AVSampleFormat, channel_layout ff.AVChannel
}

// allocate the buffers for the frame data
if err := ff.AVUtil_frame_get_buffer(frame, 0); err != nil {
if err := ff.AVUtil_frame_get_buffer(frame, false); err != nil {
ff.AVUtil_frame_free(frame)
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions etc/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY . .
RUN set -x \
&& apt update -y \
&& apt install -y ca-certificates lsb-release \
&& echo "deb https://www.deb-multimedia.org $(lsb_release -sc) main non-free" >> /etc/apt/sources.list \
&& echo "deb https://www.deb-multimedia.org $(lsb_release -sc) main" >> /etc/apt/sources.list \
&& apt update -y -oAcquire::AllowInsecureRepositories=true \
&& apt install -y --force-yes deb-multimedia-keyring \
&& apt install -y --allow-unauthenticated libavcodec-dev libavdevice-dev libavfilter-dev libavutil-dev libswscale-dev libswresample-dev
Expand All @@ -29,7 +29,7 @@ ARG SOURCE
RUN set -x \
&& apt update -y \
&& apt install -y ca-certificates lsb-release \
&& echo "deb https://www.deb-multimedia.org $(lsb_release -sc) main non-free" >> /etc/apt/sources.list \
&& echo "deb https://www.deb-multimedia.org $(lsb_release -sc) main" >> /etc/apt/sources.list \
&& apt update -y -oAcquire::AllowInsecureRepositories=true \
&& apt install -y --force-yes deb-multimedia-keyring \
&& apt install -y --allow-unauthenticated ffmpeg
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ toolchain go1.22.4
require (
github.com/alecthomas/kong v0.9.0
github.com/djthorpe/go-errors v1.0.3
github.com/djthorpe/go-tablewriter v0.0.7
github.com/djthorpe/go-tablewriter v0.0.8
github.com/hashicorp/go-multierror v1.1.1
github.com/mutablelogic/go-client v1.0.8
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 1436b17

Please sign in to comment.