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

I am having a problem trying to send camera stream to srt server (vMix) #13

Closed
jjcetraro opened this issue Dec 24, 2020 · 3 comments
Closed

Comments

@jjcetraro
Copy link

jjcetraro commented Dec 24, 2020

I am trying to send my device camera stream to a srt server I have on my laptop. The code I am using is the following:

Srt srt = new Srt();
srt.startUp();

// create SRT socket to send stream
Socket clientSocket = new Socket();
clientSocket.setSockFlag(SockOpt.TRANSTYPE, Transtype.LIVE);
// connect socket to srt server (vMix running on my laptop)
clientSocket.connect("192.168.43.50", 11001);

// create udp listening on 0.0.0.0:7800
new Thread(new Runnable() {
	@Override
	public void run() {
		byte[] data;
		try{
			byte[] buffer = new byte[1316];
			DatagramSocket socketUDP = new DatagramSocket(7800);
			while(true){
				DatagramPacket udpPacket = new DatagramPacket(buffer, buffer.length);
				socketUDP.receive(udpPacket);
				data = udpPacket.getData();
				// send received data to srt server
				clientSocket.send(data);
			}
		}catch (Exception ex){}
	}
}).start();

// I use ffmpeg to capture android camera, and stream it to socketUDP
int rc = FFmpeg.execute("-f android_camera -video_size 320x240 -input_queue_size 60 -i 0:0 -r 30 -f h264 udp://0.0.0.0:7800");

As you can see, the code is pretty simple. I do not know why it doesn't work. I think that the problem is on the srt socket settings.

If I send the android camera directly by udp to my laptop, and use ffplay on my laptop to see it, it works fine. So I think the ffmpeg command is ok.

Another interesting thing is that if I stream my android camera using the app Larix Broadcaster, it works fine (I can see the camera on my laptop using vMix)

Last but not less important, when I run the code above, It doesn't crash, and despite I can't see the camera on vMix, if I open on vMix the statistics dialog, I can see that the vMix is receiving data from my device.

@ThibaultBee
Copy link
Owner

Hi,
Do you have anything in logcat? By the way, can you log the exception?

@jjcetraro
Copy link
Author

Dear ThibaultBee, thanks for your answer. Yesterday I solved the problem. The problem was the ffmpeg command I was using. I repleace the command with a new one, and now it works perfectly. This is the new ffmpeg command I am using:

-f android_camera -video_size 320x240 -input_queue_size 60 -i 0:0 -pix_fmt yuv420p -c:v libx264 -b:v 1000k -g 30 -keyint_min 120 -profile:v baseline -preset veryfast -f mpegts "udp://0.0.0.0:7800?pkt_size=1316"

Thanks again! This project is great!

It really is a big help. I had a lot of troubles trying to build haivision/srt for Android

Best regards, and merry christmas!

@ThibaultBee
Copy link
Owner

Glad to hear that !

By the way, you can use:
socket.getSockFlag(SockOpt.PAYLOADSIZE)
to get the payload size
Also, you can use OutputStream instead of send() which is the Java/Android way to send network packet.

Best regards and best wishes!

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