cutcutcodec 1.0.post3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cutcutcodec might be problematic. Click here for more details.
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/__init__.py +6 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/__main__.py +38 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/c_build.py +33 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/_helper_properties.py +52 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/properties/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/properties/duration.py +83 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/ffprobe.py +637 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/find.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/time_backprop.py +68 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/rate_audio.py +239 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/rate_video.py +97 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/shape.py +107 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/time_backprop.py +183 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/duration.py +162 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/nb_frames.py +159 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/rate.py +102 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/timestamps.py +194 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/container.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/encoder.py +152 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/filter.py +33 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame.py +127 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame_audio.py +205 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame_video.py +322 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/layout.py +206 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/meta_filter.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/muxer.py +184 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/node.py +164 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream.py +182 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream_audio.py +130 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream_video.py +193 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/__init__.py +7 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/ast_to_file.py +125 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/__init__.py +6 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/compatibility.py +734 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/default.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/encodec.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/muxer.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/rate.py +133 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_ast.py +477 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_json.py +104 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_tree.py +190 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/json_to_graph.py +114 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/parse.py +123 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/__init__.py +15 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/dynamic.py +544 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/lambdify.py +612 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/preprocess.py +698 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/printer.py +926 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/tree_to_graph.py +168 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/decision/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/add.py +73 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/remove.py +476 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/exceptions.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/add.py +170 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/cat.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/cut.py +112 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/delay.py +85 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/equation.py +261 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/fir.py +231 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/identity.py +48 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/resample.py +451 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/subclip.py +91 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/cut.py +74 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/audio_cast.py +208 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/video_cast.py +197 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/subclip.py +53 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/add.py +331 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/cat.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/cut.py +113 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/delay.py +84 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/equation.py +265 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/identity.py +48 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/pad.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/subclip.py +91 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/empty.py +73 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/equation.py +56 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/noise.py +243 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/c_fractal.cpython-312-x86_64-linux-gnu.so +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/empty.py +69 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/equation.py +109 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/fractal.c +116 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/geometry.py +100 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/mandelbrot.py +176 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/noise.py +112 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/interfaces/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/interfaces/seedable.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/read_ffmpeg.py +904 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/read_svg.py +145 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/scheduler.py +356 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/write.py +340 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/basic.py +35 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/clean/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/clean/graph.py +80 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/hashes/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/hashes/graph.py +81 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/singleton.py +47 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cuda/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/factor/__init__.py +5 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/factor/proba.py +189 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/generalize/__init__.py +5 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/generalize/delay_to_fir.py +88 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/graph.py +17 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/parallel/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/parallel/buffer.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/utils.py +34 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/audio_5.1_narration.oga +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/intro.webm +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/logo.svg +13 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/project.json +226 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/video.mp4 +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/__main__.py +25 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/actions.py +63 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/app/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/app/app.py +248 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/base.py +50 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/container_input_ffmpeg.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_delay.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_equation.py +45 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_fir.py +58 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_subclip.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_cut.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_delay.py +20 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_subclip.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_delay.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_equation.py +53 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_subclip.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_audio_equation.py +14 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_audio_noise.py +19 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_equation.py +13 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_mandelbrot.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_noise.py +18 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/base.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/default.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/documentation.py +47 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/general.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/interface.py +305 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/loader.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/main.py +62 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edition_tabs.py +34 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/base.py +122 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/filters.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/generators.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry_tabs.py +46 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/_helper.py +54 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/container.py +226 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/doc.py +67 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/encodec.py +289 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/main.py +173 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/edge_properties.py +56 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/main.py +280 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/node.py +44 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/main.py +151 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/menu.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/audio_settings.py +183 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/main.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/video_settings.py +257 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/run.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/main.py +30 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/slider.py +286 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/track.py +97 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/view.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/toolbar.py +29 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/tools.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/audio_player.py +103 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/control.py +96 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/frame_extractor.py +254 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/main.py +115 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/__main__.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/coding_style.py +49 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/generation.py +52 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/install.py +72 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/run.py +58 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/abstract.py +215 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/audio_cast.py +35 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/audio_equation.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/c_memory.py +132 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/compatibility.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/compile.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/encoder.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_cut.py +107 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_delay.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_empty.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/fir.py +143 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/hashes.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/initialisation.py +24 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/muxer.py +22 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/nan_snapshot.py +39 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/read.py +192 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/serialization_equality.py +50 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/snapshot_shape.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/sympy_to_torch.py +135 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/thread_safe.py +77 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/time_range.py +55 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/video_equation.py +77 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/write.py +95 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/utils.py +40 -0
- cutcutcodec-1.0.post3.dist-info/LICENSE +7 -0
- cutcutcodec-1.0.post3.dist-info/METADATA +271 -0
- cutcutcodec-1.0.post3.dist-info/RECORD +233 -0
- cutcutcodec-1.0.post3.dist-info/WHEEL +5 -0
- cutcutcodec-1.0.post3.dist-info/entry_points.txt +6 -0
- cutcutcodec-1.0.post3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Management of the encoding of a multimedia stream based on PyAV."""
|
|
4
|
+
|
|
5
|
+
from fractions import Fraction
|
|
6
|
+
import copy
|
|
7
|
+
import math
|
|
8
|
+
import numbers
|
|
9
|
+
import pathlib
|
|
10
|
+
import tempfile
|
|
11
|
+
import typing
|
|
12
|
+
|
|
13
|
+
import av
|
|
14
|
+
import numpy as np
|
|
15
|
+
import tqdm
|
|
16
|
+
|
|
17
|
+
from cutcutcodec.core.classes.container import ContainerOutput
|
|
18
|
+
from cutcutcodec.core.classes.frame_audio import FrameAudio
|
|
19
|
+
from cutcutcodec.core.classes.frame_video import FrameVideo
|
|
20
|
+
from cutcutcodec.core.classes.stream import Stream
|
|
21
|
+
from cutcutcodec.core.compilation.parse import parse_to_number
|
|
22
|
+
from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
23
|
+
from cutcutcodec.core.generation.video.noise import GeneratorVideoNoise
|
|
24
|
+
from cutcutcodec.core.io.scheduler import scheduler
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ContainerOutputFFMPEG(ContainerOutput):
|
|
28
|
+
"""Allow to write the output file to disk.
|
|
29
|
+
|
|
30
|
+
Attributes
|
|
31
|
+
----------
|
|
32
|
+
filename : pathlib.Path
|
|
33
|
+
The absolute path + name of the file to encode (readonly).
|
|
34
|
+
streams_settings : list[dict]
|
|
35
|
+
Information related to each codec (readonly).
|
|
36
|
+
container_settings : dict
|
|
37
|
+
Global container file information (readonly).
|
|
38
|
+
|
|
39
|
+
Examples
|
|
40
|
+
--------
|
|
41
|
+
>>> import os
|
|
42
|
+
>>> from cutcutcodec.core.filters.audio.subclip import FilterAudioSubclip
|
|
43
|
+
>>> from cutcutcodec.core.filters.video.subclip import FilterVideoSubclip
|
|
44
|
+
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
45
|
+
>>> from cutcutcodec.core.generation.video.noise import GeneratorVideoNoise
|
|
46
|
+
>>> from cutcutcodec.core.io.write import ContainerOutputFFMPEG
|
|
47
|
+
>>> streams_settings = [
|
|
48
|
+
... {"encodec": "libopus", "rate": 8000},
|
|
49
|
+
... {"encodec": "libx264", "rate": 12, "shape": (2, 2)},
|
|
50
|
+
... ]
|
|
51
|
+
>>> container_settings = {"format": "matroska"}
|
|
52
|
+
>>> (stream_a,) = FilterAudioSubclip(GeneratorAudioNoise(0).out_streams, 0, 1).out_streams
|
|
53
|
+
>>> (stream_v,) = FilterVideoSubclip(GeneratorVideoNoise(0).out_streams, 0, 1).out_streams
|
|
54
|
+
>>> streams = (stream_a, stream_v)
|
|
55
|
+
>>> ContainerOutputFFMPEG(streams, os.devnull, streams_settings, container_settings).write()
|
|
56
|
+
>>>
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
in_streams: typing.Iterable[Stream],
|
|
62
|
+
filename: typing.Union[str, bytes, pathlib.Path],
|
|
63
|
+
streams_settings: typing.Iterable[dict],
|
|
64
|
+
container_settings: typing.Optional[dict] = None,
|
|
65
|
+
):
|
|
66
|
+
"""Initialise and create the class.
|
|
67
|
+
|
|
68
|
+
Parameters
|
|
69
|
+
----------
|
|
70
|
+
in_streams : typing.Iterable[Stream]
|
|
71
|
+
The ordered video or audio streams to be encoded.
|
|
72
|
+
For more information, please refer to initializator of
|
|
73
|
+
``cutcutcodec.core.classes.container.ContainerOutput``.
|
|
74
|
+
filename : pathlike
|
|
75
|
+
Path to the file to be encoded.
|
|
76
|
+
streams_settings : typing.Iterable[dict]
|
|
77
|
+
These are the encoding parameters associated with each stream.
|
|
78
|
+
They contain all the information about the codecs.
|
|
79
|
+
For audio streams, here is the format to follow:
|
|
80
|
+
|
|
81
|
+
* "encodec": str, # name of the codec or encoding library (ex libopus)
|
|
82
|
+
* "rate": int or str, # samplerate in Hz (ex 48000)
|
|
83
|
+
* "options": dict, # (optional) option for codec (ex {"application": "voip"})
|
|
84
|
+
* "bitrate": int, # (optional) the flow in bits/s (ex 1024000)
|
|
85
|
+
For video streams, here is the format to follow:
|
|
86
|
+
|
|
87
|
+
* "encodec": str, # name of the codec or encoding library (ex libx264)
|
|
88
|
+
* "rate": numbers.Real or str, # the framerate in Hz (ex "30000/1001")
|
|
89
|
+
* "shape": tuple[int, int], # shape (height, width) of the frames
|
|
90
|
+
* "options": dict, # (optional) option for codec (ex {"crf": "23"})
|
|
91
|
+
* "bitrate": int, # (optional) the flow in bits/s (ex 6400000)
|
|
92
|
+
* "pix_fmt": str, # (optional) pixel format (ex "yuv444p10le")
|
|
93
|
+
container_settings : dict, optional
|
|
94
|
+
Global container file information.
|
|
95
|
+
must contain the following fields:
|
|
96
|
+
|
|
97
|
+
* "format": str or None, # specific format to use, defaults to autodect
|
|
98
|
+
* "container_options": dict, # (optional) options to pass to the container
|
|
99
|
+
* "options": dict, # (optional) options to pass to the container and all streams
|
|
100
|
+
"""
|
|
101
|
+
super().__init__(in_streams)
|
|
102
|
+
|
|
103
|
+
filename = pathlib.Path(filename)
|
|
104
|
+
assert filename.parent.exists(), filename
|
|
105
|
+
assert not filename.is_dir(), filename
|
|
106
|
+
self._filename = filename
|
|
107
|
+
|
|
108
|
+
assert isinstance(streams_settings, typing.Iterable), streams_settings.__class__.__name__
|
|
109
|
+
streams_settings = list(streams_settings)
|
|
110
|
+
assert len(streams_settings) == len(self.in_streams)
|
|
111
|
+
assert all(isinstance(s, dict) for s in streams_settings), streams_settings
|
|
112
|
+
for stream, settings in zip(in_streams, streams_settings):
|
|
113
|
+
assert "encodec" in settings, "missing the 'encodec' key"
|
|
114
|
+
assert isinstance(settings["encodec"], str), settings["encodec"].__class__.__name__
|
|
115
|
+
assert "rate" in settings, "missing the 'rate' key"
|
|
116
|
+
settings["rate"] = Fraction(settings["rate"])
|
|
117
|
+
assert isinstance(settings["rate"], numbers.Number)
|
|
118
|
+
assert settings["rate"] > 0, settings["rate"]
|
|
119
|
+
settings["options"] = settings.get("options", {})
|
|
120
|
+
assert isinstance(settings["options"], dict), settings["options"].__class__.__name__
|
|
121
|
+
settings["bitrate"] = settings.get("bitrate", None)
|
|
122
|
+
if settings["bitrate"] is not None:
|
|
123
|
+
settings["bitrate"] = round(parse_to_number(settings["bitrate"]))
|
|
124
|
+
assert settings["bitrate"] >= 0, settings["bitrate"]
|
|
125
|
+
if stream.type == "video":
|
|
126
|
+
assert "shape" in settings, "missing the 'shape' key"
|
|
127
|
+
assert isinstance(
|
|
128
|
+
settings["shape"], typing.Iterable
|
|
129
|
+
), settings["shape"].__class__.__name__
|
|
130
|
+
settings["shape"] = settings["shape"]
|
|
131
|
+
assert all(isinstance(s, int) and s >= 1 for s in settings["shape"])
|
|
132
|
+
settings["pix_fmt"] = settings.get("pix_fmt", None)
|
|
133
|
+
assert settings["pix_fmt"] is None or isinstance(settings["pix_fmt"], str), \
|
|
134
|
+
settings["pix_fmt"].__class__.__name__
|
|
135
|
+
self._streams_settings = streams_settings
|
|
136
|
+
|
|
137
|
+
if container_settings is None:
|
|
138
|
+
container_settings = {}
|
|
139
|
+
assert isinstance(container_settings, dict), container_settings.__class__.__name__
|
|
140
|
+
assert isinstance(container_settings.get("format", None), (str, type(None)))
|
|
141
|
+
assert isinstance(container_settings.get("options", {}), dict)
|
|
142
|
+
assert isinstance(container_settings.get("container_options", {}), dict)
|
|
143
|
+
self._container_settings = copy.deepcopy(container_settings)
|
|
144
|
+
|
|
145
|
+
def _getstate(self) -> dict:
|
|
146
|
+
# convertion fraction to str for jsonisable
|
|
147
|
+
streams_settings = self.streams_settings
|
|
148
|
+
for settings in streams_settings:
|
|
149
|
+
if not isinstance(settings["rate"], (int, float)):
|
|
150
|
+
settings["rate"] = str(settings["rate"])
|
|
151
|
+
# get the rest
|
|
152
|
+
return {
|
|
153
|
+
"filename": str(self.filename),
|
|
154
|
+
"streams_settings": streams_settings,
|
|
155
|
+
"container_settings": self.container_settings,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
def _setstate(self, in_streams: typing.Iterable[Stream], state: dict) -> None:
|
|
159
|
+
keys = {"filename", "streams_settings", "container_settings"}
|
|
160
|
+
assert state.keys() == keys, set(state)-keys
|
|
161
|
+
ContainerOutputFFMPEG.__init__(self, in_streams, **state)
|
|
162
|
+
|
|
163
|
+
@property
|
|
164
|
+
def container_settings(self) -> dict:
|
|
165
|
+
"""Global container file information."""
|
|
166
|
+
return {
|
|
167
|
+
"format": self._container_settings.get("format", None),
|
|
168
|
+
"options": self._container_settings.get("options", {}),
|
|
169
|
+
"container_options": self._container_settings.get("container_options", {}),
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@classmethod
|
|
173
|
+
def default(cls):
|
|
174
|
+
"""Provide a minimalist example of an instance of this node."""
|
|
175
|
+
audio_stream = GeneratorAudioNoise(0).out_streams[0]
|
|
176
|
+
video_stream = GeneratorVideoNoise(0).out_streams[0]
|
|
177
|
+
in_streams = [audio_stream, video_stream]
|
|
178
|
+
_, filename = tempfile.mkstemp(suffix=".mkv")
|
|
179
|
+
streams_settings = [
|
|
180
|
+
{"encodec": "libopus", "rate": 8000},
|
|
181
|
+
{"encodec": "libx264", "rate": 12, "shape": (2, 2)},
|
|
182
|
+
]
|
|
183
|
+
return cls(in_streams, filename, streams_settings)
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def filename(self) -> pathlib.Path:
|
|
187
|
+
"""Return the absolute path + name of the file to encode."""
|
|
188
|
+
return self._filename
|
|
189
|
+
|
|
190
|
+
@property
|
|
191
|
+
def streams_settings(self) -> list[dict]:
|
|
192
|
+
"""Information related to each codec."""
|
|
193
|
+
return copy.deepcopy(self._streams_settings)
|
|
194
|
+
|
|
195
|
+
def write(self):
|
|
196
|
+
"""Encode the streams and writes the file."""
|
|
197
|
+
# container initialisation
|
|
198
|
+
with av.open(
|
|
199
|
+
str(self.filename),
|
|
200
|
+
mode="w",
|
|
201
|
+
format=self.container_settings["format"],
|
|
202
|
+
options=self.container_settings["options"],
|
|
203
|
+
container_options=self.container_settings["container_options"],
|
|
204
|
+
) as container_av:
|
|
205
|
+
|
|
206
|
+
# streams initialisation
|
|
207
|
+
streams_av = []
|
|
208
|
+
shapes = []
|
|
209
|
+
for stream, settings in zip(self.in_streams, self.streams_settings):
|
|
210
|
+
if stream.type == "audio":
|
|
211
|
+
rate = int(settings["rate"])
|
|
212
|
+
assert rate == settings["rate"], settings["rate"]
|
|
213
|
+
stream_av = container_av.add_stream(
|
|
214
|
+
settings["encodec"], rate, layout=stream.layout.name
|
|
215
|
+
)
|
|
216
|
+
stream_av.options = settings["options"] | {"strict": "experimental"}
|
|
217
|
+
if settings["bitrate"]:
|
|
218
|
+
stream_av.bit_rate = settings["bitrate"] # int
|
|
219
|
+
streams_av.append(stream_av)
|
|
220
|
+
shapes.append(None)
|
|
221
|
+
elif stream.type == "video":
|
|
222
|
+
stream_av = container_av.add_stream(
|
|
223
|
+
settings["encodec"], settings["rate"]
|
|
224
|
+
)
|
|
225
|
+
stream_av.options = settings["options"] | {"strict": "experimental"}
|
|
226
|
+
stream_av.height, stream_av.width = settings["shape"]
|
|
227
|
+
if settings["pix_fmt"] is not None:
|
|
228
|
+
stream_av.pix_fmt = settings["pix_fmt"] # str
|
|
229
|
+
if settings["bitrate"]:
|
|
230
|
+
stream_av.bit_rate = settings["bitrate"] # int
|
|
231
|
+
streams_av.append(stream_av)
|
|
232
|
+
shapes.append(settings["shape"])
|
|
233
|
+
else:
|
|
234
|
+
raise TypeError(f"only audio and video streams are accepted, not {stream.type}")
|
|
235
|
+
|
|
236
|
+
# display avancement
|
|
237
|
+
with tqdm.tqdm(
|
|
238
|
+
desc=f"Encoding {self.filename.name}",
|
|
239
|
+
total=float(max(s.beginning + s.duration for s in self.in_streams)),
|
|
240
|
+
dynamic_ncols=True,
|
|
241
|
+
bar_format=(
|
|
242
|
+
"{n:.2f}s {rate_fmt}"
|
|
243
|
+
if math.isinf(max(s.duration for s in self.in_streams)) else
|
|
244
|
+
"{l_bar}{bar}| {n:.2f}s/{total:.2f}s [{elapsed}<{remaining}]"
|
|
245
|
+
),
|
|
246
|
+
smoothing=0.1,
|
|
247
|
+
unit="sec_video",
|
|
248
|
+
) as progress_bar:
|
|
249
|
+
|
|
250
|
+
# encode
|
|
251
|
+
rates = [settings["rate"] for settings in self.streams_settings]
|
|
252
|
+
for index, frame in scheduler(
|
|
253
|
+
list(self.in_streams),
|
|
254
|
+
rates,
|
|
255
|
+
shapes=shapes,
|
|
256
|
+
samples=65536, # for audio optimisation, 1 s vs 100 ms in average
|
|
257
|
+
):
|
|
258
|
+
frame = {
|
|
259
|
+
FrameAudio: frame_audio_to_av,
|
|
260
|
+
FrameVideo: frame_video_to_av,
|
|
261
|
+
}[frame.__class__](frame)
|
|
262
|
+
container_av.mux(streams_av[index].encode(frame))
|
|
263
|
+
progress_bar.update(frame.time - progress_bar.n)
|
|
264
|
+
for stream_av in streams_av:
|
|
265
|
+
container_av.mux(stream_av.encode(None)) # flush buffer
|
|
266
|
+
progress_bar.update(progress_bar.total - progress_bar.n)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def frame_audio_to_av(frame_audio: FrameAudio) -> av.audio.frame.AudioFrame:
|
|
270
|
+
"""Convert a FrameAudio cutcutcodec into a av audio frame for encoding.
|
|
271
|
+
|
|
272
|
+
Parameters
|
|
273
|
+
----------
|
|
274
|
+
frame_audio : cutcutcodec.core.classes.frame_audio.FrameAudio
|
|
275
|
+
The torch frame to cast.
|
|
276
|
+
|
|
277
|
+
Returns
|
|
278
|
+
-------
|
|
279
|
+
av_frame : av.audio.frame.audioFrame
|
|
280
|
+
The equivalent av audio frame containing a similar audio signal.
|
|
281
|
+
|
|
282
|
+
Examples
|
|
283
|
+
--------
|
|
284
|
+
>>> import torch
|
|
285
|
+
>>> from cutcutcodec.core.classes.frame_audio import FrameAudio
|
|
286
|
+
>>> from cutcutcodec.core.io.write import frame_audio_to_av
|
|
287
|
+
>>>
|
|
288
|
+
>>> frame_audio_to_av(FrameAudio(10, 48000, "mono", torch.empty(1, 1024))) # doctest: +ELLIPSIS
|
|
289
|
+
<av.AudioFrame 0, pts=480000, 1024 samples at 48000Hz, mono, flt at ...>
|
|
290
|
+
>>> frame_audio_to_av(FrameAudio(10, 48000, "5.1", torch.empty(6, 1024))) # doctest: +ELLIPSIS
|
|
291
|
+
<av.AudioFrame 0, pts=480000, 1024 samples at 48000Hz, 5.1, flt at ...>
|
|
292
|
+
>>>
|
|
293
|
+
"""
|
|
294
|
+
assert isinstance(frame_audio, FrameAudio), frame_audio.__class__.__name__
|
|
295
|
+
frame_np = frame_audio.numpy(force=True)
|
|
296
|
+
frame_np = frame_np.astype(np.float32)
|
|
297
|
+
frame_np = np.ascontiguousarray(frame_np) # fix ValueError: ndarray is not C-contiguous
|
|
298
|
+
frame_av = av.audio.frame.AudioFrame.from_ndarray(
|
|
299
|
+
np.expand_dims(frame_np.ravel(order="F"), 0),
|
|
300
|
+
format="flt",
|
|
301
|
+
layout=frame_audio.layout.name,
|
|
302
|
+
)
|
|
303
|
+
frame_av.rate = frame_audio.rate
|
|
304
|
+
frame_av.time_base = Fraction(1, frame_audio.rate)
|
|
305
|
+
frame_av.pts = round(frame_audio.time * frame_audio.rate)
|
|
306
|
+
return frame_av
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def frame_video_to_av(frame_video: FrameVideo) -> av.video.frame.VideoFrame:
|
|
310
|
+
"""Convert a FrameVideo cutcutcodec into a av video frame for encoding.
|
|
311
|
+
|
|
312
|
+
Parameters
|
|
313
|
+
----------
|
|
314
|
+
frame_video : cutcutcodec.core.classes.frame_video.FrameVideo
|
|
315
|
+
The torch frame video to cast.
|
|
316
|
+
|
|
317
|
+
Returns
|
|
318
|
+
-------
|
|
319
|
+
av_frame : av.video.frame.VideoFrame
|
|
320
|
+
The equivalent av video frame containing the similar image in format bgr24.
|
|
321
|
+
|
|
322
|
+
Examples
|
|
323
|
+
--------
|
|
324
|
+
>>> import torch
|
|
325
|
+
>>> from cutcutcodec.core.classes.frame_video import FrameVideo
|
|
326
|
+
>>> from cutcutcodec.core.io.write import frame_video_to_av
|
|
327
|
+
>>>
|
|
328
|
+
>>> frame_video_to_av(FrameVideo(10, torch.empty(480, 720, 3))) # doctest: +ELLIPSIS
|
|
329
|
+
<av.VideoFrame #0, pts=3003000 bgr24 720x480 at ...>
|
|
330
|
+
>>> frame_video_to_av(FrameVideo(10, torch.empty(480, 720, 1))) # doctest: +ELLIPSIS
|
|
331
|
+
<av.VideoFrame #0, pts=3003000 bgr24 720x480 at ...>
|
|
332
|
+
>>> frame_video_to_av(FrameVideo(10, torch.empty(480, 720, 4))) # doctest: +ELLIPSIS
|
|
333
|
+
<av.VideoFrame #0, pts=3003000 bgr24 720x480 at ...>
|
|
334
|
+
>>>
|
|
335
|
+
"""
|
|
336
|
+
assert isinstance(frame_video, FrameVideo), frame_video.__class__.__name__
|
|
337
|
+
frame_av = av.video.frame.VideoFrame.from_ndarray(frame_video.to_numpy_bgr(), format="bgr24")
|
|
338
|
+
frame_av.time_base = Fraction(1, 300300) # ppcm 1001, 1000, 25, 30, 60
|
|
339
|
+
frame_av.pts = round(frame_video.time / frame_av.time_base)
|
|
340
|
+
return frame_av
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""The not sofisticated cache decorators."""
|
|
4
|
+
|
|
5
|
+
import functools
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def basic_cache(func: callable) -> callable:
|
|
9
|
+
"""Cache for hashable args.
|
|
10
|
+
|
|
11
|
+
Examples
|
|
12
|
+
--------
|
|
13
|
+
>>> from cutcutcodec.core.opti.cache.basic import basic_cache
|
|
14
|
+
>>> i = 0
|
|
15
|
+
>>> @basic_cache
|
|
16
|
+
... def f(x):
|
|
17
|
+
... global i
|
|
18
|
+
... i += x
|
|
19
|
+
... return i
|
|
20
|
+
...
|
|
21
|
+
>>> f(1)
|
|
22
|
+
1
|
|
23
|
+
>>> f(1)
|
|
24
|
+
1
|
|
25
|
+
>>>
|
|
26
|
+
"""
|
|
27
|
+
@functools.wraps(func)
|
|
28
|
+
def cached_func(*args, **kwargs):
|
|
29
|
+
signature = (args, tuple((k, kwargs[k]) for k in sorted(kwargs)))
|
|
30
|
+
func.cache = getattr(func, "cache", {})
|
|
31
|
+
if signature not in func.cache:
|
|
32
|
+
func.cache[signature] = func(*args, **kwargs)
|
|
33
|
+
return func.cache[signature]
|
|
34
|
+
|
|
35
|
+
return cached_func
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Allow to delete the obsolete node cache of the graph."""
|
|
4
|
+
|
|
5
|
+
import itertools
|
|
6
|
+
|
|
7
|
+
import networkx
|
|
8
|
+
|
|
9
|
+
from cutcutcodec.core.opti.cache.hashes.graph import compute_graph_items_hash
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def clean_graph(graph: networkx.MultiDiGraph) -> networkx.MultiDiGraph:
|
|
13
|
+
"""Update inplace the `cache` attribute of each nodes of the graph.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
graph : networkx.MultiDiGraph
|
|
18
|
+
The assembly graph.
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
-------
|
|
22
|
+
updated_graph : networkx.MultiDiGraph
|
|
23
|
+
The same graph with the updated `cache` node attribute.
|
|
24
|
+
The underground data are shared, operate in-place.
|
|
25
|
+
|
|
26
|
+
Examples
|
|
27
|
+
--------
|
|
28
|
+
>>> from pprint import pprint
|
|
29
|
+
>>> from cutcutcodec.core.classes.container import ContainerOutput
|
|
30
|
+
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
|
|
31
|
+
>>> from cutcutcodec.core.filters.audio.subclip import FilterAudioSubclip
|
|
32
|
+
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
33
|
+
>>> from cutcutcodec.core.opti.cache.clean.graph import clean_graph
|
|
34
|
+
>>> container_out = ContainerOutput(
|
|
35
|
+
... FilterAudioSubclip(GeneratorAudioNoise(0).out_streams, 0, 1).out_streams
|
|
36
|
+
... )
|
|
37
|
+
>>> graph = tree_to_graph(container_out)
|
|
38
|
+
>>> pprint(dict(clean_graph(graph).nodes("cache")))
|
|
39
|
+
{'container_output_1': ('099c022d457eb220c36ae22a75bf1998', {}),
|
|
40
|
+
'filter_audio_subclip_1': ('10355c7ad764f111b15798bed884a821', {}),
|
|
41
|
+
'generator_audio_noise_1': ('4dc3de85c734bfd23024c381599bfe3f', {})}
|
|
42
|
+
>>> pprint(list(graph.edges(keys=True, data=True)))
|
|
43
|
+
[('filter_audio_subclip_1',
|
|
44
|
+
'container_output_1',
|
|
45
|
+
'0->0',
|
|
46
|
+
{'cache': ('10355c7ad764f111b15798bed884a821|0', {})}),
|
|
47
|
+
('generator_audio_noise_1',
|
|
48
|
+
'filter_audio_subclip_1',
|
|
49
|
+
'0->0',
|
|
50
|
+
{'cache': ('4dc3de85c734bfd23024c381599bfe3f|0', {})})]
|
|
51
|
+
>>> for _, data in graph.nodes(data=True):
|
|
52
|
+
... data["cache"][1]["key"] = "value"
|
|
53
|
+
...
|
|
54
|
+
>>> for *_, data in graph.edges(keys=True, data=True):
|
|
55
|
+
... data["cache"][1]["key"] = "value"
|
|
56
|
+
...
|
|
57
|
+
>>> graph.nodes["filter_audio_subclip_1"]["state"]["duration_max"] = "2"
|
|
58
|
+
>>> pprint(dict(clean_graph(graph).nodes("cache")))
|
|
59
|
+
{'container_output_1': ('8978fa1dc585c4d400fb36ad711ba95f', {}),
|
|
60
|
+
'filter_audio_subclip_1': ('0c5c8e9591d25413c94a4251a3a14444', {}),
|
|
61
|
+
'generator_audio_noise_1': ('4dc3de85c734bfd23024c381599bfe3f',
|
|
62
|
+
{'key': 'value'})}
|
|
63
|
+
>>> pprint(list(graph.edges(keys=True, data=True)))
|
|
64
|
+
[('filter_audio_subclip_1',
|
|
65
|
+
'container_output_1',
|
|
66
|
+
'0->0',
|
|
67
|
+
{'cache': ('0c5c8e9591d25413c94a4251a3a14444|0', {})}),
|
|
68
|
+
('generator_audio_noise_1',
|
|
69
|
+
'filter_audio_subclip_1',
|
|
70
|
+
'0->0',
|
|
71
|
+
{'cache': ('4dc3de85c734bfd23024c381599bfe3f|0', {'key': 'value'})})]
|
|
72
|
+
>>>
|
|
73
|
+
"""
|
|
74
|
+
new_hashes = compute_graph_items_hash(graph) # assertions are done here
|
|
75
|
+
edges_iter = (((s, d, k), data) for s, d, k, data in graph.edges(keys=True, data=True))
|
|
76
|
+
for item, data in itertools.chain(graph.nodes(data=True), edges_iter):
|
|
77
|
+
new_hash = new_hashes[item]
|
|
78
|
+
if "cache" not in data or data["cache"][0] != new_hash:
|
|
79
|
+
data["cache"] = (new_hashes[item], {})
|
|
80
|
+
return graph
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Allow to summarize the state of each node of the graph.
|
|
4
|
+
|
|
5
|
+
This allows a finer management of the cache by a fine tracking of the unchanged elements.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import hashlib
|
|
9
|
+
import typing
|
|
10
|
+
|
|
11
|
+
import networkx
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def compute_graph_items_hash(
|
|
15
|
+
graph: networkx.MultiDiGraph
|
|
16
|
+
) -> dict[typing.Union[str, tuple[str, str, str]], str]:
|
|
17
|
+
"""Compute a signature for each node and edge, which reflects its state in the graph.
|
|
18
|
+
|
|
19
|
+
This is mean to detecting a change of attributes in one of the upstream elements.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
graph : networkx.MultiDiGraph
|
|
24
|
+
The assembly graph.
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
hashes : dict[typing.Union[str, tuple[str, str, str]], str]
|
|
29
|
+
To each node and edge name, associate its state as a string.
|
|
30
|
+
|
|
31
|
+
Notes
|
|
32
|
+
-----
|
|
33
|
+
The graph must not contain any cycles because the function would never returns.
|
|
34
|
+
|
|
35
|
+
Examples
|
|
36
|
+
--------
|
|
37
|
+
>>> from pprint import pprint
|
|
38
|
+
>>> from cutcutcodec.core.classes.container import ContainerOutput
|
|
39
|
+
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
|
|
40
|
+
>>> from cutcutcodec.core.filters.audio.subclip import FilterAudioSubclip
|
|
41
|
+
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
42
|
+
>>> from cutcutcodec.core.opti.cache.hashes.graph import compute_graph_items_hash
|
|
43
|
+
>>> container_out = ContainerOutput(
|
|
44
|
+
... FilterAudioSubclip(GeneratorAudioNoise(0).out_streams, 0, 1).out_streams
|
|
45
|
+
... )
|
|
46
|
+
>>> graph = tree_to_graph(container_out)
|
|
47
|
+
>>> pprint(compute_graph_items_hash(graph)) # doctest: +ELLIPSIS
|
|
48
|
+
{'container_output_1': '099c022d457eb220c36ae22a75bf1998',
|
|
49
|
+
'filter_audio_subclip_1': '10355c7ad764f111b15798bed884a821',
|
|
50
|
+
'generator_audio_noise_1': '4dc3de85c734bfd23024c381599bfe3f',
|
|
51
|
+
('filter_audio_subclip_1', 'container_output_1', '0->0'): '10355c7ad764f111b15798bed884a821|0',
|
|
52
|
+
('generator_audio_noise_1', '...subclip_1', '0->0'): '4dc3de85c734bfd23024c381599bfe3f|0'}
|
|
53
|
+
>>>
|
|
54
|
+
"""
|
|
55
|
+
assert isinstance(graph, networkx.MultiDiGraph), graph.__class__.__name__
|
|
56
|
+
|
|
57
|
+
def complete(hashes, graph, node_name) -> str:
|
|
58
|
+
if node_name not in hashes:
|
|
59
|
+
node_attr = graph.nodes[node_name]
|
|
60
|
+
local_node_signature = (
|
|
61
|
+
f"{node_attr['class'].__name__}-"
|
|
62
|
+
f"{'-'.join(str(node_attr['state'][k]) for k in sorted(node_attr['state']))}"
|
|
63
|
+
)
|
|
64
|
+
in_edges = sorted( # the name of the edges in order of arrival on the node
|
|
65
|
+
graph.in_edges(node_name, data=False, keys=True),
|
|
66
|
+
key=lambda src_dst_key: int(src_dst_key[2].split("->")[1])
|
|
67
|
+
)
|
|
68
|
+
local_edges_signature = "-".join(k.split("->")[0] for _, _, k in in_edges)
|
|
69
|
+
parents_signature = "-".join(complete(hashes, graph, n) for n, _, _ in in_edges)
|
|
70
|
+
signature = hashlib.md5( # md5 is the fastest
|
|
71
|
+
f"{parents_signature}|{local_edges_signature}|{local_node_signature}".encode()
|
|
72
|
+
).hexdigest()
|
|
73
|
+
hashes[node_name] = signature
|
|
74
|
+
for _, dst, key in graph.out_edges(node_name, keys=True):
|
|
75
|
+
hashes[(node_name, dst, key)] = f"{signature}|{int(key.split('->')[0])}"
|
|
76
|
+
return hashes[node_name]
|
|
77
|
+
|
|
78
|
+
hashes = {}
|
|
79
|
+
for node_name in graph:
|
|
80
|
+
complete(hashes, graph, node_name)
|
|
81
|
+
return hashes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Allow to create only one instance of an object."""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MetaSingleton(type):
|
|
7
|
+
"""For share memory inside the current session.
|
|
8
|
+
|
|
9
|
+
Notes
|
|
10
|
+
-----
|
|
11
|
+
The arguments needs to be hashable.
|
|
12
|
+
|
|
13
|
+
Examples
|
|
14
|
+
--------
|
|
15
|
+
>>> from cutcutcodec.core.opti.cache.singleton import MetaSingleton
|
|
16
|
+
>>> class A:
|
|
17
|
+
... pass
|
|
18
|
+
...
|
|
19
|
+
>>> class B(metaclass=MetaSingleton):
|
|
20
|
+
... pass
|
|
21
|
+
...
|
|
22
|
+
>>> class C(metaclass=MetaSingleton):
|
|
23
|
+
... def __init__(self, *args, **kwargs):
|
|
24
|
+
... self.args = args
|
|
25
|
+
... self.kwargs = kwargs
|
|
26
|
+
...
|
|
27
|
+
>>> A() is A()
|
|
28
|
+
False
|
|
29
|
+
>>> B() is B()
|
|
30
|
+
True
|
|
31
|
+
>>> C(0) is C(0)
|
|
32
|
+
True
|
|
33
|
+
>>> C(0) is C(1)
|
|
34
|
+
False
|
|
35
|
+
>>>
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
instances: dict = {}
|
|
39
|
+
|
|
40
|
+
def __call__(cls, *args, **kwargs):
|
|
41
|
+
"""Create a new class only if it is not already instanciated."""
|
|
42
|
+
signature = (cls, args, tuple((k, kwargs[k]) for k in sorted(kwargs)))
|
|
43
|
+
if signature not in MetaSingleton.instances:
|
|
44
|
+
instance = cls.__new__(cls)
|
|
45
|
+
instance.__init__(*args, **kwargs)
|
|
46
|
+
MetaSingleton.instances[signature] = instance
|
|
47
|
+
return MetaSingleton.instances[signature]
|