登录
首页 >  Golang >  Go问答

ffmpeg:读取标头管道时出错:0:参数无效

来源:stackoverflow

时间:2024-04-10 10:33:34 329浏览 收藏

在Golang实战开发的过程中,我们经常会遇到一些这样那样的问题,然后要卡好半天,等问题解决了才发现原来一些细节知识点还是没有掌握好。今天golang学习网就整理分享《ffmpeg:读取标头管道时出错:0:参数无效》,聊聊,希望可以帮助到正在努力赚钱的你。

问题内容

我需要微服务(使用流转换音频),但 ffmpeg 有问题

我的测试 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())
    }

}

在退出时,我收到错误参数无效 我尝试了不同的选项,但问题没有改变

=== 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

我决定使用cmd,但我遇到了新问题 pipeline:0: 处理输入时发现无效数据

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

如何正确设置ffmpeg参数以实现流与流之间的转换?


解决方案


通常,mp4 无法通过 pipe 协议加载。视频容器无法顺序读取。如果 mp4created with some special flags,则可以缓解此问题,但这可能会导致一些其他问题。

好了,本文到此结束,带大家了解了《ffmpeg:读取标头管道时出错:0:参数无效》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>