Skip to content

Commit

Permalink
Merge pull request #25 from mutablelogic/ffmpeg61
Browse files Browse the repository at this point in the history
Small changes
  • Loading branch information
djthorpe authored Jun 26, 2024
2 parents 74a2c76 + 2f9f9b1 commit c59ae07
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 48 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/on_pull_request_merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,6 @@ on:
pull_request:
branches: [ main ]
jobs:
analyze:
name: Analyze
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
test:
name: Test
runs-on: ubuntu-24.04
Expand Down
26 changes: 14 additions & 12 deletions cmd/cli/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,26 @@ var (
reDevice = regexp.MustCompile(`^([a-zA-Z0-9]+):([^\/].*|)$`)
)

func (cmd *ProbeCmd) Run(globals *Globals) error {
var format media.Format

manager := globals.manager

filter := media.NONE
func formatFromPath(manager media.Manager, filter media.MediaType, path string) (media.Format, string) {
if m := reDevice.FindStringSubmatch(path); m != nil {

// 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]
return fmts[0], m[2]
}
}
return nil, path
}

func (cmd *ProbeCmd) Run(globals *Globals) error {
var format media.Format

// Get format and path
manager := globals.manager
format, path := formatFromPath(manager, media.NONE, cmd.Path)

// Open the media file or device
reader, err := manager.Open(cmd.Path, format, cmd.Opts)
// Open a reader
reader, err := manager.Open(path, format, cmd.Opts)
if err != nil {
return err
}
Expand Down
14 changes: 10 additions & 4 deletions cmd/cli/thumbnails.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ import (
)

type ThumbnailsCmd struct {
Path string `arg:"" required:"" help:"Media file or path" type:"path"`
Path string `arg:"" required:"" help:"Media file, device or path" type:"string"`
Dur time.Duration `name:"duration" help:"Duration between thumnnails" type:"duration" default:"1m"`
Width int `name:"width" help:"Width of thumbnail" type:"int" default:"320"`
}

func (cmd *ThumbnailsCmd) Run(globals *Globals) error {
// If we have a device, then use this
format, path := formatFromPath(globals.manager, media.NONE, cmd.Path)
if format != nil {
return cmd.mediaWalker(globals.ctx, globals.manager, format, path)
}

// Create the walker with the processor callback
walker := file.NewWalker(func(ctx context.Context, root, relpath string, info fs.FileInfo) error {
if info.IsDir() || info.Size() == 0 {
return nil
}
if err := cmd.mediaWalker(ctx, globals.manager, filepath.Join(root, relpath)); err != nil {
if err := cmd.mediaWalker(ctx, globals.manager, nil, filepath.Join(root, relpath)); err != nil {
if err == context.Canceled {
globals.manager.Infof("Cancelled\n")
} else {
Expand All @@ -41,8 +47,8 @@ func (cmd *ThumbnailsCmd) Run(globals *Globals) error {
return walker.Walk(globals.ctx, cmd.Path)
}

func (cmd *ThumbnailsCmd) mediaWalker(ctx context.Context, manager media.Manager, path string) error {
reader, err := manager.Open(path, nil)
func (cmd *ThumbnailsCmd) mediaWalker(ctx context.Context, manager media.Manager, format media.Format, path string) error {
reader, err := manager.Open(path, format)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions sys/ffmpeg61/avcodec_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import "C"
// TYPES

type jsonAVCodecParametersAudio struct {
SampleFormat AVSampleFormat `json:"format,omitempty"`
SampleRate int `json:"sample_rate,omitempty"`
ChannelLayout AVChannelLayout `json:"channel_layout,omitempty"`
SampleFormat AVSampleFormat `json:"format"`
SampleRate int `json:"sample_rate"`
ChannelLayout AVChannelLayout `json:"channel_layout"`
FrameSize int `json:"frame_size,omitempty"`
}

type jsonAVCodecParameterVideo struct {
PixelFormat AVPixelFormat `json:"format,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
PixelFormat AVPixelFormat `json:"format"`
Width int `json:"width"`
Height int `json:"height"`
SampleAspectRatio AVRational `json:"sample_aspect_ratio,omitempty"`
}

Expand Down
8 changes: 4 additions & 4 deletions sys/ffmpeg61/avformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ type jsonAVFormatContext struct {
Url string `json:"url,omitempty"`
NumStreams uint `json:"nb_streams,omitempty"`
Streams []*AVStream `json:"streams,omitempty"`
StartTime int64 `json:"start_time,omitempty"`
Duration int64 `json:"duration,omitempty"`
StartTime AVTimestamp `json:"start_time,omitempty"`
Duration AVTimestamp `json:"duration,omitempty"`
BitRate int64 `json:"bit_rate,omitempty"`
PacketSize uint `json:"packet_size,omitempty"`
Flags AVFormatFlag `json:"flags,omitempty"`
Expand All @@ -129,8 +129,8 @@ func (ctx *AVFormatContext) MarshalJSON() ([]byte, error) {
Url: C.GoString(ctx.url),
NumStreams: uint(ctx.nb_streams),
Streams: ctx.Streams(),
StartTime: int64(ctx.start_time),
Duration: int64(ctx.duration),
StartTime: AVTimestamp(ctx.start_time),
Duration: AVTimestamp(ctx.duration),
BitRate: int64(ctx.bit_rate),
PacketSize: uint(ctx.packet_size),
Flags: AVFormatFlag(ctx.flags),
Expand Down

0 comments on commit c59ae07

Please sign in to comment.