Skip to content

Commit

Permalink
Merge pull request #16 from vladaad/dev
Browse files Browse the repository at this point in the history
Release 0.6.3
  • Loading branch information
vladaad authored Jan 26, 2022
2 parents 3f940d4 + b19745c commit 1cc6bb1
Show file tree
Hide file tree
Showing 30 changed files with 447 additions and 425 deletions.
84 changes: 42 additions & 42 deletions .github/workflows/autocompile-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,45 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build - Windows 64bit
run: GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o "discordcompressor-win64.exe" -v

- name: Build - Windows 32bit
run: GOOS=windows GOARCH=386 go build -trimpath -ldflags "-s -w" -o "discordcompressor-win32.exe" -v

- name: Build - Linux 64bit
run: GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o "discordcompressor-linux64" -v

- name: Build - Linux 32bit
run: GOOS=linux GOARCH=386 go build -trimpath -ldflags "-s -w" -o "discordcompressor-linux32" -v

- name: Upload
uses: actions/upload-artifact@master
with:
name: Windows 64bit
path: discordcompressor-win64.exe

- name: Upload
uses: actions/upload-artifact@master
with:
name: Windows 32bit
path: discordcompressor-win32.exe

- name: Upload
uses: actions/upload-artifact@master
with:
name: Linux 64bit
path: discordcompressor-linux64

- name: Upload
uses: actions/upload-artifact@master
with:
name: Linux 32bit
path: discordcompressor-linux32
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build - Windows 64bit
run: GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o "discordcompressor-win64.exe" -v

- name: Build - Windows 32bit
run: GOOS=windows GOARCH=386 go build -trimpath -ldflags "-s -w" -o "discordcompressor-win32.exe" -v

- name: Build - Linux 64bit
run: GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o "discordcompressor-linux64" -v

- name: Build - Linux 32bit
run: GOOS=linux GOARCH=386 go build -trimpath -ldflags "-s -w" -o "discordcompressor-linux32" -v

- name: Upload
uses: actions/upload-artifact@master
with:
name: Windows 64bit
path: discordcompressor-win64.exe

- name: Upload
uses: actions/upload-artifact@master
with:
name: Windows 32bit
path: discordcompressor-win32.exe

- name: Upload
uses: actions/upload-artifact@master
with:
name: Linux 64bit
path: discordcompressor-linux64

- name: Upload
uses: actions/upload-artifact@master
with:
name: Linux 32bit
path: discordcompressor-linux32
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
<!-- DO NOT REMOVE - contributor_list:data:start:["vladaad", "anddddrew"]:end -->

# DiscordCompressor

A small program in Go that efficiently compresses videos using ffmpeg.

## Dependencies

