Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
110.15k stars 10.56k forks source link

How does scrcpy decode/display YUV420p frame? #3149

Open Saddingt0n opened 2 years ago

Saddingt0n commented 2 years ago

My apologies in advanced if this is not an appropriate place to ask.

I'm new to C programming, I know a little bit of C#. I'm very interested in scrcpy and want to play around with it.

I want to save images that scrcpy gets from Android devices as JPEG files in BGRA or some RGB pixel format. In this function in "screen.c":

static bool sc_screen_update_frame(struct sc_screen *screen) {

...
    AVFrame *frame = screen->frame;
...

}

I do this to get pixel format of that AVFrame:

const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);

And I see that the pixel format is: yuv420p. I'm having troubles converting YUV420p to other formats and saving AVFrame to file.

Can I set scrcpy to output frame in other format other than yuv420p and how does scrcpy decode this frame to get it to appear in the window? Can somebody give me some pointers or some documents to read, I would very much appreciate it. Thank you!

rom1v commented 2 years ago

The frame is decoded here (by ffmpeg).

The frame is uploaded to GPU here and presented here.

You could find examples about how to encode a frame to a jpeg for example (random link on google).

Saddingt0n commented 2 years ago

The frame is decoded here (by ffmpeg).

The frame is uploaded to GPU here and presented here.

You could find examples about how to encode a frame to a jpeg for example (random link on google).

Thank you! I'm not familiar with image/video stream so I haven't been able to decode the H264 stream sent from scrcpy-server to my client. Could you give me the general steps to do this?