英文:
mplayer fail to get stdin stream from golang
问题
我想为Linux编写一个简单的命令行m3u8播放器。(如果已经有一个,请告诉我。)
m3u8文件中有几个ts文件的URL。m3u8文件是从网络动态更改的。通常,一个ts文件只有几秒钟的长度。所以我需要不断地下载m3u8文件和其中的ts文件。然后我使用mplayer来连续播放流。我想这就是一个网络广播。
以下是我已经完成的部分:
首先,我启动mplayer进程并获取其标准输入:
mplayer_cmd := exec.Command("sh", "-c", "mplayer -msglevel all=9 -cache 80 -")
mplayer_writer, mplayer_err := mplayer_cmd.StdinPipe()
然后,我获取m3u8文件和其中的ts文件URL,并使用wget下载ts文件的内容并将其写入mplayer的标准输入。我会一遍又一遍地执行这个步骤:
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 empty, consider increasing -cache and/or -cache-min. [performance issue]
一个可疑的信息是,mplayer在启动时会fork一个子进程。在这种情况下,stdin/stdout管道会断开吗?
| | \-+- 03027 hgneng mplayer -msglevel all=9 -cache 80 -
| | \--- 03033 hgneng mplayer -msglevel all=9 -cache 80 -
英文:
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
得分: 0
抱歉,这是我的错。我在某个地方获取了mplayer的stdout管道进行调试。然而,由于没有输出,代码在那里挂起了。我通过godebug发现了这个问题。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论