2016-02-24 02:00
浏览 45


I want to write a simple command line m3u8 player for Linux. (Let me know if there already one.)

There are several ts file urls in m3u8 file. m3u8 file is dynamically changed from network. Usually, one ts file has only a few seconds. So I need to download m3u8 file and ts files in it again and again. Then I use mplayer to play the stream continuesly. I suppose this is a network radio.

Here is what I have done:

First, I lauch mplayer process and get the stdin:

mplayer_cmd := exec.Command("sh", "-c", "mplayer -msglevel all=9 -cache 80 -")
mplayer_writer, mplayer_err := mplayer_cmd.StdinPipe()

Then, I get m3u8 file and ts urls in it and wget content of ts file and write it to stdin of mplayer. And I do this step again and again:

out, err = exec.Command("sh", "-c", "wget " + m3u8_url + " -qO - | grep '.ts'").Output()
out, err = exec.Command("sh", "-c", "wget " + ts_url + " -qO -").Output()
n, err = mplayer_writer.Write(out)
fmt.Println("wrote ", n)

No sound come out from mplayer. Comparing to a successful running from command line, there is such related error messsage:

Cache empty, consider increasing -cache and/or -cache-min. [performance issue]

A suspect info is that - mplayer fork a child process when lauch. Will stdin/stdout pipe broken in this situation?

 | |       \-+- 03027 hgneng mplayer -msglevel all=9 -cache 80 -
 | |         \--- 03033 hgneng mplayer -msglevel all=9 -cache 80 -

图片转代码服务由CSDN问答提供 功能建议

我想为Linux编写一个简单的命令行m3u8播放器。 (让我知道是否已经有一个。)

m3u8文件中有多个ts文件网址。 m3u8文件是从网络动态更改的。 通常,一个ts文件只有几秒钟的时间。 因此,我需要一次又一次下载m3u8文件和ts文件。 然后,我使用mplayer连续播放流。 我想这是网络广播。



  mplayer_cmd:= exec.Command(“ sh”,“ -c”,“ mplayer -msglevel all = 9 -cache 80-”)
mplayer_writer,mplayer_err:= mplayer_cmd.StdinPipe  ()

然后,我在其中获取m3u8文件和ts网址,并获取ts文件的内容并将其写入mplayer的stdin。 我一次又一次地执行此步骤:

  out,err = exec.Command(“ sh”,“ -c”,“ wget” + m3u8_url +“ -qO-  | grep'.ts'“)。Output()
out,err = exec.Command(” sh“,” -c“,” wget“ + ts_url +” -qO-“)。Output(  )
n,err = mplayer_writer.Write(out)
fmt.Println(“ wrote”,n)

没有声音传出 mplayer的。 与从命令行成功运行相比,存在以下相关错误消息:

 缓存为空,请考虑增加-cache和/或-cache-min。  [性能问题] 

一个可疑的信息是-mplayer在启动时会分叉一个子进程。 在这种情况下,stdin / stdout管道会断开吗?

  |  |  \-+-03027 hgneng mplayer -msglevel all = 9 -cache 80-
 |  |  \ --- 03033 hgneng mplayer -msglevel all = 9 -cache 80-
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongpang9573 2016-02-24 08:19

    Sorry, it's my fault. I get the stdout pipe of mplayer somewhere for debug. However, the code hangs there because there is no output. I found this with godebug.

    点赞 评论

相关推荐 更多相似问题