英文:
Golang joy4 package publish example does not work
问题
- 服务器: https://github.com/nareix/joy4/tree/master/examples/http_flv_and_rtmp_server
- 发布: https://github.com/nareix/joy4/tree/master/examples/rtmp_publish
我先启动了服务器,然后运行了 rtmp_publish
来将 flv 数据发布到服务器上。不幸的是,它没有起作用。
之后,我尝试使用 ffmpeg 进行发布:
$ ffmpeg -re -i projectindex.flv -c copy -f flv rtmp://localhost:1936/app/publish
这样做是成功的,我可以用 VLC 播放流。
然后我检查了服务器上的日志。对于 ffmpeg,日志中包含 Accept
和 Parsing URL
。但对于 rtmp_publish.go
,日志只包含 Accept
。
英文:
- Server: https://github.com/nareix/joy4/tree/master/examples/http_flv_and_rtmp_server
- Publish: https://github.com/nareix/joy4/tree/master/examples/rtmp_publish
I started the server first, then ran rtmp_publish
to publish flv data to the server. Unfortunately, it didn't work.
After that, I tried to publish with ffmpeg:
$ ffmpeg -re -i projectindex.flv -c copy -f flv rtmp://localhost:1936/app/publish
It worked and I could play the stream with VLC.
Then I checked the log on the server. For ffmpeg, the log contains Accept
and Parsing URL
. But for rtmp_publish.go
, the log only contains Accept
.
答案1
得分: 1
我使用从https://getsamplefiles.com/sample-video-files/flv下载的flv文件(sample-3.flv
)进行了测试,ffmpeg和rtmp_publish/main.go
都可以正常工作。你能否请使用这个文件进行测试?
如果它可以正常工作,那么最有可能的是你最初测试的flv文件包含了该包不支持的流。
我使用ffprobe
检查了sample-3.flv
的信息:
$ ffprobe sample-3.flv
Input #0, flv, from 'sample-3.flv':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.15.102
Duration: 00:00:30.08, start: 0.000000, bitrate: 7836 kb/s
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 8000 kb/s, 25 fps, 25 tbr, 1k tbn
你可以检查你的文件并将输出与上面的输出进行比较(但我不知道该包支持什么或不支持什么)。
其他想运行示例的注意事项:
首先,该包的源代码中不包含go.mod
文件。在存储库的根目录创建一个:
$ go mod init github.com/nareix/joy4
http_flv_and_rtmp_server
默认监听端口1935
。所以如果我们不改变服务器,我们必须更改rtmp_publish/main.go
:
- file, _ := avutil.Open("projectindex.flv")
- conn, _ := rtmp.Dial("rtmp://localhost:1936/app/publish")
+ file, _ := avutil.Open("sample-3.flv")
+ conn, _ := rtmp.Dial("rtmp://localhost:1935/app/publish")
ffmpeg命令应为:
$ ffmpeg -re -i sample-3.flv -c copy -f flv rtmp://localhost:1935/app/publish
流可以使用ffplay
播放:
$ ffplay http://localhost:8089/app/publish
在运行ffmpeg
或go run rtmp_publish/main.go
时,请确保sample-3.flv
位于当前工作目录中。
英文:
I tested with a flv file (sample-3.flv
) downloaded from https://getsamplefiles.com/sample-video-files/flv, and both ffmpeg and rtmp_publish/main.go
work. Can you please test with this file?
If it works, then it's most likely that the flv file you tested at first contains stream that is not supported by the package.
I haved checked the information of sample-3.flv
with ffprobe
:
$ ffprobe sample-3.flv
Input #0, flv, from 'sample-3.flv':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.15.102
Duration: 00:00:30.08, start: 0.000000, bitrate: 7836 kb/s
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 8000 kb/s, 25 fps, 25 tbr, 1k tbn
You can check yours and compare the output with the one above (but I don't know what is or is not supported by the package).
Notes for others who want to run the example:
First, the source code of the package does not contain a go.mod
file. Create one at the root of the repository:
$ go mod init github.com/nareix/joy4
http_flv_and_rtmp_server
listens on port 1935
by default. So if we don't change the server, we have to change rtmp_publish/main.go
:
- file, _ := avutil.Open("projectindex.flv")
- conn, _ := rtmp.Dial("rtmp://localhost:1936/app/publish")
+ file, _ := avutil.Open("sample-3.flv")
+ conn, _ := rtmp.Dial("rtmp://localhost:1935/app/publish")
And the ffmpeg command should be:
$ ffmpeg -re -i sample-3.flv -c copy -f flv rtmp://localhost:1935/app/publish
And the stream can be played with ffplay
:
$ ffplay http://localhost:8089/app/publish
Make sure sample-3.flv
is in the current working directory when running ffmpeg
or go run rtmp_publish/main.go
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论