[FFmpeg](https://ffmpeg.org) including FFprobe

### Optional (needed for some settings options)

[qaac](https://github.com/nu774/qaac)
[fdkaac](https://github.com/nu774/fdkaac)

## Usage

`discordcompressor <arguments> <input video(s)>`
* `-o filename` - Sets the output filename, extension is automatically added
* `-focus string` - Sets the focus - for example, "framerate" or "resolution" (configured in settings.json)
* `-mixaudio` - Mixes all audio tracks into one
* `-normalize` - Normalizes audio volume
* `-noscale` - Disables FPS limiting and scaling (not recommended)
* `-reenc string` - Force re-encodes audio or video ("a", "v", "av")
* `-settings string` - Selects the settings file - for example, settings-test.json.
* `-forcescore 60` - Forces a specific benchmark score when generating settings. Higher = slower, but higher-quality settings.
* `-size 8` - Sets the target size in MB
* `-subfind string` - Finds a certain string in subtitles and cuts according to it
* `-last 10` - Compresses the last x seconds of a video
* `-ss 15` - Sets the starting time like in ffmpeg
* `-t 10` - Sets the time to encode after the start of the file or `-ss`

Settings and logs are located in %appdata%\vladaad\dc on Windows and /home/username/.config/vladaad/dc on other platforms.

* `-o filename` - Sets the output filename, extension is automatically added
* `-focus string` - Sets the focus - for example, "framerate" or "resolution" (configured in settings.json)
* `-mixaudio` - Mixes all audio tracks into one
* `-normalize` - Normalizes audio volume
* `-noscale` - Disables FPS limiting and scaling (not recommended)
* `-reenc string` - Force re-encodes audio or video ("a", "v", "av")
* `-settings string` - Selects the settings file - for example, settings-test.json.
* `-forcescore 60` - Forces a specific benchmark score when generating settings. Higher = slower, but higher-quality
settings.
* `-size 8` - Sets the target size in MB
* `-subfind string` - Finds a certain string in subtitles and cuts according to it
* `-last 10` - Compresses the last x seconds of a video
* `-ss 15` - Sets the starting time like in ffmpeg
* `-t 10` - Sets the time to encode after the start of the file or `-ss`

Settings and logs are located in %appdata%\vladaad\dc on Windows and /home/username/.config/vladaad/dc on other
platforms.

## Compiling from source

You need [Go 1.16](https://golang.org/dl/) or newer

Afterwards run `go build` or `build.sh`. `build.sh` builds execs for both 64bit and 32bit and both Windows and Linux.

<!-- prettier-ignore-start -->
<!-- DO NOT REMOVE - contributor_list:start -->
## 👥 Contributors

## 👥 Contributors

- **[@vladaad](https://github.com/vladaad)**

Expand Down
6 changes: 3 additions & 3 deletions encoder/audio/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
)

func EncodeAudio (video *settings.Video) (outBitrate float64, outFilename string) {
func EncodeAudio(video *settings.Video) (outBitrate float64, outFilename string) {
// filename
outFilenameBase := video.UUID + "."
// normalize audio
Expand Down Expand Up @@ -47,9 +47,9 @@ func EncodeAudio (video *settings.Video) (outBitrate float64, outFilename string
}
}

func isAudioSilent (params *LoudnormParams) bool {
func isAudioSilent(params *LoudnormParams) bool {
if params.LRA == "-inf" || params.Thresh == "-inf" || params.IL == "-inf" || params.TP == "-inf" {
return true
}
return false
}
}
6 changes: 4 additions & 2 deletions encoder/audio/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
)

func decodeAudio (video *settings.Video, lnParams *LoudnormParams) io.ReadCloser {
func decodeAudio(video *settings.Video, lnParams *LoudnormParams) io.ReadCloser {
var options []string
dontDownmix := []int{1, 2, 6, 8}

Expand All @@ -37,7 +37,9 @@ func decodeAudio (video *settings.Video, lnParams *LoudnormParams) io.ReadCloser
}
filters, mapping := filters(video, lnParams)

if filters != "" {options = append(options, "-filter_complex", filters)}
if filters != "" {
options = append(options, "-filter_complex", filters)
}
options = append(options, "-map", mapping)

// Mapping
Expand Down
2 changes: 1 addition & 1 deletion encoder/audio/fdkaac.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ func encFDKaac(outFilename string, video *settings.Video, input io.ReadCloser) {
panic(err)
}
}
}
}
4 changes: 2 additions & 2 deletions encoder/audio/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func encFFmpeg(outFilename string, video *settings.Video, input io.ReadCloser) {
}
if video.Output.Audio.Encoder.UsesBitrate {
options = append(options,
"-b:a", strconv.FormatFloat(video.Output.Audio.Bitrate, 'f', -1, 64) + "k",
"-b:a", strconv.FormatFloat(video.Output.Audio.Bitrate, 'f', -1, 64)+"k",
)
}
options = append(options, "-map", "0:a:0")
Expand Down Expand Up @@ -68,4 +68,4 @@ func encFFmpeg(outFilename string, video *settings.Video, input io.ReadCloser) {
panic(err)
}
}
}
}
12 changes: 6 additions & 6 deletions encoder/audio/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func filters(video *settings.Video, lnParams *LoudnormParams) (filter string, ma
var inputs []string
if video.Output.Audio.Mix {
for i := 0; i < video.Input.AudioTracks; i++ {
inputs = append(inputs, "[0:a:" + strconv.Itoa(i) + "]")
inputs = append(inputs, "[0:a:"+strconv.Itoa(i)+"]")
}
} else {
inputs = []string{"[0:a:0]"}
Expand Down Expand Up @@ -46,10 +46,10 @@ func filters(video *settings.Video, lnParams *LoudnormParams) (filter string, ma
filter = append(filter, inputs...)
filter = append(filter, "loudnorm=linear=true:i=-14:lra=7:tp=-1")

filter = append(filter, ":measured_i=" + lnParams.IL)
filter = append(filter, ":measured_lra=" + lnParams.LRA)
filter = append(filter, ":measured_tp=" + lnParams.TP)
filter = append(filter, ":measured_thresh=" + lnParams.Thresh)
filter = append(filter, ":measured_i="+lnParams.IL)
filter = append(filter, ":measured_lra="+lnParams.LRA)
filter = append(filter, ":measured_tp="+lnParams.TP)
filter = append(filter, ":measured_thresh="+lnParams.Thresh)

filter = append(filter, "[voladj]")
filters = append(filters, strings.Join(filter, ""))
Expand All @@ -59,4 +59,4 @@ func filters(video *settings.Video, lnParams *LoudnormParams) (filter string, ma

merged := strings.Join(filters, ";")
return merged, mapping
}
}
2 changes: 1 addition & 1 deletion encoder/audio/qaac.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ func encQaac(outFilename string, video *settings.Video, input io.ReadCloser) {
panic(err)
}
}
}
}
8 changes: 4 additions & 4 deletions encoder/audio/voldetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type LoudnormParams struct {
IL string `json:"input_i"`
LRA string `json:"input_lra"`
TP string` json:"input_tp"`
TP string ` json:"input_tp"`
Thresh string `json:"input_thresh"`
}

