vnc2video icon indicating copy to clipboard operation
vnc2video copied to clipboard

[Feature Request] Force Input Close on vcodec.Close()

Open toni-moreno opened this issue 5 years ago • 5 comments

Hi @amitbet , I'm working also with your great library but I found a non expected behaviour.

When I I call: vcodec.Close() On by example x264 enconder https://github.com/amitbet/vnc2video/blob/master/encoders/x264-enc.go ffmpeg doen't save video.

I've been playing by copying the complete x264-enc.go/image-enc.go into my code (renaming as CustomEncode) and 've finally achieved force ffmpeg to save video on vcodec.Close() by forcing input close.


func (enc *CustomEncoder) Close() {
	enc.closed = true
	err := enc.input.Close()
	if err != nil {
		debug.PrintStack()
		log.Errorf("=============>Error on waiting for stop ffmpeg encoder: %s", err)
	}
}

¿ Could yo please add to your encoders please?

Thank you very much

toni-moreno avatar Feb 20 '20 05:02 toni-moreno

I tried your solution but did not work well, I see the author add a comment in Close function,//enc.cmd.Process.Kill(), he maybe think about this long before. I'm trying to fix this problem

liuzheng avatar Mar 13 '20 01:03 liuzheng

using ffmpeg the way I did is kind of a hack in itself, you don't have direct control of the ffmpeg process once you have launched it. The right way would be to use one of the go-ffmpeg wrapper libs, but that was too complex for what I wanted to do (which was to implement a VNC client in go). another solution is to use the MJPEG implementation which is pure go code instead of using ffmpeg, and encode the resulting video to another format later on.

amitbet avatar Mar 21 '20 01:03 amitbet

The enc.input.Close() is working fine for me in production for more than 1 month.

We are recording selenium based browsing inside qemu VNC based vm's inside docker. We control the stop recording and the start of writting mpg file by executing the Close() method in the recorder image before kill the image, as I told you in my previous message.

toni-moreno avatar Mar 21 '20 09:03 toni-moreno

enc.input.Close() works fine, but it didnot work well in a exec.Command goroutine. The file will get moov atom not found error, this is lseek did not return the right filesize, cause the ffmpeg think he did not get the file. I will try go-ffmpeg.

liuzheng avatar Mar 22 '20 12:03 liuzheng

enc.input.Close() will force ffmpeg to properly close the file. I can confirm this works.

saily avatar Oct 24 '20 22:10 saily