I need microservice (converter audio using streams), but have problem with ffmpeg
my test ffmpeg
package codec
import (
"bytes"
"os"
"os/exec"
"testing"
)
func Test1(t *testing.T) {
in, err := os.Open("/mp4-mp3/src.m4a")
if err != nil {
t.Fatal(err.Error())
}
out, err := os.OpenFile("/mp4-mp3/out.mp3", os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
t.Fatal(err.Error())
}
cmd := exec.Command(
"ffmpeg",
"-f", "m4a",
"-i", "pipe:0",
"-f", "mp3",
"pipe:1")
cmd.Stdin = in
cmd.Stdout = out
stderr := &bytes.Buffer{}
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {
t.Logf(stderr.String())
t.Fatal(err.Error())
}
}
At the exit, I have the error invalid argument i tried different options but the problem didn't change
=== RUN Test1
codec_test.go:31: ffmpeg version git-2020-08-31-4a11a6f Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.1 (GCC) 20200805
configuration: hide...
libavutil 56. 58.100 / 56. 58.100
libavcodec 58.101.101 / 58.101.101
libavformat 58. 51.101 / 58. 51.101
libavdevice 58. 11.101 / 58. 11.101
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000019ccc3acb40] error reading header
pipe:0: Invalid argument
codec_test.go:32: exit status 1
--- FAIL: Test1 (0.07s)
FAIL
Process finished with exit code 1
i decided to use cmd, but i have new problem pipe:0: Invalid data found when processing input
cat src.m4a | ffmpeg -f m4a -i pipe:0 out.mp3
ffmpeg version git-2020-08-31-4a11a6f Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.1 (GCC) 20200805
configuration: hide...
libavutil 56. 58.100 / 56. 58.100
libavcodec 58.101.101 / 58.101.101
libavformat 58. 51.101 / 58. 51.101
libavdevice 58. 11.101 / 58. 11.101
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000019afa98d800] invalid STSD entries 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000019afa98d800] error reading header
pipe:0: Invalid data found when processing input
How to properly set ffmpeg parameters to convert from stream to stream?