u2takey / ffmpeg-go

golang binding for ffmpeg
Apache License 2.0
1.67k stars 167 forks source link

Any way to pass []byte as Input #31

Open captain-bugs opened 2 years ago

captain-bugs commented 2 years ago

I want to read image from s3 and convert it. Is there way to pass []byte to Input func?

u2takey commented 2 years ago

try this:

buf := bytes.NewBuffer(your []byte input)
err := ffmpeg.Input("pipe:",ffmpeg.KwArgs{}).
            Output(outfileName, ffmpeg.KwArgs{}).
            OverWriteOutput().
            WithInput(buf).Run()
LucasJosivan commented 11 months ago

try this:

buf := bytes.NewBuffer(your []byte input)
err := ffmpeg.Input("pipe:",ffmpeg.KwArgs{}).
          Output(outfileName, ffmpeg.KwArgs{}).
          OverWriteOutput().
          WithInput(buf).Run()

This didn't work for me.

I'm trying to add watermark to images and videos using ffmpeg. My files are stored on AWS S3, so they are byte arrays ([]byte).

I need my input and output to be in a byte array and not saved to disk.

I tried something like the code and it didn't work:

    buffFile := bytes.NewBuffer(file)
    out := &bytes.Buffer{}
    overlay := ffmpeg.Input("pipe:", ffmpeg.KwArgs{}).Filter("scale", ffmpeg.Args{"64:-1"}).WithInput(buffWatermark)
    err = ffmpeg.Filter(
        []*ffmpeg.Stream{
            ffmpeg.Input("pipe:", ffmpeg.KwArgs{}).WithInput(buffFile),
            overlay,
        }, "overlay", ffmpeg.Args{"10:10"}, ffmpeg.KwArgs{"enable": "gte(t,1)"}).
        Output("pipe:", ffmpeg.KwArgs{}).WithOutput(out).OverWriteOutput().ErrorToStdOut().Run()
juxiaoming commented 5 months ago
func FfmpegTransByte(src []byte) ([]byte, error) {
    buf := bytes.NewBuffer(src)
    out := &bytes.Buffer{}
    err := ffmpeg.Input("pipe:", ffmpeg.KwArgs{}).WithInput(buf).Output("pipe:", ffmpeg.KwArgs{
        "acodec": "pcm_s16le",
        "f":      "wav",
        "ac":     "1",
        "ar":     "16000",
    }).WithOutput(out).OverWriteOutput().Silent(true).Run()
    return out.Bytes(), err
}

This may be ok