Skip to content

add support for mp4 + audio and screen_recorder.py rewritted to use FFMPEG #416

Open
RgeditV1 wants to merge 1 commit into
Baekalfen:masterfrom
RgeditV1:screen-recorder
Open

add support for mp4 + audio and screen_recorder.py rewritted to use FFMPEG #416
RgeditV1 wants to merge 1 commit into
Baekalfen:masterfrom
RgeditV1:screen-recorder

Conversation

@RgeditV1
Copy link
Copy Markdown

@RgeditV1 RgeditV1 commented May 5, 2026

patch for: #368

  • add full support for mp4 + audio

  • add new hotkey U for toggle mp4 recording

  • screen recorder backend rewritted to FFMPEG

GIF

POKEMON RED-2026 05 05-15 54 51

MP4

POKEMON.RED-2026.05.05-15.54.24.mp4

UNIT TEST TRACE

uv run python -m pytest -s -vv test_screen_recorder.py  

============================================= test session starts ==============================================
platform linux -- Python 3.11.15, pytest-9.0.3, pluggy-1.6.0 -- /home/rgedit/Documentos/repo/PyBoy/.venv/bin/python3
cachedir: .pytest_cache
benchmark: 5.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/rgedit/Documentos/repo/PyBoy
configfile: pyproject.toml
plugins: xdist-3.8.0, benchmark-5.2.3, lazy-fixtures-1.4.0
collected 2 items                                                                                              