Expand Down Expand Up @@ -46,13 +46,13 @@ func detectVolume(input io.ReadCloser) *LoudnormParams {
var lines []string
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if strings.Contains(line,"{") {
if strings.Contains(line, "{") {
foundJson = true
}
if foundJson {
lines = append(lines, line)
}
if strings.Contains(line,"}") {
if strings.Contains(line, "}") {
foundJson = false
}
}
Expand All @@ -65,4 +65,4 @@ func detectVolume(input io.ReadCloser) *LoudnormParams {
}

return parsed
}
}
20 changes: 10 additions & 10 deletions encoder/video/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@ func filters(video *settings.Video, pass int) (filter string, vertRes int, FPS f
} else {
FPS = float64(video.Output.Video.Limits.FPSMax)
}
filters = append(filters, "fps=" + strconv.FormatFloat(FPS, 'f', -1, 64))
filters = append(filters, "fps="+strconv.FormatFloat(FPS, 'f', -1, 64))
}

// Deduplication
if settings.Advanced.DeduplicateFrames && !settings.Original {
maxframes := FPS - 1
if maxframes >= 1 {
filters = append(filters, "mpdecimate=max=" + strconv.FormatFloat(maxframes,'f', 0, 64))
filters = append(filters, "mpdecimate=max="+strconv.FormatFloat(maxframes, 'f', 0, 64))
}
}

// Subtitle burning
if video.Output.Subs.SubFile != "" {
filters = append(filters, "subtitles=si=" + strconv.Itoa(video.Input.SubtitleStream) + ":f=" + video.Output.Subs.SubFile)
filters = append(filters, "subtitles=si="+strconv.Itoa(video.Input.SubtitleStream)+":f="+video.Output.Subs.SubFile)
}

