Golang joy4 package publish example does not work

175 Views Asked by At

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

There are 1 best solutions below

3
Zeke Lu On BEST ANSWER

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