Open Darkroll76 opened 4 years ago
Is it possible to send frames already decoded by FFmpeg instead of forwarding packet? If yes, any idea in which function I should take it and write it to a socket?
(sorry, I don't have much time right now to review)
Is it possible to send frames already decoded by FFmpeg instead of forwarding packet?
That's a bad idea, the decoded frames are way bigger than the encoded ones. You want to transmit the encoded stream, and decode on the client.
ΒΉ For example, in YUV 4:2:0 at 8 bit/color, each pixel takes 16 bits. In 1920Γ1080, that's 4Mb/frame. At 60fps, 237Mb/s.
(sorry, I don't have much time right now to review)
Don't be sorry! You're very helpful with everyone so thank you π.
That's a bad idea, the decoded frames are way bigger than the encoded ones. You want to transmit the encoded stream, and decode on the client.
Ok haha, I asked because I'm having trouble decoding H264 stream on my client because I'm using C# with Unity 3D and, by this fact, it's more complicated to use FFmpeg library to decode since it's less documented and have some compatibility issues that's requiring additional development.
Note that if you just want to test your implementation of the --serve
option, you can just use VLC as client:
vlc --demux h264 tcp://localhost:1234
(the latency will be higher because VLC bufferizes, but it should work)
The behavior of the --serve
option should be ~ the same as:
# listen on localhost:1234 and stream the ouput of screenrecord
adb exec-out screenrecord --output-format h264 - | nc -l -p 1234
@Darkroll76 I hope you make progress with this important feature! I don't have so advanced C knowledge, so I won't be able to help you. Anyway, Good Luck!
@Darkroll76 I am also working on this feature... https://github.com/dedosmedia/scrcpy/tree/h264 This is what I have till now, it's almost the same as you.
@rom1v When I launch scrcpy, it will wait for a connection to port 27184 (the default, but can be overwritten by --serve PORT). Once that I launch:
vlc --demux h264 tcp://localhost:27184
scrcpy continues its process and launch SDL_Window, where I can see my phone screen, however, VLC does not play anything.
When I do the same, but using Putty (raw mode, port 27184). I can see that I receive a lot of garbage, much more when I handle my screen's phone.
Maybe we are not sending the right thing. Excuse but I don't understand anything about AVFrame, AVPacket, frame, pts, header... etc I am using the code @Darkroll76 used for doing it:
ok = stream_push_packet(stream, &packet);
net_send(ClientSocket, packet.buf, packet.size);
av_packet_unref(&packet);
Maybe we are not sending the right thing... I know you are busy with other matters, however, if you have a few free minutes, please give us a hand to get this working. Thanks in advanced
[UPDATE]
Hi,
I almost did it. @dedosmedia I changed to packet.data
instead. I'm about to create a fork today.
For now, only TCP, "localhost" and the port are taken as parameters.
I gave the possibility the display the screen (or not) independently from --serve
option. So, in order to only forward the stream, we should specify scrcpy --serve tcp:localhost:1234 --no-display
.
@rom1v What about allowing recording and serve at the same time?
TODO:
char *IP
to uint32_t
(Currently just checking if it's "localhost", then I set value to IPV4_LOCALHOST
)serve
, but when I stop the process by force, MSYS is crashing. I guess it's because It's not closing properly.accept()
is called only one time for testing)IDEAS:
--serve
to --forward-to
or --forward-on
could be more clear about what it's doing ? I changed to
packet.data
instead
Good catch :)
What about allowing recording and serve at the same time?
Yes, serve
will not prevent recording.
(and it should be done from another thread, not to block the stream on blocking calls).
Allow also UDP
Nope, UDP does not guarantee packet ordering and does not retransmit lost packets, so the stream will be corrupted as soon as one of these events occur.
[UPDATE] Here is the fork and branch: https://github.com/Darkroll76/scrcpy/tree/serve
Yes, serve will not prevent recording.
Ok, I was wondering if it should be allowed or not.
Nope, UDP does not guarantee packet ordering and does not retransmit lost packets, so the stream will be corrupted as soon as one of these events occur.
So, we can remove tcp as parameter: --serve IP:PORT
So, we can remove tcp as parameter:
--serve IP:PORT
For now, we can. In theory, we could also serve over other protocols (http://
, rtsp://
β¦).
Very interesting idea!
I simply viewed the code, there are several coding style needs to be refined.
For example,
if
, while
etc.After feature completed, I suggest to fix coding style before sending PR.
Overall, I like this idea, we can build some application after supporting this feature. And it can be a temporary workaround before libscrcpy
finishing.
It's a great feature for streaming to OBS without opening a scrcpy window too :wink:
@npes87184 Are you talking about the code shown in my first post? Because it was just for testing. Thanks for this quick review π
It works now! Although sometimes after some seconds the video on VLC becomes "corrupted", anyway the video on scrcpy window is always fine. I suppose it's due to VLC because of its buffering.
You both Rock guys!
It works now!
:+1:
It's a great feature for streaming to OBS without opening a scrcpy window too :wink:
Arf, it does not work: OBS supports opening a stream from VLC, but not adding extra parameters (--demux h264
). :disappointed:
hi, thanks a lot for your work. can I ask for a feature package this (tcp) h264 stream into a v4l-like video capture device which can then be used by any application like skype, zoom, obs, etc.
@solnyshok Yes, I thought there was already a feature request for that, but I didn't find it.
Could you create one please?
I'm really looking forward to this feature. Can't wait to use it on my website :D
Ok haha, I asked because I'm having trouble decoding H264 stream on my client because I'm using C# with Unity 3D and, by this fact, it's more complicated to use FFmpeg library to decode since it's less documented and have some compatibility issues that's requiring additional development.
Hello
I am trying to implement a scrcpy in c# to extend some functionality in a familiar environment. But, there are some problems with video decoding. Have you found a good solution to decode and show raw h264 in c#? I've tried https://github.com/qaisbayabani/SCRCPY-C-Sharp-Client, but it doesn't seem stable enough. Perhaps you could share some examples, or thoughts about this?
Ok haha, I asked because I'm having trouble decoding H264 stream on my client because I'm using C# with Unity 3D and, by this fact, it's more complicated to use FFmpeg library to decode since it's less documented and have some compatibility issues that's requiring additional development.
Hello
I am trying to implement a scrcpy in c# to extend some functionality in a familiar environment. But, there are some problems with video decoding. Have you found a good solution to decode and show raw h264 in c#? I've tried https://github.com/qaisbayabani/SCRCPY-C-Sharp-Client, but it doesn't seem stable enough. Perhaps you could share some examples, or thoughts about this?
I have the same problem as you, did you resolve this? I mean to decode and show raw h264 in c#.
Ok haha, I asked because I'm having trouble decoding H264 stream on my client because I'm using C# with Unity 3D and, by this fact, it's more complicated to use FFmpeg library to decode since it's less documented and have some compatibility issues that's requiring additional development.
Hello I am trying to implement a scrcpy in c# to extend some functionality in a familiar environment. But, there are some problems with video decoding. Have you found a good solution to decode and show raw h264 in c#? I've tried https://github.com/qaisbayabani/SCRCPY-C-Sharp-Client, but it doesn't seem stable enough. Perhaps you could share some examples, or thoughts about this?
I have the same problem as you, did you resolve this? I mean to decode and show raw h264 in c#.
No. I am still using ffmpeg. But it sometimes crashes and so I have to reset the connection. All the wrapper libraries I've tried have similar problems and none have proven to be stable enough. Reducing the frame rate slightly improves the situation. Maybe you need to understand the structure of the incoming H264 and write your own wrapper or decoder. If you or someone else comes up with a solution, please let me know.
Hello,
Would this work help for https://github.com/Genymobile/scrcpy/issues/1939#issuecomment-811193380 ?
Regards,
Hi, Could you tell me how to build from your source on mac ? Thanks
https://github.com/qaisbayabani/SCRCPY-C-Sharp-Client is 100% stable now and also without adb server and client updated on git
Ok haha, I asked because I'm having trouble decoding H264 stream on my client because I'm using C# with Unity 3D and, by this fact, it's more complicated to use FFmpeg library to decode since it's less documented and have some compatibility issues that's requiring additional development.
Hello
I am trying to implement a scrcpy in c# to extend some functionality in a familiar environment. But, there are some problems with video decoding. Have you found a good solution to decode and show raw h264 in c#? I've tried https://github.com/qaisbayabani/SCRCPY-C-Sharp-Client, but it doesn't seem stable enough. Perhaps you could share some examples, or thoughts about this?
UPDATE now its Stable
yup
Hi everyone,
Following this post: #1073 and suggested by @rom1v, I started to work on an option
--serve
. This option would allow forwarding the video stream to any clients connected. It could be a C# Unity App, Java App or C# UWP App or whatever.The command would be
--serve tcp:localhost:1234
It could be a great solution for people like me, who wants to display the video stream inside a desktop application without redeveloping and rebuilding the scrcpy client in the desired language.
I create this post to give some updates and request some help in C development.
Following these indications :
So, we create another socket (for testing, we're using localhost and port 27015) In
stream.c -> run_stream(void *data)
We 're not sure that we are sending the right thing yet but this is our first step. Everyone who wants to help is welcomed π !
Thanks,