Video editing with Python
Ignore max line length in flake8 linter as black already force 88 chars when possible
osaajanifba35f2d904a
diff --git a/.github/workflows/formatting_linting.yml b/.github/workflows/formatting_linting.ymlindex eacf31d9..3cb57644 100644--- a/.github/workflows/formatting_linting.yml+++ b/.github/workflows/formatting_linting.yml@@ -47,7 +47,7 @@ jobs:- name: Show Flake8 versionrun: flake8 --version- name: Run Flake8- run: flake8 -v --show-source --max-line-length=92 moviepy docs/conf.py examples tests+ run: flake8 -v --show-source --ignore=E501 moviepy docs/conf.py examples testsisort:name: isort import sorterdiff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 3a7759f7..23a5ff4f 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -22,6 +22,6 @@ repos:- flake8-rst-docstrings>=0.3- flake8-implicit-str-concat==0.4.0args:- - --max-line-length=92+ - --ignore=E501 # Black will force a line length of 88 when possiblename: flake8-testfiles: \.py$diff --git a/docs/_static/code/getting_started/moviepy_10_minutes/trailer.py b/docs/_static/code/getting_started/moviepy_10_minutes/trailer.pyindex 00adda81..571819c4 100644--- a/docs/_static/code/getting_started/moviepy_10_minutes/trailer.py+++ b/docs/_static/code/getting_started/moviepy_10_minutes/trailer.py@@ -1,7 +1,8 @@# Lets import moviepy, lets also import numpy we will use it a some point-from moviepy import *import numpy as np+from moviepy import *+################## VIDEO LOADING #@@ -199,13 +200,28 @@ bunny_clip = bunny_clip.with_effects([vfx.FadeIn(1), vfx.FadeOut(1), afx.AudioFadeIn(1), afx.AudioFadeOut(1)])rodents_clip = rodents_clip.with_effects(- [vfx.FadeIn(1), vfx.CrossFadeOut(1.5), afx.AudioFadeIn(1), afx.AudioFadeOut(1.5)]+ [+ vfx.FadeIn(1),+ vfx.CrossFadeOut(1.5),+ afx.AudioFadeIn(1),+ afx.AudioFadeOut(1.5),+ ]) # Just fade in, rambo clip will do the cross faderambo_clip = rambo_clip.with_effects(- [vfx.CrossFadeIn(1.5), vfx.FadeOut(1), afx.AudioFadeIn(1.5), afx.AudioFadeOut(1)]+ [+ vfx.CrossFadeIn(1.5),+ vfx.FadeOut(1),+ afx.AudioFadeIn(1.5),+ afx.AudioFadeOut(1),+ ])rambo_clip = rambo_clip.with_effects(- [vfx.CrossFadeIn(1.5), vfx.FadeOut(1), afx.AudioFadeIn(1.5), afx.AudioFadeOut(1)]+ [+ vfx.CrossFadeIn(1.5),+ vfx.FadeOut(1),+ afx.AudioFadeIn(1.5),+ afx.AudioFadeOut(1),+ ])# Effects are not only for transition, they can also change a clip timing or appearancediff --git a/docs/_static/code/user_guide/compositing/juxtaposing.py b/docs/_static/code/user_guide/compositing/juxtaposing.pyindex 3f032643..61413967 100644--- a/docs/_static/code/user_guide/compositing/juxtaposing.py+++ b/docs/_static/code/user_guide/compositing/juxtaposing.py@@ -2,6 +2,7 @@from moviepy import VideoFileClip, clips_array, vfx+# We will use the same clip and transform it in 3 waysclip1 = VideoFileClip("example.mp4").with_effects([vfx.Margin(10)]) # add 10px contourclip2 = clip1.with_effects([vfx.MirrorX()]) # Flip horizontalydiff --git a/docs/_static/code/user_guide/compositing/with_position.py b/docs/_static/code/user_guide/compositing/with_position.pyindex 9fca3ec4..af8ec7cb 100644--- a/docs/_static/code/user_guide/compositing/with_position.py+++ b/docs/_static/code/user_guide/compositing/with_position.py@@ -1,6 +1,7 @@"""Let's position some text and images on a video."""-from moviepy import TextClip, VideoFileClip, CompositeVideoClip, ImageClip+from moviepy import CompositeVideoClip, ImageClip, TextClip, VideoFileClip+# We load all the clips we want to composebackground = VideoFileClip("example2.mp4").subclipped(0, 2)diff --git a/docs/_static/code/user_guide/loading/UpdatedVideoClip.py b/docs/_static/code/user_guide/loading/UpdatedVideoClip.pyindex 7959fc36..3c1aa9d7 100644--- a/docs/_static/code/user_guide/loading/UpdatedVideoClip.py+++ b/docs/_static/code/user_guide/loading/UpdatedVideoClip.py@@ -1,7 +1,9 @@-from moviepy import UpdatedVideoClip-import numpy as npimport random+import numpy as np++from moviepy import UpdatedVideoClip+class CoinFlipWorld:"""A simulation of coin flipping.@@ -9,7 +11,8 @@ class CoinFlipWorld:Imagine we want to make a video that become more and more red as we repeat same faceon coinflip in a row because coinflip are done in real time, we need to waituntil a winning row is done to be able to make the next frame.- This is a world simulating that. Sorry, it's hard to come up with examples..."""+ This is a world simulating that. Sorry, it's hard to come up with examples...+ """def __init__(self, fps):"""diff --git a/docs/_static/code/user_guide/loading/VideoClip.py b/docs/_static/code/user_guide/loading/VideoClip.pyindex 5952af35..5a3a5f5f 100644--- a/docs/_static/code/user_guide/loading/VideoClip.py+++ b/docs/_static/code/user_guide/loading/VideoClip.py@@ -1,7 +1,10 @@-from PIL import Image, ImageDraw+import math+import numpy as np+from PIL import Image, ImageDraw+from moviepy import VideoClip-import math+WIDTH, HEIGHT = (128, 128)RED = (255, 0, 0)diff --git a/docs/_static/code/user_guide/loading/VideoFileClip.py b/docs/_static/code/user_guide/loading/VideoFileClip.pyindex 297af717..25f302b4 100644--- a/docs/_static/code/user_guide/loading/VideoFileClip.py+++ b/docs/_static/code/user_guide/loading/VideoFileClip.py@@ -1,5 +1,6 @@from moviepy import VideoFileClip+myclip = VideoFileClip("example.mp4")# video file clips already have fps and durationdiff --git a/docs/_static/code/user_guide/loading/loading.py b/docs/_static/code/user_guide/loading/loading.pyindex 3ebc677e..db39dbf0 100644--- a/docs/_static/code/user_guide/loading/loading.py+++ b/docs/_static/code/user_guide/loading/loading.py@@ -1,14 +1,16 @@+import numpy as np+from moviepy import (- VideoClip,- VideoFileClip,- ImageSequenceClip,+ AudioClip,+ AudioFileClip,+ ColorClip,ImageClip,+ ImageSequenceClip,TextClip,- ColorClip,- AudioFileClip,- AudioClip,+ VideoClip,+ VideoFileClip,)-import numpy as np+# Define some constants for later useblack = (255, 255, 255) # RGB for blackdiff --git a/docs/_static/code/user_guide/loading/masks.py b/docs/_static/code/user_guide/loading/masks.pyindex a58f48de..cfc876ee 100644--- a/docs/_static/code/user_guide/loading/masks.py+++ b/docs/_static/code/user_guide/loading/masks.py@@ -1,6 +1,8 @@-from moviepy import VideoClip, ImageClip, VideoFileClipimport numpy as np+from moviepy import ImageClip, VideoClip, VideoFileClip++# Random RGB noise image of 200x100frame_function = lambda t: np.random.rand(100, 200)diff --git a/docs/_static/code/user_guide/rendering/preview.py b/docs/_static/code/user_guide/rendering/preview.pyindex a7de2230..26039537 100644--- a/docs/_static/code/user_guide/rendering/preview.py+++ b/docs/_static/code/user_guide/rendering/preview.py@@ -1,5 +1,6 @@from moviepy import *+myclip = VideoFileClip("./example.mp4").subclipped(0, 1) # Keep only 0 to 1 sec# We preview our clip as a video, inheriting FPS and audio of the original clipdiff --git a/docs/developer_guide/developers_install.rst b/docs/developer_guide/developers_install.rstindex 7c19e5c9..70e8a640 100644--- a/docs/developer_guide/developers_install.rst+++ b/docs/developer_guide/developers_install.rst@@ -50,7 +50,7 @@ and.. code:: bash- $ python3 -m flake8 -v --show-source --max-line-length=92 moviepy docs/conf.py examples tests+ $ python3 -m flake8 -v --show-source --ignore=E501 moviepy docs/conf.py examples testsAdding Git pre-commit hooks-----------------------------diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.pyindex e3a19569..be20b99c 100644--- a/tests/test_ffmpeg_reader.py+++ b/tests/test_ffmpeg_reader.py@@ -833,5 +833,65 @@ def test_frame_seek():assert not np.array_equal(frame, frame2)+def test_side_data():+ infos = """Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/ajani/Téléchargements/10CAE6A8-1A7A-488F-8DDD-691F0242A5BD_L0_001_1748075354.671342_o_IMG_1977.MOV':+ Metadata:+ major_brand : qt+ minor_version : 0+ compatible_brands: qt+ creation_time : 2025-05-24T08:27:14.000000Z+ com.apple.quicktime.location.accuracy.horizontal: 15.257182+ com.apple.quicktime.full-frame-rate-playback-intent: 0+ com.apple.quicktime.location.ISO6709: +37.8187+127.0583+097.529/+ com.apple.quicktime.make: Apple+ com.apple.quicktime.model: iPhone 14+ com.apple.quicktime.software: 18.3.2+ com.apple.quicktime.creationdate: 2025-05-24T17:27:14+0900+ Duration: 00:00:16.10, start: 0.000000, bitrate: 8764 kb/s+ Stream #0:0(und): Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67), 1920x1080, 8540 kb/s, 30 fps, 30 tbr, 600 tbn, 600 tbc (default)+ Metadata:+ rotate : 90+ creation_time : 2025-05-24T08:27:14.000000Z+ handler_name : Core Media Video+ vendor_id : [0][0][0][0]+ encoder : HEVC+ Side data:+ DOVI configuration record: version: 1.0, profile: 8, level: 4, rpu flag: 1, el flag: 0, bl flag: 1, compatibility id: 4+ displaymatrix: rotation of -90.00 degrees+ Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 157 kb/s (default)+ Metadata:+ creation_time : 2025-05-24T08:27:14.000000Z+ handler_name : Core Media Audio+ vendor_id : [0][0][0][0]+ Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)+ Metadata:+ creation_time : 2025-05-24T08:27:14.000000Z+ handler_name : Core Media Metadata+ Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)+ Metadata:+ creation_time : 2025-05-24T08:27:14.000000Z+ handler_name : Core Media Metadata+ Stream #0:4(und): Data: none (mebx / 0x7862656D), 42 kb/s (default)+ Metadata:+ creation_time : 2025-05-24T08:27:14.000000Z+ handler_name : Core Media Metadata+ Stream #0:5(und): Data: none (mebx / 0x7862656D), 2 kb/s (default)+ Metadata:+ creation_time : 2025-05-24T08:27:14.000000Z+ handler_name : Core Media Metadata+ Stream #0:6(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)+ Metadata:+ creation_time : 2025-05-24T08:27:14.000000Z+ handler_name : Core Media Metadata+"""++ d = FFmpegInfosParser(infos, "foo.mov").parse()+ assert d["blocks"].childs[1].childs[1].type == "side_data"+ assert (+ d["blocks"].childs[1].childs[1].data["DOVI configuration record"]+ == "version: 1.0, profile: 8, level: 4, rpu flag: 1, el flag: 0, bl flag: 1, compatibility id: 4"+ )++if __name__ == "__main__":pytest.main()