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

Project quality? #1976

Closed
sausix opened this issue May 20, 2023 · 7 comments
Closed

Project quality? #1976

sausix opened this issue May 20, 2023 · 7 comments
Labels
question Questions regarding functionality, usage tooling Apps, integrations, workflows, tools... relevant to the maintenance of this project/repo.

Comments

@sausix
Copy link

sausix commented May 20, 2023

I've opened this project in PyCharm and a lot of problems appeared immediately. Mostly docstrings out of date, type mismatches and strange decorator usages.

Most Python devs don't know about type hinting and annotations. Programming in Python should never be guessing function or method names. It's not that hard to implement! Typing is fun and locates issues early in a project. Hinting and annotations were requested at least twice! #1695 and #1912 but received not even a reply!

Docstrings out of date examples:
image

And here:
image

Other issues:

  • file descriptors hinted as int? Why?
  • Bad example files: AttributeError: 'VideoFileClip' object has no attribute 'set_pos'
  • Why "hacking" functions like resize in that way into VideoClips etc.?

Very sad, because a lot of work has been done here obviously.

Anyway. I've started my own project instead of using moviepy. In a more pythonic way.

@sausix sausix added the question Questions regarding functionality, usage label May 20, 2023
@batmanscode
Copy link

@sausix what's your project? Is it available to use?

@sausix
Copy link
Author

sausix commented May 24, 2023

@batmanscode It's still in dev state and does not output video yet.
I'm on it for a few days from scratch now and still on hardening a general and usefull concept.
After simple examples give an output I'll push it of course.

Here's my feature list so far:

# Features
- Templating and automation
- Parallel processing and caching on rendering if possible
- Immutable Clips
- "KISAP"? - Keep it simple and pythonic.
- No expensive processing within Python. ffmpeg's internal processing is on priority.
- Not reinventing the wheel. External tools are perfect and keep the project's code small and clean.


# ToDo
- resolution & fps vs. cache?
- Stream interface for Clip classes
- Transitions with \_\_add__()
- Encoder interface
- Jupyter integration?
- Docs and tests :-)
- Get community, feedback and love :-)


# Clip ToDo
- FFmpeg base
- Transform
- Filter
- Crossfade
- ClipSequence compare formats

# Roadmap
- Optional UI managing and helping with the python code.
- Animations, vector based (+motion blur)

Here's a sneak peek containing the principle and syntax for a video project:

# Define cache before first Clip instance or else it will
#   be created implicitly as "cwd/cache"
cache = Cache("/tmp/project.cache", discard_missing=True)  # Or define a non volatile place
# discard_missing should be True on project caches (default)
#   and False on global caches for multiple projects.

# Assign the cache to the base class for all clips
Clip.set_root_cache(cache)

# Project constants
fps = 60
resolution = 1920, 1080

# Static sources
intro = FileClip("/home/user/intro.mpv")  # Missing
outro = FileClip("outro.mpv")  # Missing

# Images
agenda = ImageFromFile("/home/as/Screenshot_20201207_064554.png")
# print(agenda.size)
# print(agenda.format)

# Video files
video1 = FileClip("/home/as/Rick Astley - Never Gonna Give You Up.mp4", master_format=True)
# master_format: This format will be preferred for other clips.
print(video1)  # <FileClip:/home/as/Rick Astley - Never Gonna Give You Up.mp4>
print(video1.video_format)  # VideoFormat(codec_name='av1', codec_type='video', codec_tag_string='av01', profile='Main', time_base='1/12800', width=1920, height=1080, coded_width=1920, coded_height=1080, pix_fmt='yuv420p', r_frame_rate='25/1', level=8)
print(video1.audio_format)  # AudioFormat(codec_name='aac', codec_type='audio', codec_tag_string='mp4a', profile='LC', time_base='1/44100', channels=2, channel_layout='stereo', sample_fmt='fltp', sample_rate='44100')


video2 = FileClip("testmedia/x264-1080p60.mkv")
print(video2)  # <FileClip[V]:testmedia/x264-1080p60.mkv>
print(video2.video_format)  # VideoFormat(codec_name='h264', codec_type='video', codec_tag_string='[0][0][0][0]', profile='High 4:4:4 Predictive', time_base='1/1000', width=1920, height=1080, coded_width=1920, coded_height=1080, pix_fmt='yuv444p', r_frame_rate='60/1', level=50)
print(video2.audio_format)  # None


# Do some simple magic with clips
mainvideo = video1 * 2 + video2

