Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic streaming to nginx #82

Open
hasnickl opened this issue Nov 5, 2018 · 2 comments
Open

Panic streaming to nginx #82

hasnickl opened this issue Nov 5, 2018 · 2 comments

Comments

@hasnickl
Copy link

hasnickl commented Nov 5, 2018

I have a ffmpeg command line that runs well streaming to nginx rtmp module:

i want to control this from my code, so i implement proper output:

	outputFormat := gmf.FindOutputFmt("flv", "rtmp://localhost:1935/live/test", "")
	log.Println("OutputFormat:")
	log.Println("\t", outputFormat.Infomation())
	dashOutCtx, err := gmf.NewOutputCtx(outputFormat)
	if err != nil {
		panic(err)
	}
	for i := 0; i < inputCtx.StreamsCnt(); i++ {
		srcStream, err := inputCtx.GetStream(i)
		if err != nil {
			fmt.Println("GetStream error")
		}
		dashOutCtx.AddStreamWithCodeCtx(srcStream.CodecCtx())
	}

        for packet := range inputCtx.GetNewPackets() {
            if err := dashOutCtx.WritePacket(packet); err != nil {
		log.Println("Error writing to live stream:", err)
            }
        }

but it hits error immediately every time:

Error writing to live stream: Unable to write packet to 'rtmp://localhost:1935/live/test': Invalid argument
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f958ca1606e]

runtime stack:
runtime.throw(0x924cb4, 0x2a)
        /usr/local/go/src/runtime/panic.go:608 +0x72
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:374 +0x2f2

goroutine 14 [syscall]:
runtime.cgocall(0x814140, 0xc0000cfb78, 0xc000166d20)
        /usr/local/go/src/runtime/cgocall.go:128 +0x5e fp=0xc0000cfb48 sp=0xc0000cfb10 pc=0x42b58e
gitlab.com/cavillis/hsnotify/vendor/github.com/3d0c/gmf._Cfunc_av_interleaved_write_frame(0x7f952c04cb00, 0xc000166d20, 0xc000000000)
        _cgo_gotypes.go:1676 +0x4d fp=0xc0000cfb78 sp=0xc0000cfb48 pc=0x7d9ebd
gitlab.com/cavillis/hsnotify/vendor/github.com/3d0c/gmf.(*FmtCtx).WritePacket.func1(0x7f952c04cb00, 0xc000166d20, 0x7e8acd)
        /media/nickl/Workspace/workspace/tune/go/src/gitlab.com/cavillis/hsnotify/vendor/github.com/3d0c/gmf/format.go:312 +0xd2 fp=0xc0000cfbb0 sp=0xc0000cfb78 pc=0x7e6c22
gitlab.com/cavillis/hsnotify/vendor/github.com/3d0c/gmf.(*FmtCtx).WritePacket(0xc0002d8000, 0xc000166d20, 0x3, 0x2)
        /media/nickl/Workspace/workspace/tune/go/src/gitlab.com/cavillis/hsnotify/vendor/github.com/3d0c/gmf/format.go:312 +0x47 fp=0xc0000cfc38 sp=0xc0000cfbb0 pc=0x7e0a47

This same code is writing out mp4/mkv files no problem. Only the live stream to nginx causes problems

@3d0c
Copy link
Owner

3d0c commented Nov 5, 2018

Errors in av_interleaved_write_frame usually mean wrong input. There is no WriteHeader() in your code snippet. Please check and add it before packets loop.
BTW, it's better to use GetNextPacket instead of GetNewPackets.

@hasnickl
Copy link
Author

hasnickl commented Nov 12, 2018

thanks @3d0c for your reply. You were write about WriteHeader, i added in that step and also switched to using GetNextPacket. I am still unable to stream to nginx via gmf.

When running GMF stream to nginx, it appears to run normally (no errors writing to nginx). When I try to play the stream in VLC the screen is just black, sometimes 1 frame will come through but nothing else. Here is a snippet of the VLC log:

main warning: picture is too late to be displayed (missing 19870 ms)
main warning: picture is too late to be displayed (missing 19961 ms)
avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?)
avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?)
main warning: picture is too late to be displayed (missing 19960 ms)
main warning: picture is too late to be displayed (missing 19870 ms)
avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?)
avcodec error: more than 5 seconds of late video -> dropping frame (computer too slow ?)
main warning: picture is too late to be displayed (missing 19870 ms)

Nginx log looks normal (just PUBLISH and PLAY statements).

The same code is producing files to local disk that are flawless so I know GMF is working in that scenario. It seems specific to rtmp/flv streaming that GMF is having problems.

I also tried using WritePacketNoBuffer, and also tried running without the second output (recording to local disk), both had same result. VLC will grab 1 frame after ~ 5 seconds of streaming but nothing else.

The exact same nginx process works flawlessly when I stream to it using ffmpeg binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants