-
Notifications
You must be signed in to change notification settings - Fork 3
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 #22 from vladaad/dev
Release 1.0 - full rewrite
- Loading branch information
Showing
47 changed files
with
1,533 additions
and
1,858 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package encoder | ||
|
||
import ( | ||
"github.com/vladaad/discordcompressor/settings" | ||
"strconv" | ||
) | ||
|
||
func calculateFPS(video *settings.Vid) (*settings.FPS, bool) { | ||
modified := false // This variable is for accurate detection if FPS was changed, float fuckery? was making -vf fps=25/1 when input was 25.0000 | ||
fps := new(settings.FPS) | ||
fps.D, fps.N = video.Input.FPS.D, video.Input.FPS.N | ||
for { | ||
if float64(fps.N)/float64(fps.D) > float64(video.Output.Settings.MaxFPS)+1 { // allow for leniency | ||
if settings.Encoding.HalveFPS { | ||
fps.D *= 2 | ||
modified = true | ||
} else { | ||
fps.N = video.Output.Settings.MaxFPS | ||
fps.D = 1 | ||
modified = true | ||
break | ||
} | ||
} else { | ||
break | ||
} | ||
} | ||
return fps, modified | ||
} | ||
|
||
func fpsFilter(video *settings.Vid) string { | ||
fps := video.Output.FPS | ||
if video.Input.FPS != video.Output.FPS { | ||
var str string | ||
expr := strconv.Itoa(fps.N) | ||
expr += "/" | ||
expr += strconv.Itoa(fps.D) | ||
str = "fps=" + expr | ||
return str | ||
} else { | ||
return "" | ||
} | ||
} |
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,55 +1,49 @@ | ||
package audio | ||
|
||
import ( | ||
"github.com/vladaad/discordcompressor/metadata" | ||
"github.com/vladaad/discordcompressor/settings" | ||
"log" | ||
"os" | ||
"sync" | ||
) | ||
|
||
func EncodeAudio(video *settings.Video) (outBitrate float64, outFilename string) { | ||
// filename | ||
outFilenameBase := video.UUID + "." | ||
// normalize audio | ||
lnParams := new(LoudnormParams) | ||
if video.Input.AudioChannels > 2 { | ||
video.Output.Audio.Normalize = true | ||
} | ||
if video.Output.Audio.Normalize { | ||
dec := decodeAudio(video, lnParams) | ||
lnParams = detectVolume(dec) | ||
if isAudioSilent(lnParams) { | ||
return 0.0, "" | ||
} | ||
func GenFilename(video *settings.Vid) string { | ||
filename := video.UUID + "." | ||
switch video.Output.AEncoder.Type { | ||
case "ffmpeg": | ||
filename += video.Output.Settings.Container | ||
case "qaac", "fdkaac", "fhgaac": | ||
filename += "m4a" | ||
} | ||
// start decoding | ||
dec := decodeAudio(video, lnParams) | ||
// encode | ||
switch video.Output.Audio.Encoder.Type { | ||
return filename | ||
} | ||
func EncodeAudio(video *settings.Vid, wg *sync.WaitGroup) *settings.Vid { | ||
defer wg.Done() | ||
dec := decodeAudio(video) | ||
switch video.Output.AEncoder.Type { | ||
case "ffmpeg": | ||
outFilename = outFilenameBase + video.Output.Video.Encoder.Container | ||
encFFmpeg(outFilename, video, dec) | ||
case "qaac": | ||
outFilename = outFilenameBase + "m4a" | ||
encQaac(outFilename, video, dec) | ||
encFFmpeg(video, dec) | ||
case "fdkaac": | ||
outFilename = outFilenameBase + "m4a" | ||
encFDKaac(outFilename, video, dec) | ||
default: | ||
log.Println("Encoder type " + video.Output.Audio.Encoder.Type + " not found") | ||
os.Exit(0) | ||
encFDK(video, dec) | ||
case "fhgaac": | ||
encFHG(video, dec) | ||
case "qaac": | ||
encQaac(video, dec) | ||
} | ||
// bitrate | ||
if !settings.DryRun { | ||
return metadata.GetStats(outFilename, true).Bitrate, outFilename | ||
|
||
if !settings.Encoding.FastMode { | ||
video.Output.Bitrate.Audio = getBitrate(video) | ||
video.Output.Bitrate.Video = video.Output.Bitrate.Total - video.Output.Bitrate.Audio | ||
} else { | ||
return video.Output.Audio.Bitrate, outFilename | ||
log.Println("Audio encoding finished!") | ||
} | ||
return video | ||
} | ||
|
||
func isAudioSilent(params *LoudnormParams) bool { | ||
if params.LRA == "-inf" || params.Thresh == "-inf" || params.IL == "-inf" || params.TP == "-inf" { | ||
return true | ||
func getBitrate(video *settings.Vid) int { | ||
info, err := os.Stat(video.Output.AudioFile) | ||
if err != nil { | ||
panic("Failed to get audio bitrate") | ||
} | ||
return false | ||
return int(float64(info.Size()*8) / video.Time.Duration) | ||
} |
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,49 @@ | ||
package audio | ||
|
||
import ( | ||
"github.com/vladaad/discordcompressor/metadata" | ||
"github.com/vladaad/discordcompressor/settings" | ||
"io" | ||
"log" | ||
"os/exec" | ||
) | ||
|
||
func decodeAudio(video *settings.Vid) io.ReadCloser { | ||
var options []string | ||
|
||
// input | ||
options = append(options, "-loglevel", "warning", "-stats") | ||
options = append(options, metadata.AppendTimes(video)...) | ||
options = append(options, "-i", video.InFile) | ||
|
||
options = append(options, "-map_metadata", "-1") | ||
options = append(options, "-map_chapters", "-1") | ||
|
||
// filters | ||
filters, mapping := getFilters(video) | ||
if filters != "" { | ||
options = append(options, "-filter_complex", filters) | ||
} | ||
options = append(options, "-map", mapping) | ||
|
||
// output format | ||
options = append(options, "-c:a", "pcm_s32le") | ||
if video.Input.AChannels > 2 { | ||
options = append(options, "-ac", "2") | ||
} | ||
|
||
options = append(options, "-f", "wav", "-") | ||
|
||
if settings.Debug { | ||
log.Println(options) | ||
} | ||
|
||
cmd := exec.Command(settings.General.FFmpegExecutable, options...) | ||
pipe, _ := cmd.StdoutPipe() | ||
err := cmd.Start() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return pipe | ||
} |
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
Oops, something went wrong.