DEV Community

Yusuf Turhan Papurcu
Yusuf Turhan Papurcu

Posted on

Transform Audio Files Bit Rate

I download music for car stereo but it’s not support 160k bit rate files. And this audio files little big (like ~700MB).

So i decided write a program for this. In short project link is here. You must add your files to “input” and double-click main. Your transformed files saved in “out”.

For long let’s code some go code and run it.

First we need ffmpeg library in Windows. You can install from here. Extract it and go bin folder. Copy “ffmpeg.exe” to project folder. And open input and out folders. Then open the main.go file. I use baisic way for this. OS/Exec is used in here.

package main

import (
    "fmt"
    "os"
    "os/exec"
    "path/filepath"
)

func main() {
    err := filepath.Walk("./input", func(path string, info os.FileInfo, err error) error {
        name := info.Name()
        cmd := exec.Command("powershell", "./ffmpeg.exe", "-i", "'./input/"+name+"'", "-b", "128k", "'./out/"+name+"'")
        if err := cmd.Run(); err != nil {
            fmt.Println("Error: ", err)
        }
        return nil
    })
    if err != nil {
        panic(err)
    }

}
Enter fullscreen mode Exit fullscreen mode

And build it with go build . Now we can publish it as a folder. Zip it and upload Google Drive.

Top comments (0)