Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.14-buster
- image: circleci/golang:1.17-buster
environment:
GO111MODULE: "on"

Expand Down
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ MIT License

Copyright (c) 2020 FlooStack

Copyright (c) 2021 Legion-Zver (MACROX & ITRabbit)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
69 changes: 3 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
# Golang Transcoding Library

<br />

<div align="center">
<!-- Build status -->
<a href="https://circleci.com/gh/floostack/transcoder">
<img src="https://circleci.com/gh/floostack/transcoder.svg?style=svg" alt="Build Status" />
</a>

<!-- Code Quality -->
<a href="https://www.codacy.com/manual/floostack/transcoder?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=floostack/transcoder&amp;utm_campaign=Badge_Grade">
<img src="https://app.codacy.com/project/badge/Grade/f8ee19ef723b4134bb8bb1f9c439959e" alt="Build Status" />
</a>

</div>

<br />

<div align="center">
<sub>Created by <a href="https://floostack.com">FlooStack</a>.</sub>
</div>
Exec ffmpeg and ffprobe

## Features

Expand All @@ -34,49 +15,5 @@
## Download from Github

```shell
go get github.com/floostack/transcoder
```

## Example

```go
package main

import (
"log"

ffmpeg "github.com/floostack/transcoder/ffmpeg"
)

func main() {

format := "mp4"
overwrite := true

opts := ffmpeg.Options{
OutputFormat: &format,
Overwrite: &overwrite,
}

ffmpegConf := &ffmpeg.Config{
FfmpegBinPath: "/usr/local/bin/ffmpeg",
FfprobeBinPath: "/usr/local/bin/ffprobe",
ProgressEnabled: true,
}

progress, err := ffmpeg.
New(ffmpegConf).
Input("/tmp/avi").
Output("/tmp/mp4").
WithOptions(opts).
Start(opts)

if err != nil {
log.Fatal(err)
}

for msg := range progress {
log.Printf("%+v", msg)
}
}
```
go get github.com/legion-zver/transcoder
```
60 changes: 56 additions & 4 deletions ffmpeg/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
package ffmpeg

import (
"bytes"
"errors"
"os/exec"
"strings"
)

// Flags ...
type Flags struct {
Progress bool `json:"progress,omitempty"`
Verbose bool `json:"verbose,omitempty"`
Debug bool `json:"debug,omitempty"`
}

// Config ...
type Config struct {
FfmpegBinPath string
FfprobeBinPath string
ProgressEnabled bool
Verbose bool
Flags

// Paths
FfmpegBinPath string `json:"ffmpeg_bin_path"`
FfprobeBinPath string `json:"ffprobe_bin_path"`
}

func mergeFlags(flags ...Flags) (result Flags) {
for _, v := range flags {
result.Progress = result.Progress || v.Progress
result.Verbose = result.Verbose || v.Verbose
result.Debug = result.Debug || v.Debug
}
return
}

func NewAutoConfig(flags ...Flags) (*Config, error) {
out, which := bytes.Buffer{}, exec.Command("which", "ffmpeg")
which.Stdout = &out
if err := which.Run(); err != nil {
return nil, err
}
ffmpegBinPath := strings.TrimSpace(out.String())
out.Reset()
if len(ffmpegBinPath) < 1 {
return nil, errors.New("ffmpeg binary path not found")
}
which = exec.Command("which", "ffprobe")
which.Stdout = &out
if err := which.Run(); err != nil {
return nil, err
}
ffprobeBinPath := strings.TrimSpace(out.String())
out.Reset()
if len(ffprobeBinPath) < 1 {
return nil, errors.New("ffprobe binary path not found")
}
return &Config{
Flags: mergeFlags(flags...),
FfmpegBinPath: ffmpegBinPath,
FfprobeBinPath: ffprobeBinPath,
}, nil
}
1 change: 1 addition & 0 deletions ffmpeg/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package ffmpeg
Loading