test_screen_recorder.py::test_screen_recorder_gif_ffmpeg_pipeline [screen-recorder-test] Starting GIF recorder flow
[screen-recorder-test] Toggle ON GIF recording
[screen-recorder-test] Toggle OFF GIF recording
[screen-recorder-test] Captured 2 ffmpeg calls for GIF
[screen-recorder-test] GIF call #1 args: ['/usr/bin/ffmpeg', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-s:v', '160x144', '-r', '60', '-i', './recordings/screenrec-53vs8olz/video.rgba', '-vf', 'fps=60,palettegen=stats_mode=diff', './recordings/screenrec-53vs8olz/palette.png']
[screen-recorder-test] GIF call #2 args: ['/usr/bin/ffmpeg', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-s:v', '160x144', '-r', '60', '-i', './recordings/screenrec-53vs8olz/video.rgba', '-i', './recordings/screenrec-53vs8olz/palette.png', '-lavfi', 'fps=60[x];[x][1:v]paletteuse=dither=bayer:bayer_scale=3:diff_mode=rectangle', './recordings/DEFAULT-ROM-2026.05.05-16.46.31.gif']
[screen-recorder-test] GIF recorder flow finished
PASSED
test_screen_recorder.py::test_screen_recorder_mp4_with_audio [screen-recorder-test] Starting MP4 recorder flow
[screen-recorder-test] Toggle ON MP4 recording
[screen-recorder-test] Toggle OFF MP4 recording
[screen-recorder-test] Captured 1 ffmpeg calls for MP4
[screen-recorder-test] MP4 call args: ['/usr/bin/ffmpeg', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-s:v', '160x144', '-r', '60', '-i', './recordings/screenrec-breuoi5c/video.rgba', '-f', 's8', '-ar', '48000', '-ac', '2', '-i', './recordings/screenrec-breuoi5c/audio.s8', '-c:v', 'libx264', '-preset', 'veryfast', '-crf', '18', '-pix_fmt', 'yuv420p', '-c:a', 'aac', '-b:a', '128k', '-shortest', './recordings/DEFAULT-ROM-2026.05.05-16.46.31.mp4']
[screen-recorder-test] MP4 recorder flow finished
PASSED

============================================== 2 passed in 0.70s ===============================================

Copy link
Copy Markdown
Owner

@Baekalfen Baekalfen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. The only thing that doesn’t look right, is the gif. It seems like it’s dropping frames? It should be completely smooth 60 FPS, as we are storing every frame and playing it back with perfect timing.

Comment thread pyboy/plugins/screen_recorder.py Outdated
Comment thread pyboy/plugins/screen_recorder.py
Comment thread pyboy/plugins/screen_recorder.py
@RgeditV1
Copy link
Copy Markdown
Author

RgeditV1 commented May 9, 2026

i was watching the gif frame rate and now im sure its working now, i cant notice a drop frame rate, try dont use visual studio to watch the gif

PD: for some reason in file explorer its see fine but using visual studio and github see too slow

File Explorer:

screenrecording-2026-05-09_12-08-28.mp4

Github Version and Visual Studio

POKEMON RED-2026 05 09-12 04 23

@RgeditV1 RgeditV1 requested a review from Baekalfen May 11, 2026 00:21
Copy link
Copy Markdown
Author

@RgeditV1 RgeditV1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like its working fine for me

Comment thread pyboy/plugins/screen_recorder.py Outdated
Comment thread pyboy/plugins/screen_recorder.py
Comment thread pyboy/plugins/screen_recorder.py Outdated
@Baekalfen
Copy link
Copy Markdown
Owner

Baekalfen commented May 11, 2026

Ok, it seems it’s not dropping frames, rather the framerate is far too low. Maybe there’s some metadata that should be configured? I think that was initially an issue with the current implementation, but I fixed it somehow with different parameters.

The current GIFs work fine in Safari, while the one you sent might be around 10-15 FPS?
https://github.com/Baekalfen/PyBoy/blob/master/extras/README/1.gif

@RgeditV1
Copy link
Copy Markdown
Author

Ok, it seems it’s not dropping frames, rather the framerate is far too low. Maybe there’s some metadata that should be configured? I think that was initially an issue with the current implementation, but I fixed it somehow with different parameters.

The current GIFs work fine in Safari, while the one you sent might be around 10-15 FPS?
https://github.com/Baekalfen/PyBoy/blob/master/extras/README/1.gif

Yeah, your gif is fine right now
Pd: the workflows isnt working 😭😭😭

@RgeditV1
Copy link
Copy Markdown
Author

hope you could helpme with the workflows

@Baekalfen
Copy link
Copy Markdown
Owner

You can ignore the workflow for now. As long as the macOS ones are working, it’s just some setup

@RgeditV1
Copy link
Copy Markdown
Author

You can ignore the workflow for now. As long as the macOS ones are working, it’s just some setup

Take ur time for feedbacks
If you see something else, ill be here
🧐🧐

@Baekalfen
Copy link
Copy Markdown
Owner

Did you fix the frame rate issue? You can post a GIF here so I can verify, I’m not much at the computer these weeks

@RgeditV1
Copy link
Copy Markdown
Author

Did you fix the frame rate issue? You can post a GIF here so I can verify, I’m not much at the computer these weeks

there isnt frame rate issue, its working now, but when u open it with github or vscode it seems slow.

look at this

screenrecording-2026-05-09_12-08-28.mp4

its really working fine

@Baekalfen
Copy link
Copy Markdown
Owner

But it also has to work in Visual Studio. There's a small detail you're missing. Try opening extras/README/1.gif. This works fine in VSCode too.

The GIFs in the readme here on GitHub are recorded with this code, so it has to keep working on GitHub.

@RgeditV1
Copy link
Copy Markdown
Author

But it also has to work in Visual Studio. There's a small detail you're missing. Try opening extras/README/1.gif. This works fine in VSCode too.

The GIFs in the readme here on GitHub are recorded with this code, so it has to keep working on GitHub.

i think i got it

@RgeditV1
Copy link
Copy Markdown
Author

POKEMON RED-2026 05 14-12 07 18

# cannot be represented exactly and some players jitter or clamp playback.
# 50 FPS maps exactly to 2 centiseconds per frame and is broadly compatible.
# Finally DONE!!
GIF_FPS = 50
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s a good insight, and you might be onto something. But the current GIFs work fine at 60 fps, so there must be a way to configure it.

Copy link
Copy Markdown
Author

@RgeditV1 RgeditV1 May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been researching 60fps in GIFs and I understand that 60fps doesn't actually exist; Pillow uses a technique to create the illusion of 60fps.

I understand that 60 frames per second is not possible due to limitations of the GIF file in question.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can use pillow and ffmpeg at same time but in theroy will be the same thing
ill be waiting your answer to put my hand to work

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That’s surprising. Wonder how it’s done now.

Did you try this? Changing the delay per frame: https://superuser.com/a/1449427

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i did but isnt work

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, maybe just do the original plan and have a separate mp4 recorder? That should be easy, right?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate the effort you put into this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, maybe just do the original plan and have a separate mp4 recorder? That should be easy, right?

So, pillow=gif and ffmpeg=mp4?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, maybe just do the original plan and have a separate mp4 recorder? That should be easy, right?

I think it should be in same file

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, pillow=gif and ffmpeg=mp4?

Exactly. You can decide if it needs separate files

Signed-off-by: Rgeditv1 <rgeditv1@protonmail.com>
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

Successfully merging this pull request may close these issues.

2 participants