duanfangfei5558 2016-02-24 02:00
浏览 50
已采纳

mplayer无法从golang获取stdin流

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 -
  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 Google Chrome 所有页面崩溃,三种解决方案都没有解决,我崩溃了
    • ¥18 如何用c++编写数学规律题
    • ¥20 使用uni-app发起网络请求,获取重定向302返回的cookie
    • ¥20 手机外部浏览器拉起微信小程序支付 (相关搜索:微信小程序)
    • ¥20 怎样通过一个网址找到其他同样模版的网址
    • ¥30 XIAO esp32c3 读取FDC2214的数据
    • ¥15 在工控机(Ubuntu系统)上外接USB蓝牙硬件进行蓝牙通信
    • ¥15 关于PROCEDURE和FUNCTION的问题
    • ¥100 webapi的部署(标签-服务器)
    • ¥20 怎么加快手机软件内部计时的时间(关键词-日期时间)