-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from mutablelogic/ffmpeg61
Updates to the media abstraction
- Loading branch information
Showing
48 changed files
with
2,695 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
// Packages | ||
"github.com/djthorpe/go-tablewriter" | ||
"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"` | ||
Format string `name:"format" short:"f" help:"Format of input file (name, .extension or mimetype)" type:"string"` | ||
Audio *bool `name:"audio" short:"a" help:"Output raw audio stream" type:"bool"` | ||
Video *bool `name:"video" short:"v" help:"Output raw video stream" type:"bool"` | ||
} | ||
|
||
func (cmd *DecodeCmd) Run(globals *Globals) error { | ||
reader, err := media.Open(cmd.Path, "") | ||
var format media.Format | ||
|
||
manager := media.NewManager() | ||
if cmd.Format != "" { | ||
if formats := manager.InputFormats(media.NONE, cmd.Format); len(formats) == 0 { | ||
return fmt.Errorf("unknown format %q", cmd.Format) | ||
} else if len(formats) > 1 { | ||
return fmt.Errorf("ambiguous format %q", cmd.Format) | ||
} else { | ||
format = formats[0] | ||
} | ||
} | ||
|
||
// Open media file | ||
reader, err := manager.Open(cmd.Path, format) | ||
if err != nil { | ||
return err | ||
} | ||
defer reader.Close() | ||
|
||
data, _ := json.MarshalIndent(reader, "", " ") | ||
fmt.Println(string(data)) | ||
// Create a decoder - copy streams | ||
decoder, err := reader.Decoder(nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
// Demultiplex the stream | ||
header := []tablewriter.TableOpt{tablewriter.OptHeader()} | ||
tablewriter := tablewriter.New(os.Stdout, tablewriter.OptOutputText()) | ||
return decoder.Demux(context.Background(), func(packet media.Packet) error { | ||
if packet == nil { | ||
return nil | ||
} | ||
if err := tablewriter.Write(packet, header...); err != nil { | ||
return err | ||
} | ||
// Reset the header | ||
header = header[:0] | ||
return nil | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
// Packages | ||
"github.com/djthorpe/go-tablewriter" | ||
"github.com/mutablelogic/go-media" | ||
) | ||
|
||
type SampleFormatsCmd struct{} | ||
|
||
type ChannelLayoutsCmd struct{} | ||
|
||
type PixelFormatsCmd struct{} | ||
|
||
func (cmd *SampleFormatsCmd) Run(globals *Globals) error { | ||
manager := media.NewManager() | ||
writer := tablewriter.New(os.Stdout, tablewriter.OptHeader(), tablewriter.OptOutputText()) | ||
return writer.Write(manager.SampleFormats()) | ||
} | ||
|
||
func (cmd *ChannelLayoutsCmd) Run(globals *Globals) error { | ||
manager := media.NewManager() | ||
writer := tablewriter.New(os.Stdout, tablewriter.OptHeader(), tablewriter.OptOutputText()) | ||
return writer.Write(manager.ChannelLayouts()) | ||
} | ||
|
||
func (cmd *PixelFormatsCmd) Run(globals *Globals) error { | ||
manager := media.NewManager() | ||
writer := tablewriter.New(os.Stdout, tablewriter.OptHeader(), tablewriter.OptOutputText()) | ||
return writer.Write(manager.PixelFormats()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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"` | ||
} | ||
|
||
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() | ||
var formats []media.Format | ||
if cmd.Filter == "" { | ||
formats = manager.OutputFormats(media.ANY) | ||
} else { | ||
formats = manager.OutputFormats(media.ANY, cmd.Filter) | ||
} | ||
return Run(cmd.Filter, formats) | ||
} | ||
|
||
func (cmd *DemuxersCmd) Run(globals *Globals) error { | ||
manager := media.NewManager() | ||
var formats []media.Format | ||
if cmd.Filter == "" { | ||
formats = manager.InputFormats(media.ANY) | ||
} else { | ||
formats = manager.InputFormats(media.ANY, cmd.Filter) | ||
} | ||
return Run(cmd.Filter, formats) | ||
} | ||
|
||
func Run(filter string, formats []media.Format) error { | ||
writer := tablewriter.New(os.Stdout, tablewriter.OptHeader(), tablewriter.OptOutputText()) | ||
if len(formats) == 0 { | ||
fmt.Printf("No (de)muxers found for %q\n", filter) | ||
return nil | ||
} else { | ||
return writer.Write(formats) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"regexp" | ||
|
||
// Packages | ||
"github.com/mutablelogic/go-media" | ||
) | ||
|
||
type ProbeCmd struct { | ||
Path string `arg:"" required:"" help:"Media file or device name" type:"string"` | ||
Opts string `name:"opts" short:"o" help:"Options for opening the media file or device, (ie, \"framerate=30 video_size=176x144\")"` | ||
} | ||
|
||
var ( | ||
reDevice = regexp.MustCompile(`^([a-zA-Z0-9]+):(.*)$`) | ||
) | ||
|
||
func (cmd *ProbeCmd) Run(globals *Globals) error { | ||
var format media.Format | ||
|
||
manager := media.NewManager() | ||
filter := media.NONE | ||
|
||
// Try device first | ||
if m := reDevice.FindStringSubmatch(cmd.Path); m != nil { | ||
cmd.Path = m[2] | ||
fmts := manager.InputFormats(filter|media.DEVICE, m[1]) | ||
if len(fmts) > 0 { | ||
format = fmts[0] | ||
} | ||
} | ||
|
||
// Open the media file or device | ||
reader, err := manager.Open(cmd.Path, format, cmd.Opts) | ||
if err != nil { | ||
return err | ||
} | ||
defer reader.Close() | ||
|
||
// Print out probe data | ||
data, _ := json.MarshalIndent(reader, "", " ") | ||
fmt.Println(string(data)) | ||
|
||
// Return success | ||
return nil | ||
} |
Oops, something went wrong.