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,82 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Allow to search for elements in the graph."""
|
|
4
|
+
|
|
5
|
+
import typing
|
|
6
|
+
|
|
7
|
+
import networkx
|
|
8
|
+
|
|
9
|
+
from cutcutcodec.core.classes.stream import Stream
|
|
10
|
+
from cutcutcodec.core.compilation.graph_to_tree import update_trees
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def find_edge_from_edge_tree(
|
|
14
|
+
graph: networkx.MultiDiGraph,
|
|
15
|
+
stream: Stream,
|
|
16
|
+
nbunch: typing.Optional[typing.Iterable[tuple[str, str, str]]] = None,
|
|
17
|
+
pointer: bool = False,
|
|
18
|
+
) -> tuple[str, str, str]:
|
|
19
|
+
"""Search in the graph for the edge that corresponds to the stream provided.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
graph : networkx.MultiDiGraph
|
|
24
|
+
The assembly graph.
|
|
25
|
+
stream : cutcutcodec.core.classes.stream.Stream
|
|
26
|
+
One of the output stream of the node. It can be a stream of any type.
|
|
27
|
+
nbunch : typing.Iterable[tuple[str, str, str]], optional
|
|
28
|
+
The edges to be analyzed. By default all edges are analyzed.
|
|
29
|
+
pointer : boolean
|
|
30
|
+
If True, returns only if the node stream is the same objet as the provide stream.
|
|
31
|
+
If False (default), compare the streams contents. It is slower but stronger.
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
edge : tuple[str, str, str]
|
|
36
|
+
The name of the corresponding edge.
|
|
37
|
+
|
|
38
|
+
Raises
|
|
39
|
+
------
|
|
40
|
+
KeyError
|
|
41
|
+
If no edge matches.
|
|
42
|
+
|
|
43
|
+
Examples
|
|
44
|
+
--------
|
|
45
|
+
>>> from cutcutcodec.core.analysis.graph.find import find_edge_from_edge_tree
|
|
46
|
+
>>> from cutcutcodec.core.classes.container import ContainerOutput
|
|
47
|
+
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
|
|
48
|
+
>>> from cutcutcodec.core.filters.audio.subclip import FilterAudioSubclip
|
|
49
|
+
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
50
|
+
>>> container_out = ContainerOutput(
|
|
51
|
+
... FilterAudioSubclip(GeneratorAudioNoise(0).out_streams, 1, 2).out_streams
|
|
52
|
+
... )
|
|
53
|
+
>>> graph = tree_to_graph(container_out)
|
|
54
|
+
>>> find_edge_from_edge_tree(graph, container_out.in_streams[0])
|
|
55
|
+
('filter_audio_subclip_1', 'container_output_1', '0->0')
|
|
56
|
+
>>>
|
|
57
|
+
"""
|
|
58
|
+
# verifications
|
|
59
|
+
assert isinstance(graph, networkx.MultiDiGraph), graph.__class__.__name__
|
|
60
|
+
assert isinstance(stream, Stream), stream.__class__.__name__
|
|
61
|
+
if nbunch is not None:
|
|
62
|
+
assert isinstance(nbunch, typing.Iterable), nbunch.__class__.__name__
|
|
63
|
+
nbunch = set(nbunch)
|
|
64
|
+
assert all(
|
|
65
|
+
isinstance(e, tuple) and len(e) == 3 and all(isinstance(k, str) for k in e)
|
|
66
|
+
for e in nbunch
|
|
67
|
+
), nbunch
|
|
68
|
+
|
|
69
|
+
update_trees(graph)
|
|
70
|
+
|
|
71
|
+
# search the right edge
|
|
72
|
+
for src, dst, key, cache in graph.edges(data="cache", keys=True):
|
|
73
|
+
if nbunch is not None and (src, dst, key) not in nbunch:
|
|
74
|
+
continue
|
|
75
|
+
tree = cache[1]["tree"]
|
|
76
|
+
if pointer:
|
|
77
|
+
if stream is tree:
|
|
78
|
+
return (src, dst, key)
|
|
79
|
+
else:
|
|
80
|
+
if stream == tree:
|
|
81
|
+
return (src, dst, key)
|
|
82
|
+
raise KeyError(f"{stream} not founded in the graph")
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Backpropagation of the time interval in a node."""
|
|
4
|
+
|
|
5
|
+
from fractions import Fraction
|
|
6
|
+
import math
|
|
7
|
+
import typing
|
|
8
|
+
|
|
9
|
+
import networkx
|
|
10
|
+
|
|
11
|
+
from cutcutcodec.core.analysis.graph.find import find_edge_from_edge_tree
|
|
12
|
+
from cutcutcodec.core.analysis.stream.time_backprop import time_backprop as time_backprop_stream
|
|
13
|
+
from cutcutcodec.core.compilation.graph_to_tree import update_trees
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def time_backprop(
|
|
17
|
+
graph: networkx.MultiDiGraph,
|
|
18
|
+
edge: tuple[str, str, str],
|
|
19
|
+
t_min: Fraction,
|
|
20
|
+
t_max: typing.Union[Fraction, float]
|
|
21
|
+
) -> tuple[tuple[str, str, str], tuple[Fraction, typing.Union[Fraction, float]]]:
|
|
22
|
+
"""Graph version of ``cutcutcodec.core.analysis.stream.time_backprop.time_backprop``.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
graph : networkx.MultiDiGraph
|
|
27
|
+
The assembly graph. The graph is supposed to be updated.
|
|
28
|
+
It means ``cutcutcodec.core.compilation.graph_to_tree.update_trees`` was called.
|
|
29
|
+
edge : tuple[str, str, str]
|
|
30
|
+
The name of the edge corresponding to the outgoing stream. It can be a stream of any type.
|
|
31
|
+
t_min : Fraction
|
|
32
|
+
The starting included time of decoding the data of the given stream.
|
|
33
|
+
t_max : frctions.Fraction or inf
|
|
34
|
+
The final excluded time of decoding the data of the given stream.
|
|
35
|
+
|
|
36
|
+
Yields
|
|
37
|
+
------
|
|
38
|
+
in_edge : tuple[str, str, str]
|
|
39
|
+
Turn by turn, the input edge of the main node given by the edge in argument.
|
|
40
|
+
If the node is a generator, no edge are yields.
|
|
41
|
+
new_t_min : Fraction
|
|
42
|
+
The start time of this slice matching with the given time slice.
|
|
43
|
+
new_t_max : Fraction or inf
|
|
44
|
+
The final time of this slice matching with the given time slice.
|
|
45
|
+
"""
|
|
46
|
+
assert isinstance(graph, networkx.MultiDiGraph), graph.__class__.__name__
|
|
47
|
+
assert isinstance(edge, tuple), edge.__class__.__name__
|
|
48
|
+
assert len(edge) == 3, edge
|
|
49
|
+
assert all(isinstance(e, str) for e in edge), edge
|
|
50
|
+
assert edge in graph.edges, (edge, graph.edges)
|
|
51
|
+
assert isinstance(t_min, Fraction), t_min.__class__.__name__
|
|
52
|
+
assert t_max == math.inf or isinstance(t_max, Fraction), t_max
|
|
53
|
+
|
|
54
|
+
update_trees(graph)
|
|
55
|
+
stream = graph.edges[edge]["cache"][1]["tree"]
|
|
56
|
+
|
|
57
|
+
def _time_backprop(stream, t_min, t_max):
|
|
58
|
+
for in_stream, t_min_, t_max_ in time_backprop_stream(stream, t_min, t_max):
|
|
59
|
+
try:
|
|
60
|
+
in_edge = find_edge_from_edge_tree(
|
|
61
|
+
graph, in_stream, nbunch=graph.in_edges(edge[0], keys=True), pointer=True
|
|
62
|
+
)
|
|
63
|
+
except KeyError: # case meta filter
|
|
64
|
+
yield from _time_backprop(in_stream, t_min_, t_max_)
|
|
65
|
+
else:
|
|
66
|
+
yield in_edge, t_min_, t_max_
|
|
67
|
+
|
|
68
|
+
yield from _time_backprop(stream, t_min, t_max)
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Smartly choose the framerate of an audio stream."""
|
|
4
|
+
|
|
5
|
+
from fractions import Fraction
|
|
6
|
+
import math
|
|
7
|
+
import typing
|
|
8
|
+
|
|
9
|
+
from sympy.core.add import Add
|
|
10
|
+
from sympy.core.function import diff
|
|
11
|
+
from sympy.core.mul import Mul
|
|
12
|
+
from sympy.core.power import Pow
|
|
13
|
+
from sympy.core.symbol import Symbol
|
|
14
|
+
from sympy.functions.elementary.trigonometric import cos, sin
|
|
15
|
+
from sympy.functions.special.delta_functions import DiracDelta
|
|
16
|
+
from sympy.utilities import lambdify
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
from cutcutcodec.core.analysis.stream.time_backprop import time_backprop
|
|
20
|
+
from cutcutcodec.core.classes.stream_audio import StreamAudio
|
|
21
|
+
from cutcutcodec.core.compilation.sympy_to_torch.preprocess import evalf
|
|
22
|
+
from cutcutcodec.core.generation.audio.equation import GeneratorAudioEquation
|
|
23
|
+
from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
24
|
+
from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
RATE_ESTIMATORS = {} # to each node stream class, associate the func to find the optimal rate
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _add_estimator(node_cls: type) -> callable:
|
|
31
|
+
def _add_func(func) -> callable:
|
|
32
|
+
RATE_ESTIMATORS[node_cls] = func
|
|
33
|
+
return func
|
|
34
|
+
return _add_func
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _eq_estimate_freq_max(
|
|
38
|
+
signal, t_symb: Symbol, t_min: Fraction, t_max: typing.Union[Fraction, float]
|
|
39
|
+
) -> float:
|
|
40
|
+
"""Recursive delegation (parallelization is slower)."""
|
|
41
|
+
if t_symb not in signal.free_symbols: # facultative, optimisation
|
|
42
|
+
return 0.0
|
|
43
|
+
if isinstance(signal, Add): # fourier transform is linear
|
|
44
|
+
return max(_eq_estimate_freq_max(s, t_symb, t_min, t_max) for s in signal.args)
|
|
45
|
+
if isinstance(signal, Mul): # fourier transform of prod is convolution, max is sum
|
|
46
|
+
return sum(_eq_estimate_freq_max(s, t_symb, t_min, t_max) for s in signal.args)
|
|
47
|
+
if isinstance(signal, (cos, sin)):
|
|
48
|
+
return _eq_abs_max_expr(
|
|
49
|
+
diff(signal.args[0], t_symb), t_symb, float(t_min), float(t_max)
|
|
50
|
+
) / (2*math.pi)
|
|
51
|
+
if isinstance(signal, Pow) and signal.exp.is_integer and signal.exp > 0: # recursive Mul
|
|
52
|
+
return float(signal.exp) * _eq_estimate_freq_max(signal.base, t_symb, t_min, t_max)
|
|
53
|
+
return _eq_estimate_freq_max_by_diff(signal, t_symb, float(t_min), float(t_max))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _eq_abs_max_expr(expr, t_symb: Symbol, t_min: float, t_max: float) -> float:
|
|
57
|
+
"""Search an aproximation of the max with a pseudo dichotomie gradient."""
|
|
58
|
+
if expr.is_number:
|
|
59
|
+
return abs(float(expr))
|
|
60
|
+
if expr.atoms(DiracDelta):
|
|
61
|
+
return math.inf
|
|
62
|
+
func_max_and_diff = lambdify( # sign(abs(s)') = sign((s**2)') = sign(2*s'*s) = sign(s'*s)
|
|
63
|
+
[t_symb],
|
|
64
|
+
[expr, Mul(diff(expr, t_symb), expr, evaluate=False)],
|
|
65
|
+
modules="numpy",
|
|
66
|
+
cse=True,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# the initials positions
|
|
70
|
+
t_max = 3600.0 if t_max == math.inf else t_max
|
|
71
|
+
t_0 = np.logspace(0, 3, 512, base=10) # [1, 1000]
|
|
72
|
+
t_0 *= (t_max-t_min) / 999.0 # [(tmax-t_min)/999, 1000/999*(tmax-t_min)]
|
|
73
|
+
t_0 += (1000.0*t_min - t_max) / 999.0 # [t_min, t_max]
|
|
74
|
+
t_0 = np.concatenate([t_0, np.linspace(t_min, t_max, 1024), (t_min+t_max)-t_0], axis=0)
|
|
75
|
+
t_0.sort(axis=0, kind="quicksort")
|
|
76
|
+
|
|
77
|
+
# search the maximums
|
|
78
|
+
old_max = 0
|
|
79
|
+
for i in range(30): # f > 19200 Hz for delta_t <= 3600 s
|
|
80
|
+
new_max, direction = func_max_and_diff(t_0)
|
|
81
|
+
if not np.isfinite(new_max).any():
|
|
82
|
+
return old_max
|
|
83
|
+
|
|
84
|
+
new_max = np.absolute(new_max, out=new_max)
|
|
85
|
+
new_max = np.nanmax(new_max)
|
|
86
|
+
if old_max > new_max:
|
|
87
|
+
return old_max
|
|
88
|
+
old_max = new_max
|
|
89
|
+
|
|
90
|
+
direction = np.sign(direction).astype(int)
|
|
91
|
+
direction[0], direction[-1] = max(0, direction[0]), min(0, direction[-1])
|
|
92
|
+
direction += np.arange(len(direction), dtype=int)
|
|
93
|
+
t_0 = (1 - 2**(-1-i))*t_0 + (2**(-1-i))*t_0[direction]
|
|
94
|
+
|
|
95
|
+
return old_max
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _eq_estimate_freq_max_by_diff(signal, t_symb: Symbol, t_min: float, t_max: float) -> float:
|
|
99
|
+
"""Match the max freq sin by differencials.
|
|
100
|
+
|
|
101
|
+
Hypotetical model : signal = s = a*sin(2*pi*f*t)
|
|
102
|
+
<=> s' = 2*pi*a*f*cos(2*pi*f*t) and s''' = -8*pi**3*a*f**3*cos(2*pi*f*t)
|
|
103
|
+
<=> f_max = sqrt(abs(s'**3 * s'''))/(2 * pi * s'**2)
|
|
104
|
+
<=> f_max**2 = abs(-s'''/(4*pi**2*s'))
|
|
105
|
+
<=> 4*pi**2 * f_max**2 = abs(s'''/s')
|
|
106
|
+
"""
|
|
107
|
+
# compute the successives differentials
|
|
108
|
+
if signal.is_Atom: # average 8% faster this test
|
|
109
|
+
return 0
|
|
110
|
+
signal = evalf(signal) # average 60% faster with this simplification
|
|
111
|
+
max_freq = diff(signal, t_symb)
|
|
112
|
+
max_freq = diff(max_freq, t_symb, 2) / max_freq
|
|
113
|
+
return math.sqrt(_eq_abs_max_expr(max_freq, t_symb, t_min, t_max) / (4*math.pi**2))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@_add_estimator(ContainerInputFFMPEG)
|
|
117
|
+
def _optimal_rate_container_input_ffmpeg(stream: StreamAudio, *_) -> int:
|
|
118
|
+
"""Detect the rate of a ContainerInputFFMPEG stream.
|
|
119
|
+
|
|
120
|
+
Examples
|
|
121
|
+
--------
|
|
122
|
+
>>> from cutcutcodec.core.analysis.stream.rate_audio import optimal_rate_audio
|
|
123
|
+
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
|
|
124
|
+
>>> (stream,) = ContainerInputFFMPEG("cutcutcodec/examples/audio_5.1_narration.oga").out_streams
|
|
125
|
+
>>> optimal_rate_audio(stream)
|
|
126
|
+
16000
|
|
127
|
+
>>>
|
|
128
|
+
"""
|
|
129
|
+
assert isinstance(stream.node, ContainerInputFFMPEG), stream.node.__class__.__name__
|
|
130
|
+
return stream.rate
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@_add_estimator(GeneratorAudioEquation)
|
|
134
|
+
def _optimal_rate_generator_audio_equation(
|
|
135
|
+
stream: StreamAudio, t_min: Fraction, t_max: typing.Union[Fraction, float]
|
|
136
|
+
) -> int:
|
|
137
|
+
"""Detect the rate of a GeneratorAudioEquation stream.
|
|
138
|
+
|
|
139
|
+
Examples
|
|
140
|
+
--------
|
|
141
|
+
>>> from cutcutcodec.core.analysis.stream.rate_audio import optimal_rate_audio
|
|
142
|
+
>>> from cutcutcodec.core.generation.audio.equation import GeneratorAudioEquation
|
|
143
|
+
>>>
|
|
144
|
+
>>> optimal_rate_audio(GeneratorAudioEquation(0).out_streams[0])
|
|
145
|
+
0
|
|
146
|
+
>>> (stream,) = GeneratorAudioEquation("sin(2*pi*440*t)").out_streams
|
|
147
|
+
>>> optimal_rate_audio(stream)
|
|
148
|
+
881
|
|
149
|
+
>>> (stream,) = GeneratorAudioEquation("1/2*cos(2*pi*440*t)").out_streams
|
|
150
|
+
>>> optimal_rate_audio(stream)
|
|
151
|
+
881
|
|
152
|
+
>>> (stream,) = GeneratorAudioEquation("cos(2*pi*440*t)+cos(2*pi*880*t)").out_streams
|
|
153
|
+
>>> optimal_rate_audio(stream)
|
|
154
|
+
1761
|
|
155
|
+
>>> (stream,) = GeneratorAudioEquation("cos(2*pi*440*t)**4").out_streams
|
|
156
|
+
>>> optimal_rate_audio(stream)
|
|
157
|
+
3521
|
|
158
|
+
>>> (stream,) = GeneratorAudioEquation("cos(2*pi*440*t)*cos(2*pi*880*t)").out_streams
|
|
159
|
+
>>> optimal_rate_audio(stream)
|
|
160
|
+
2641
|
|
161
|
+
>>> (stream,) = GeneratorAudioEquation("sin(2*pi*440*exp(-t))").out_streams
|
|
162
|
+
>>> optimal_rate_audio(stream)
|
|
163
|
+
881
|
|
164
|
+
>>> (stream,) = GeneratorAudioEquation("exp(-t**2/(2*1/1000))").out_streams
|
|
165
|
+
>>> optimal_rate_audio(stream)
|
|
166
|
+
192000
|
|
167
|
+
>>> (stream,) = GeneratorAudioEquation("max(-1, min(1, 100*t))").out_streams
|
|
168
|
+
>>> optimal_rate_audio(stream)
|
|
169
|
+
192000
|
|
170
|
+
>>>
|
|
171
|
+
"""
|
|
172
|
+
assert isinstance(stream.node, GeneratorAudioEquation), stream.node.__class__.__name__
|
|
173
|
+
|
|
174
|
+
t_symb = Symbol("t", real=True, positive=True)
|
|
175
|
+
freq = max(
|
|
176
|
+
_eq_estimate_freq_max(signal, t_symb, t_min, t_max) for signal in stream.node.signals
|
|
177
|
+
)
|
|
178
|
+
if math.isfinite(freq):
|
|
179
|
+
shannon = math.floor(2*freq) + 1 if freq else 0 # shannon strict superior to 2 f_max
|
|
180
|
+
return min(192000, shannon) # the max supported by some sound cards
|
|
181
|
+
return 192000
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@_add_estimator(GeneratorAudioNoise)
|
|
185
|
+
def _optimal_rate_generator_audio_noise(stream: StreamAudio, *_) -> int:
|
|
186
|
+
"""Detect the rate of a GeneratorAudioNoise stream.
|
|
187
|
+
|
|
188
|
+
Examples
|
|
189
|
+
--------
|
|
190
|
+
>>> from cutcutcodec.core.analysis.stream.rate_audio import optimal_rate_audio
|
|
191
|
+
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
192
|
+
>>> (stream,) = GeneratorAudioNoise(0).out_streams
|
|
193
|
+
>>> optimal_rate_audio(stream)
|
|
194
|
+
48000
|
|
195
|
+
>>>
|
|
196
|
+
"""
|
|
197
|
+
assert isinstance(stream.node, GeneratorAudioNoise), stream.node.__class__.__name__
|
|
198
|
+
return 48000
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def optimal_rate_audio(
|
|
202
|
+
stream: StreamAudio,
|
|
203
|
+
t_min: typing.Optional[Fraction] = None,
|
|
204
|
+
t_max: typing.Optional[typing.Union[Fraction, float]] = None,
|
|
205
|
+
) -> int:
|
|
206
|
+
"""Find the optimal sampling rate for a given audio stream.
|
|
207
|
+
|
|
208
|
+
Parameters
|
|
209
|
+
----------
|
|
210
|
+
stream : cutcutcodec.core.classes.stream_audio.StreamAudio
|
|
211
|
+
The audio stream that we want to find the optimal rate.
|
|
212
|
+
t_min : float, optional
|
|
213
|
+
The lower bound of the time slice estimation.
|
|
214
|
+
t_max : float, optional
|
|
215
|
+
The higher bound of the time slice estimation.
|
|
216
|
+
|
|
217
|
+
Returns
|
|
218
|
+
-------
|
|
219
|
+
framerate : int
|
|
220
|
+
The minimum samplerate that respects the Nyquist–Shannon theorem.
|
|
221
|
+
The special value 0 is returned if not special rate is suggested.
|
|
222
|
+
"""
|
|
223
|
+
# verifications
|
|
224
|
+
assert isinstance(stream, StreamAudio), stream.__class__.__name__
|
|
225
|
+
assert t_min is None or isinstance(t_min, Fraction), t_min.__class__.__name__
|
|
226
|
+
assert t_max is None or t_max == math.inf or isinstance(t_max, Fraction), t_max
|
|
227
|
+
|
|
228
|
+
# estimation of the best rate
|
|
229
|
+
t_min, t_max = t_min or stream.beginning, t_max or stream.beginning + stream.duration
|
|
230
|
+
if (estimator := RATE_ESTIMATORS.get(stream.node.__class__, None)) is not None:
|
|
231
|
+
return estimator(stream, t_min, t_max)
|
|
232
|
+
return max(
|
|
233
|
+
(
|
|
234
|
+
optimal_rate_audio(s, *t)
|
|
235
|
+
for s, *t in time_backprop(stream, t_min, t_max)
|
|
236
|
+
if s.type == "audio"
|
|
237
|
+
),
|
|
238
|
+
default=0,
|
|
239
|
+
)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Smartly choose the framerate of a video stream."""
|
|
4
|
+
|
|
5
|
+
from fractions import Fraction
|
|
6
|
+
import math
|
|
7
|
+
import typing
|
|
8
|
+
|
|
9
|
+
from cutcutcodec.core.analysis.stream.time_backprop import time_backprop
|
|
10
|
+
from cutcutcodec.core.classes.stream_video import StreamVideo
|
|
11
|
+
from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
FPS_ESTIMATORS = {} # to each node stream class, associate the func to find the optimal rate
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _add_estimator(node_cls: type) -> callable:
|
|
18
|
+
def _add_func(func) -> callable:
|
|
19
|
+
FPS_ESTIMATORS[node_cls] = func
|
|
20
|
+
return func
|
|
21
|
+
return _add_func
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@_add_estimator(ContainerInputFFMPEG)
|
|
25
|
+
def _optimal_rate_container_input_ffmpeg(stream: StreamVideo, *_) -> Fraction:
|
|
26
|
+
"""Detect the rate of a ContainerInputFFMPEG stream.
|
|
27
|
+
|
|
28
|
+
Examples
|
|
29
|
+
--------
|
|
30
|
+
>>> from cutcutcodec.core.analysis.stream.rate_video import optimal_rate_video
|
|
31
|
+
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
|
|
32
|
+
>>> (stream,) = ContainerInputFFMPEG("cutcutcodec/examples/video.mp4").out_streams
|
|
33
|
+
>>> optimal_rate_video(stream)
|
|
34
|
+
Fraction(25, 1)
|
|
35
|
+
>>>
|
|
36
|
+
"""
|
|
37
|
+
assert isinstance(stream.node, ContainerInputFFMPEG), stream.node.__class__.__name__
|
|
38
|
+
return stream.rate
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def optimal_rate_video(
|
|
42
|
+
stream: StreamVideo,
|
|
43
|
+
t_min: typing.Optional[Fraction] = None,
|
|
44
|
+
t_max: typing.Optional[typing.Union[Fraction, float]] = None,
|
|
45
|
+
choices: typing.Optional[set[Fraction]] = None,
|
|
46
|
+
) -> Fraction:
|
|
47
|
+
"""Find the optimal frame rate for a given video stream.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
stream : cutcutcodec.core.classes.stream_video.StreamVideo
|
|
52
|
+
The video stream that we want to find the optimal fps.
|
|
53
|
+
t_min : float, optional
|
|
54
|
+
The lower bound of the time slice estimation.
|
|
55
|
+
t_max : float, optional
|
|
56
|
+
The higher bound of the time slice estimation.
|
|
57
|
+
choices : set[Fraction], optional
|
|
58
|
+
The possible fps. If provide, returns the most appropriate fps of this set.
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
framerate : numbers.Real
|
|
63
|
+
The framerate (maximum) that allows to minimize / cancel the loss of information,
|
|
64
|
+
(minimum) and avoids an excess of frame that does not bring more information.
|
|
65
|
+
"""
|
|
66
|
+
# verifications
|
|
67
|
+
assert isinstance(stream, StreamVideo), stream.__class__.__name__
|
|
68
|
+
assert t_min is None or isinstance(t_min, Fraction), t_min.__class__.__name__
|
|
69
|
+
assert t_max is None or t_max == math.inf or isinstance(t_max, Fraction), t_max
|
|
70
|
+
if choices is not None:
|
|
71
|
+
assert isinstance(choices, set) and all(isinstance(r, Fraction) and r > 0 for r in choices)
|
|
72
|
+
|
|
73
|
+
# optimisation
|
|
74
|
+
if choices and len(choices) == 1: # case not nescessary to do computing
|
|
75
|
+
return choices.pop()
|
|
76
|
+
|
|
77
|
+
# estimation of the best fps
|
|
78
|
+
t_min, t_max = t_min or stream.beginning, t_max or stream.beginning + stream.duration
|
|
79
|
+
if (estimator := FPS_ESTIMATORS.get(stream.node.__class__, None)) is not None:
|
|
80
|
+
fps = estimator(stream, t_min, t_max)
|
|
81
|
+
else:
|
|
82
|
+
fps = max(
|
|
83
|
+
(
|
|
84
|
+
optimal_rate_video(s, *t)
|
|
85
|
+
for s, *t in time_backprop(stream, t_min, t_max)
|
|
86
|
+
if s.type == "video"
|
|
87
|
+
),
|
|
88
|
+
default=0,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# select the most appropriate rate among the choices
|
|
92
|
+
if not choices or not fps:
|
|
93
|
+
return min(choices) if choices else fps
|
|
94
|
+
for choice in sorted(choices):
|
|
95
|
+
if fps <= choice:
|
|
96
|
+
return choice
|
|
97
|
+
return max(choices)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Smartly choose the shape of a video stream."""
|
|
4
|
+
|
|
5
|
+
from fractions import Fraction
|
|
6
|
+
import math
|
|
7
|
+
import typing
|
|
8
|
+
|
|
9
|
+
from cutcutcodec.core.analysis.stream.time_backprop import time_backprop
|
|
10
|
+
from cutcutcodec.core.classes.stream_video import StreamVideo
|
|
11
|
+
from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
SHAPE_ESTIMATORS = {} # to each node stream class, associate the func to find the optimal rate
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _add_estimator(node_cls: type) -> callable:
|
|
18
|
+
def _add_func(func) -> callable:
|
|
19
|
+
SHAPE_ESTIMATORS[node_cls] = func
|
|
20
|
+
return func
|
|
21
|
+
return _add_func
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@_add_estimator(ContainerInputFFMPEG)
|
|
25
|
+
def _optimal_shape_container_input_ffmpeg(stream: StreamVideo, *_) -> Fraction:
|
|
26
|
+
"""Detect the shape of a ContainerInputFFMPEG.
|
|
27
|
+
|
|
28
|
+
Examples
|
|
29
|
+
--------
|
|
30
|
+
>>> from cutcutcodec.core.analysis.stream.shape import optimal_shape_video
|
|
31
|
+
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
|
|
32
|
+
>>> (stream,) = ContainerInputFFMPEG("cutcutcodec/examples/video.mp4").out_streams
|
|
33
|
+
>>> optimal_shape_video(stream)
|
|
34
|
+
(360, 640)
|
|
35
|
+
>>>
|
|
36
|
+
"""
|
|
37
|
+
assert isinstance(stream.node, ContainerInputFFMPEG), stream.node.__class__.__name__
|
|
38
|
+
return (stream.height, stream.width)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def optimal_shape_video(
|
|
42
|
+
stream: StreamVideo,
|
|
43
|
+
t_min: typing.Optional[Fraction] = None,
|
|
44
|
+
t_max: typing.Optional[typing.Union[Fraction, float]] = None,
|
|
45
|
+
choices: typing.Optional[set[tuple[int, int]]] = None,
|
|
46
|
+
) -> typing.Union[tuple[int, int], None]:
|
|
47
|
+
"""Find the optimal frame shape for a given video stream.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
stream : cutcutcodec.core.classes.stream_video.StreamVideo
|
|
52
|
+
The video stream that we want to find the optimal fps.
|
|
53
|
+
t_min : float, optional
|
|
54
|
+
The lower bound of the time slice estimation.
|
|
55
|
+
t_max : float, optional
|
|
56
|
+
The higher bound of the time slice estimation.
|
|
57
|
+
choices : set[tuple[int, int]], optional
|
|
58
|
+
The possible shape. If provide, returns the most appropriate shape of this set.
|
|
59
|
+
The convention adopted is the numpy convention (height, width) in pixels.
|
|
60
|
+
|
|
61
|
+
Returns
|
|
62
|
+
-------
|
|
63
|
+
shape : tuple[int, int]
|
|
64
|
+
The shape that limit the reshape informations and the information loss.
|
|
65
|
+
"""
|
|
66
|
+
# verifications
|
|
67
|
+
assert isinstance(stream, StreamVideo), stream.__class__.__name__
|
|
68
|
+
assert t_min is None or isinstance(t_min, Fraction), t_min.__class__.__name__
|
|
69
|
+
assert t_max is None or t_max == math.inf or isinstance(t_max, Fraction), t_max
|
|
70
|
+
if choices is not None:
|
|
71
|
+
assert isinstance(choices, set), choices.__class__.__name__
|
|
72
|
+
assert all(isinstance(s, tuple) for s in choices), choices
|
|
73
|
+
assert all(len(s) == 2 for s in choices), choices
|
|
74
|
+
assert all(isinstance(s[0], int) and isinstance(s[1], int) for s in choices), choices
|
|
75
|
+
assert all(min(s) >= 1 for s in choices), choices
|
|
76
|
+
|
|
77
|
+
def shape_key(shape):
|
|
78
|
+
"""Favorise little surface and square surface."""
|
|
79
|
+
height, width = shape
|
|
80
|
+
area = height * width
|
|
81
|
+
deformation = 2*math.sqrt(area) / (height + width) # 1 -> square, 0 -> flat
|
|
82
|
+
return area - deformation
|
|
83
|
+
|
|
84
|
+
# optimisation
|
|
85
|
+
if choices and len(choices) == 1: # case not nescessary to do computing
|
|
86
|
+
return choices.pop()
|
|
87
|
+
|
|
88
|
+
# estimation of the best shape
|
|
89
|
+
t_min, t_max = t_min or stream.beginning, t_max or stream.beginning + stream.duration
|
|
90
|
+
if (estimator := SHAPE_ESTIMATORS.get(stream.node.__class__, None)) is not None:
|
|
91
|
+
shape = estimator(stream, t_min, t_max)
|
|
92
|
+
else:
|
|
93
|
+
shapes = (
|
|
94
|
+
optimal_shape_video(s, *t) for s, *t in time_backprop(stream, t_min, t_max)
|
|
95
|
+
if s.type == "video"
|
|
96
|
+
)
|
|
97
|
+
shapes = [s for s in shapes if s is not None]
|
|
98
|
+
shape = (max(s[0] for s in shapes), max(s[1] for s in shapes)) if shapes else None
|
|
99
|
+
|
|
100
|
+
# select the most appropriate rate among the choices
|
|
101
|
+
if not choices or shape is None:
|
|
102
|
+
return min(choices, key=shape_key) if choices else shape
|
|
103
|
+
choices = sorted(choices, key=shape_key)
|
|
104
|
+
for choice in choices:
|
|
105
|
+
if shape[0] <= choice[0] and shape[1] <= choice[1]:
|
|
106
|
+
return choice
|
|
107
|
+
return choices[-1]
|