From 3feb0c7e1b05552eb49bb468592ef3cdd974c072 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Tue, 11 Feb 2025 18:36:29 -0300 Subject: [PATCH] feat: improve audio conversion with enhanced ffmpeg parameters - Updated Dockerfile to use Go 1.22 - Refined audio conversion parameters for mp3 and mp4 formats - Added specific sample rate, channels, and bitrate settings - Used libmp3lame codec for mp3 conversion - Improved mp4 audio extraction configuration --- Dockerfile | 2 +- main.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 12f06dd..0eafdbf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Usar uma imagem base do Go -FROM golang:1.21-alpine +FROM golang:1.22-alpine # Instalar ffmpeg RUN apk update && apk add --no-cache ffmpeg diff --git a/main.go b/main.go index 2140c5e..7faaded 100644 --- a/main.go +++ b/main.go @@ -161,9 +161,15 @@ func convertAudio(inputData []byte, format string) ([]byte, int, error) { var cmd *exec.Cmd switch format { case "mp3": - cmd = exec.Command("ffmpeg", "-i", "pipe:0", "-f", "mp3", "pipe:1") + cmd = exec.Command("ffmpeg", "-i", "pipe:0", + "-ar", "44100", // sample rate + "-ac", "2", // canais (stereo) + "-b:a", "128k", // bitrate + "-c:a", "libmp3lame", // codec especĂ­fico + "-f", "mp3", // formato + "pipe:1") case "mp4": - cmd = exec.Command("ffmpeg", "-i", "pipe:0", "-c:a", "aac", "-f", "mp4", "pipe:1") + cmd = exec.Command("ffmpeg", "-i", "pipe:0", "-vn", "-c:a", "aac", "-b:a", "128k", "-f", "adts", "pipe:1") default: cmd = exec.Command("ffmpeg", "-i", "pipe:0", "-ac", "1", "-ar", "16000", "-c:a", "libopus", "-f", "ogg", "pipe:1") }