// Pixfmt conversion
if video.Input.Pixfmt != video.Output.Video.Encoder.Pixfmt {
filters = append(filters, "format=" + video.Output.Video.Encoder.Pixfmt)
filters = append(filters, "format="+video.Output.Video.Encoder.Pixfmt)
}

// Resolution
vertRes = video.Input.Height
if video.Input.Height > video.Output.Video.Limits.VResMax || float64(video.Input.Width) > float64(video.Output.Video.Limits.VResMax) / 0.5625 {
if video.Input.Height > video.Output.Video.Limits.VResMax || float64(video.Input.Width) > float64(video.Output.Video.Limits.VResMax)/0.5625 {
vertRes = video.Output.Video.Limits.VResMax
scaleExpr := ""
scaleAlgo := ""
if float64(video.Input.Height) / float64(video.Input.Width) < 0.5625 { // 0.5625 = 16:9
horizRes := int(float64(video.Output.Video.Limits.VResMax) / 1.125) * 2 // very hacky way of ensuring a multiple of 2
if float64(video.Input.Height)/float64(video.Input.Width) < 0.5625 { // 0.5625 = 16:9
horizRes := int(float64(video.Output.Video.Limits.VResMax)/1.125) * 2 // very hacky way of ensuring a multiple of 2
scaleExpr = strconv.Itoa(horizRes) + ":-2"
} else {
scaleExpr = "-2:" + strconv.Itoa(video.Output.Video.Limits.VResMax)
}
switch settings.Decoding.ScalingHWAccel {
case "cuda":
filters = append(filters, "hwupload_cuda,scale_cuda=" + scaleExpr + ":lanczos,hwdownload,format=" + video.Output.Video.Encoder.Pixfmt)
filters = append(filters, "hwupload_cuda,scale_cuda="+scaleExpr+":bicubic,hwdownload,format="+video.Output.Video.Encoder.Pixfmt)
default:
if pass == 1 {
scaleAlgo = "bilinear"
} else {
scaleAlgo = "spline"
}
filters = append(filters, "scale=" + scaleExpr + ":flags=" + scaleAlgo)
filters = append(filters, "scale="+scaleExpr+":flags="+scaleAlgo)
}
}

Expand All @@ -74,4 +74,4 @@ func filters(video *settings.Video, pass int) (filter string, vertRes int, FPS f
}

return strings.Join(filters, ","), vertRes, FPS
}
}
7 changes: 3 additions & 4 deletions encoder/video/outmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
func addMetadata(video *settings.Video, vertRes int, FPS float64) []string {
var options []string

options = append(options, "-metadata:s:v:0", "title=" + strconv.FormatFloat(settings.TargetSize, 'f', 0, 64 ) + "mb video compressed using DiscordCompressor " + build.VERSION + " | " + generateVideoDescription(video, vertRes, FPS))
options = append(options, "-metadata:s:v:0", "title="+strconv.FormatFloat(settings.TargetSize, 'f', 0, 64)+"mb video compressed using DiscordCompressor "+build.VERSION+" | "+generateVideoDescription(video, vertRes, FPS))
if video.Output.Audio.Bitrate > 0 {
options = append(options, "-metadata:s:a:0", "title=" + generateAudioDescription(video))
options = append(options, "-metadata:s:a:0", "title="+generateAudioDescription(video))
}

return options
Expand Down Expand Up @@ -70,6 +70,5 @@ func generateAudioDescription(video *settings.Video) (description string) {
description = description + video.Output.Audio.Encoder.Options
}


return description
}
}
2 changes: 1 addition & 1 deletion encoder/video/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Encode(video *settings.Video, outFilename string, pass int) bool {
"-y", "-hwaccel", settings.Decoding.HardwareAccel,
)
if video.Input.IsHDR && settings.Decoding.TonemapHWAccel {
options = append(options, "-hwaccel", "opencl")
options = append(options, "-init_hw_device", "opencl")
}
options = append(options, times...)
options = append(options, "-i", video.Filename)
Expand Down
Loading

0 comments on commit 1cc6bb1

Please sign in to comment.