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

Fix pixel_format in FFMPEG_VideoWriter #2359

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jhadida
Copy link

@jhadida jhadida commented Feb 3, 2025

  • I have provided code that clearly demonstrates the bug and that only works correctly when applying this fix
  • I have added suitable tests demonstrating a fixed bug or new/changed feature to the test suite in tests/
  • I have properly documented new or changed features in the documentation or in the docstrings
  • I have properly explained unusual or unexpected code in the comments around it

I will be going through the checkpoints above later on.

The main issues that this PR fixes are with the implementation of FFMPEG_VideoWriter:

  • The current implementation effectively disregards the pixel_format argument, and overrides it with either rgb24 or rgba.
  • The FFMPEG option -pix_fmt is duplicated in some cases.
  • The FFMPEG option -vcodec (or -c:v) is systematically duplicated.

This PR addresses these issues by honoring the pixel_format argument when it is not None regardless of other arguments. It also introduces an argument print_cmd to print the FFMPEG command to the terminal for debugging purposes.

@jhadida jhadida changed the title Move comment to the right spot Fix pixel_format in FFMPEG_VideoWriter Feb 3, 2025
@@ -1867,7 +1869,8 @@ def __find_text_size(
To summarize, the real height of the text is:
``initial padding + (lines - 1) * height + end padding``
or:
``(ascent + stroke_width) + (lines - 1) * height + (descent + stroke_width)``
``(ascent + stroke_width) + (lines - 1) * height
+ (descent + stroke_width)``
Copy link
Author

@jhadida jhadida Feb 3, 2025

Choose a reason for hiding this comment

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

Split the comment here to satisfy flake8 pre-commit hook.

@OsaAjani
Copy link
Collaborator

OsaAjani commented Feb 4, 2025

Hi, you are right in that pixel format is indeed not respected in the current implementation, many thanks for pointing this out.

This being said, I think you made a few errors. FFMPEG is a pretty uncommon cli tools, and some arguments can be duplicated to apply them either to input (before -i) or output (after -i) videos. In our case -vcodec should be duplicated, as well as -pix_fmt, though for the latest we should indeed honor the pixel_format argument for the output pix_fmt.

As for the print_cmd parameter, it's a good idea, but any new parameter should be documented in the function docstring.

Would you be willing to implement those changes ?

Copy link
Collaborator

@OsaAjani OsaAjani left a comment

Choose a reason for hiding this comment

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

Need a global rewrite to keep input and output params as well as fixing missing auto-alt-ref

@@ -226,6 +226,7 @@ def write_videofile(
ffmpeg_params=None,
logger="bar",
pixel_format=None,
print_cmd=False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be documented

@@ -111,12 +110,8 @@ def __init__(
"error" if logfile == sp.PIPE else "info",
"-f",
"rawvideo",
"-vcodec",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We actually need thoses

@@ -101,8 +102,6 @@ def __init__(
self.audio_codec = audio_codec
self.ext = self.filename.split(".")[-1]

pixel_format = "rgba" if with_mask else "rgb24"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should keep this logic, but change the variable name to avoid overriding the param

moviepy/video/io/ffmpeg_writer.py Show resolved Hide resolved
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