def make_video_as_always(main: Clip) -> Clip:
    """
    Helper function to compose a full video.
    Just add the main clip
    """

    # ToDo: Crossfades
    # return intro + Crossfade(duration=1) + ImageClip(agenda, 2.) + main + Crossfade(duration=1) + outro
    return intro + ImageClip(agenda, 2.) + main + outro


final_video = make_video_as_always(mainvideo)
print(final_video)  # Gives repr()
# <ClipSequence:⇻(<FileClip[?]:/home/user/intro.mpv>, <ImageClip[V]:2.0s:<ImageFromFile:/home/as/Screenshot_20201207_064554.png>>, <FileClip:/home/as/Rick Astley - Never Gonna Give You Up.mp4>, <FileClip:/home/as/Rick Astley - Never Gonna Give You Up.mp4>, <FileClip[V]:testmedia/x264-1080p60.mkv>, <FileClip[?]:outro.mpv>)>

final_video.render("/tmp/test.mkv", resolution, fps)
# Will use multiple processes
# Make use of cache if available or at least create it for the next run

@batmanscode
Copy link

Wow that looks great! Looking forward to using it @sausix, good luck with the rest of the development

The video magic is very cool! And I appreciate the "Not reinventing the wheel" and "keep the project's code small and clean" 🙂

@mgaitan
Copy link
Collaborator

mgaitan commented May 24, 2023

  • The concatenation of clips (video1 + video2 ) plus several other goodies, has been included moviepy in Implement basic data model #1076. It's currently waiting some feedback so we can include that in moviepy 2.0 . Could you give it a try?

  • Type hints #1962 is a first effort to add typing annotation to the codebase

  • IMHO @sausix you project looks very promising. But also consider if it woudn't be better to actively contribute to moviepy. It is a project that has a huge user base but there are very few of us who can maintain and contribute to the project and we agree that it has many problems. The effort to achieve a version 2.0 to modernize the API and the quality of the code has been going on for years and has not yet materialized for this reason.

On the other hand, maybe you just wanted to give your opinion and you didn't need to check what was the state of things (for example those two prs I mentioned are very recent).

@sausix
Copy link
Author

sausix commented May 25, 2023

@mgaitan I always prefer colaboration instead of forking or creating a new projects.

But...
moviepy codebase is quite old and improving standards seems to be a problem already.

  • Clip concatenation seems to be unwanted by Zulko. And I want to add crossovers also into it.
  • Just adding type hints seems to cause a lot of problems.

I know moviepy has a lot of work inside and a lot of users. But I've browsed the code and had a lot of "ooof" moments.
Current moviepy seems to be hard to maintain already. And maintainers seem to be breaking off or too busy forever.
moviepy 2.0 would be a lot of work and break compatibility as mentioned anyway.

So why not making a deeper cut?
I only see a complete rework as a promising solution.
My project follows some complete different directions like immutability of clips, caching and intelligent remuxing or reencoding.

Maybe my project will be moviepy 2.0?
Don't get me wrong. I don't want to steal the name or something. And i'ts not bragging with fancy, better or whatever type of code. And I don't want to destroy this project of course.

Anyway. I've pushed my code as dev preview. Rendering is not yet implemented.
I'm currently still working on concepts how Clip subclasses should provide their streams including caching.

https://github.com/sausix/scriptycut
Around 40 hrs of work including a lot of investigation for multi platform support like "Windows vs. Pipes" :-(

@mgaitan
Copy link
Collaborator

mgaitan commented May 25, 2023

@sausix excellent, thanks for sharing. I'll be around looking for your progress.

Regarding ffmpeg rendering (and reading), and in the spirit of "not reinventing the wheel", I'd recommended you to take a look to imageio v3 , that's something we would like for movipy itself.

#1957 (comment)

@sausix
Copy link
Author

sausix commented May 25, 2023

@mgaitan Thanks. I'm using imageio.v3 already in image.py.
I'll probably not use the ffmpeg wrapper of imageio because it does not do a lot of magic stuff.

I'll try not to use imageio for every rendering process. ffmpeg as as ton of filters, effects and transistions.

@mgaitan mgaitan closed this as completed May 25, 2023
@keikoro keikoro added the tooling Apps, integrations, workflows, tools... relevant to the maintenance of this project/repo. label Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions regarding functionality, usage tooling Apps, integrations, workflows, tools... relevant to the maintenance of this project/repo.
Projects
None yet
Development

No branches or pull requests

4 participants