facebookresearch / facebookresearch/co-tracker
mediapy.write_video() fails with libx265 and qp parameter in gradio_demo Describe the issue
- Dominant language
- Jupyter Notebook
- Stars
- 5.1k
- Forks
- 389
- PR merge metrics
- No merged PRs in 30d
Description
Bug Report: mediapy.write_video() fails with libx265 and qp parameter in gradio_demo Describe the issue When running python -m gradio_demo.app locally to annotate video points via the web UI, the app crashes after selection with a BrokenPipeError followed by a RuntimeError, pointing to a problem with mediapy.write_video().
Reproduction steps
Start the app with:
python -m gradio_demo.app
Open the app in browser, annotate points.
The following output appears in terminal:

What I tried
I verified my FFmpeg version supports libx265 and -qp

Manually running ffmpeg works just fine:

I tried modifying app.py to use:
mediapy.write_video(
video_file_path,
painted_video,
fps=video_fps,
codec='libx265',
qp=28,
encoded_format='yuv420p',
ffmpeg_args=['-preset', 'medium']
)
But I still get the same error.
Expected behavior
The video should be written to disk using libx265 with QP encoding without any crash.
Environment
OS: Ubuntu (inside container)
Python: 3.10
Mediapy: latest (as installed with the project)
FFmpeg: 7.0.2 (static build) with --enable-libx265
Additional context
From looking into the source code, it seems like mediapy is failing to correctly pass -qp when libx265 is specified. This results in a broken pipe when writing video, possibly due to an invalid command construction passed to ffmpeg under the hood.
What would help
A fix in mediapy or a recommended way to safely pass -qp to ffmpeg through mediapy.write_video() — or guidance on how to bypass mediapy safely while staying inside the gradio app.
Thank you for the great tool and your help!
Contributor guide
Research direction
Start by running `python -m gradio_demo.app` and reproducing the crash after annotating points. Read the `app.py` call to `mediapy.write_video()` and compare its arguments with the working manual FFmpeg command; done means the annotated video is written with libx265 and QP encoding without BrokenPipeError or RuntimeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100