GoLang 将 webm 转换为 mp3

问题描述

这是我的代码示例

package main 

import (
  "fmt"
  "io"
  "net/http"

  "github.com/kkdai/youtube"
)

func getVideo() {
  client := youtube.Client{}
  currentVideo,videoError := client.GetVideo("https://www.youtube.com/watch?v=kGEJNZd1hTA")
  resp,err := client.GetStream(currentVideo,&currentVideo.Formats.Type("audio/webm")[0])
  w.Header().Set("Content-Type",req.Header.Get("Content-Type"))
  w.Header().Set("Content-disposition","attachment; filename=WHATEVER_YOU_WANT.webm")
  io.copy(w,resp.Body)
}

func main() {
  http.HandleFunc("/video",getVideo)

  http.ListenAndServe(":8090",nil)
}

那么问题是如何将我的 webm 流转换为 mp3 并将其提供给客户端?

解决方法

ffmpeg 是处理媒体的不错选择。
您可以尝试使用 go 的 exec pkg 并从那里运行 ffmpeg 命令。

一些在 go 中为 ffmpeg 提供绑定的库 - ffmpeg-go goav gmf