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,637 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Extract the properties of different streams of a multimedia file."""
|
|
4
|
+
|
|
5
|
+
from fractions import Fraction
|
|
6
|
+
import json
|
|
7
|
+
import numbers
|
|
8
|
+
import pathlib
|
|
9
|
+
import re
|
|
10
|
+
import subprocess
|
|
11
|
+
import typing
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
import tqdm
|
|
15
|
+
|
|
16
|
+
from cutcutcodec.core.exceptions import MissingInformation, MissingStreamError
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _decode_duration_ffmpeg(filename: str, index: int, accurate: bool) -> Fraction:
|
|
20
|
+
"""Extract the duration by the complete decoding of the stream.
|
|
21
|
+
|
|
22
|
+
Slow but 100% accurate method. The duration of the last frame is takn in considered.
|
|
23
|
+
Equivalent to:
|
|
24
|
+
``ffmpeg -thread 0 -loglevel quiet -stats -i file -map 0:v:0 -c:v rawvideo -f null /dev/null``
|
|
25
|
+
|
|
26
|
+
Examples
|
|
27
|
+
--------
|
|
28
|
+
>>> from cutcutcodec.core.analysis.ffprobe import _decode_duration_ffmpeg
|
|
29
|
+
>>> _decode_duration_ffmpeg("cutcutcodec/examples/audio_5.1_narration.oga", 0, accurate=True)
|
|
30
|
+
Fraction(8, 1)
|
|
31
|
+
>>> _decode_duration_ffmpeg("cutcutcodec/examples/video.mp4", 0, accurate=True)
|
|
32
|
+
Fraction(16, 1)
|
|
33
|
+
>>> _decode_duration_ffmpeg("cutcutcodec/examples/intro.webm", 0, accurate=True)
|
|
34
|
+
Fraction(9809, 1000)
|
|
35
|
+
>>>
|
|
36
|
+
"""
|
|
37
|
+
# get context
|
|
38
|
+
if not (data := get_metadata(filename).get("streams", [])) or index >= len(data):
|
|
39
|
+
raise MissingStreamError(f"only {len(data)} streams in '{filename}', no {index}")
|
|
40
|
+
data = data[index]
|
|
41
|
+
time_base = Fraction(data["time_base"])
|
|
42
|
+
headers, infos = get_slices_metadata(filename, slice_type=("frame" if accurate else "packet"))
|
|
43
|
+
last = dict(zip(headers[index], infos[index][-1, :]))
|
|
44
|
+
del headers, infos
|
|
45
|
+
|
|
46
|
+
# extract duration
|
|
47
|
+
for time_key in ("best_effort_timestamp", "pts", "pkt_pts", "dts", "pkt_dts"):
|
|
48
|
+
if (time := last.get(time_key, "N/A")) != "N/A":
|
|
49
|
+
time = int(time) * time_base
|
|
50
|
+
break
|
|
51
|
+
else: # if time not found
|
|
52
|
+
for time_key in (
|
|
53
|
+
"pts_time", "pkt_pts_time", "dts_time", "pkt_dts_time", "best_effort_timestamp_time"
|
|
54
|
+
):
|
|
55
|
+
if (time := last.get(time_key, "N/A")) != "N/A":
|
|
56
|
+
time = Fraction(time)
|
|
57
|
+
break
|
|
58
|
+
else:
|
|
59
|
+
raise MissingInformation(
|
|
60
|
+
"impossible to extract time of the last packet "
|
|
61
|
+
f"of the stream {index} of '{filename}'"
|
|
62
|
+
)
|
|
63
|
+
duration = 0
|
|
64
|
+
for duration_key in ("duration", "pkt_duration"):
|
|
65
|
+
if (duration := last.get(duration_key, "N/A")) != "N/A":
|
|
66
|
+
duration = int(duration) * time_base
|
|
67
|
+
break
|
|
68
|
+
else: # if duration not found
|
|
69
|
+
for duration_key in ("duration_time", "pkt_duration_time"):
|
|
70
|
+
if (duration := last.get(duration_key, "N/A")) != "N/A":
|
|
71
|
+
duration = Fraction(duration)
|
|
72
|
+
break
|
|
73
|
+
return time + duration
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _decode_timestamps_ffmpeg(
|
|
77
|
+
filename: str, index: int
|
|
78
|
+
) -> np.ndarray[typing.Union[None, Fraction]]:
|
|
79
|
+
"""Retrieve the exact position of the frames in a stream.
|
|
80
|
+
|
|
81
|
+
Examples
|
|
82
|
+
--------
|
|
83
|
+
>>> from cutcutcodec.core.analysis.ffprobe import _decode_timestamps_ffmpeg
|
|
84
|
+
>>> _decode_timestamps_ffmpeg(
|
|
85
|
+
... "cutcutcodec/examples/audio_5.1_narration.oga", 0
|
|
86
|
+
... ) # doctest: +ELLIPSIS
|
|
87
|
+
array([Fraction(0, 1), Fraction(4, 125), Fraction(8, 125),
|
|
88
|
+
Fraction(12, 125), Fraction(16, 125), Fraction(4, 25),
|
|
89
|
+
Fraction(24, 125), Fraction(28, 125), Fraction(32, 125),
|
|
90
|
+
...
|
|
91
|
+
Fraction(972, 125), Fraction(976, 125), Fraction(196, 25),
|
|
92
|
+
Fraction(984, 125), Fraction(988, 125), Fraction(992, 125),
|
|
93
|
+
Fraction(996, 125)], dtype=object)
|
|
94
|
+
>>> _decode_timestamps_ffmpeg("cutcutcodec/examples/video.mp4", 0) # doctest: +ELLIPSIS
|
|
95
|
+
array([Fraction(0, 1), Fraction(1, 25), Fraction(2, 25), Fraction(3, 25),
|
|
96
|
+
Fraction(4, 25), Fraction(1, 5), Fraction(6, 25), Fraction(7, 25),
|
|
97
|
+
Fraction(8, 25), Fraction(9, 25), Fraction(2, 5), Fraction(11, 25),
|
|
98
|
+
...
|
|
99
|
+
Fraction(393, 25), Fraction(394, 25), Fraction(79, 5),
|
|
100
|
+
Fraction(396, 25), Fraction(397, 25), Fraction(398, 25),
|
|
101
|
+
Fraction(399, 25)], dtype=object)
|
|
102
|
+
>>>
|
|
103
|
+
"""
|
|
104
|
+
# get context
|
|
105
|
+
if (headers := get_metadata(filename).get("streams", [])) and index < len(headers):
|
|
106
|
+
headers = headers[index]
|
|
107
|
+
if "time_base" in headers:
|
|
108
|
+
time_base = Fraction(headers["time_base"])
|
|
109
|
+
else:
|
|
110
|
+
time_base = 0
|
|
111
|
+
|
|
112
|
+
# decode frames
|
|
113
|
+
headers, infos = get_slices_metadata(filename, slice_type="frame")
|
|
114
|
+
if index >= len(headers):
|
|
115
|
+
raise MissingStreamError(f"only {len(headers)} streams in '{filename}', no {index}")
|
|
116
|
+
headers, infos = headers[index], infos[index]
|
|
117
|
+
|
|
118
|
+
# catch information
|
|
119
|
+
timestamps = []
|
|
120
|
+
for frame in infos:
|
|
121
|
+
data = dict(zip(headers, frame))
|
|
122
|
+
for time_key in ("best_effort_timestamp", "pts", "pkt_pts", "dts", "pkt_dts"):
|
|
123
|
+
if time_base and (time := data.get(time_key, "N/A")) != "N/A":
|
|
124
|
+
timestamps.append(int(time) * time_base)
|
|
125
|
+
break
|
|
126
|
+
else:
|
|
127
|
+
for time_key in (
|
|
128
|
+
"best_effort_timestamp_time", "pts_time", "pkt_pts_time", "dts_time",
|
|
129
|
+
"pkt_dts_time"
|
|
130
|
+
):
|
|
131
|
+
if (time := data.get(time_key, "N/A")) != "N/A":
|
|
132
|
+
timestamps.append(Fraction(time))
|
|
133
|
+
break
|
|
134
|
+
else:
|
|
135
|
+
timestamps.append(None)
|
|
136
|
+
|
|
137
|
+
# cast to ndarray
|
|
138
|
+
timestamps = np.array(timestamps, dtype=object)
|
|
139
|
+
return timestamps
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _estimate_duration_ffmpeg(filename: str, index: int, *, _indirect=True) -> Fraction:
|
|
143
|
+
"""Extract the duration from the metadata.
|
|
144
|
+
|
|
145
|
+
Very fast method but inaccurate. It doesn't work all the time.
|
|
146
|
+
|
|
147
|
+
Examples
|
|
148
|
+
--------
|
|
149
|
+
>>> from cutcutcodec.core.analysis.ffprobe import _estimate_duration_ffmpeg
|
|
150
|
+
>>> _estimate_duration_ffmpeg("cutcutcodec/examples/audio_5.1_narration.oga", 0)
|
|
151
|
+
Fraction(8, 1)
|
|
152
|
+
>>> _estimate_duration_ffmpeg("cutcutcodec/examples/video.mp4", 0)
|
|
153
|
+
Fraction(16, 1)
|
|
154
|
+
>>>
|
|
155
|
+
"""
|
|
156
|
+
metadata = get_metadata(filename)
|
|
157
|
+
if (stream_meta := metadata.get("streams", [])) and len(stream_meta) > index:
|
|
158
|
+
stream_meta = stream_meta[index]
|
|
159
|
+
if "duration_ts" in stream_meta and "time_base" in stream_meta:
|
|
160
|
+
return stream_meta["duration_ts"] * Fraction(stream_meta["time_base"])
|
|
161
|
+
if "duration" in stream_meta:
|
|
162
|
+
return Fraction(stream_meta["duration"])
|
|
163
|
+
for key, val in stream_meta.get("tags", {}).items():
|
|
164
|
+
if "duration" in key.lower():
|
|
165
|
+
if (duration := parse_duration(val)) is not None:
|
|
166
|
+
return duration
|
|
167
|
+
if (format_meta := metadata.get("format", None)) is not None and "duration" in format_meta:
|
|
168
|
+
return Fraction(format_meta["duration"])
|
|
169
|
+
|
|
170
|
+
if _indirect:
|
|
171
|
+
return (
|
|
172
|
+
_estimate_len_ffmpeg(filename, index, _indirect=False)
|
|
173
|
+
/ _estimate_rate_ffmpeg(filename, index, _indirect=False)
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
raise MissingInformation(
|
|
177
|
+
f"'ffprobe' did not get a correct duration in '{filename}' stream {index}"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _estimate_len_ffmpeg(filename: str, index: int, *, _indirect=True) -> int:
|
|
182
|
+
"""Extract the number of frames or samples from the metadata.
|
|
183
|
+
|
|
184
|
+
Very fast method but inaccurate. It doesn't work all the time.
|
|
185
|
+
|
|
186
|
+
Examples
|
|
187
|
+
--------
|
|
188
|
+
>>> from cutcutcodec.core.analysis.ffprobe import _estimate_len_ffmpeg
|
|
189
|
+
>>> _estimate_len_ffmpeg("cutcutcodec/examples/audio_5.1_narration.oga", 0)
|
|
190
|
+
128000
|
|
191
|
+
>>> _estimate_len_ffmpeg("cutcutcodec/examples/video.mp4", 0)
|
|
192
|
+
400
|
|
193
|
+
>>>
|
|
194
|
+
"""
|
|
195
|
+
metadata = get_metadata(filename)
|
|
196
|
+
if not ((stream_meta := metadata.get("streams", [])) and len(stream_meta) > index):
|
|
197
|
+
raise MissingStreamError(f"no stream {index} metadata detected in '{filename}'")
|
|
198
|
+
stream_meta = stream_meta[index]
|
|
199
|
+
|
|
200
|
+
if "nb_frames" in stream_meta:
|
|
201
|
+
return int(stream_meta["nb_frames"])
|
|
202
|
+
|
|
203
|
+
if _indirect:
|
|
204
|
+
return round(
|
|
205
|
+
_estimate_duration_ffmpeg(filename, index, _indirect=False)
|
|
206
|
+
* _estimate_rate_ffmpeg(filename, index, _indirect=False)
|
|
207
|
+
)
|
|
208
|
+
raise MissingInformation(
|
|
209
|
+
f"'ffprobe' did not get a correct frames number in '{filename}' stream {index}"
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _estimate_rate_ffmpeg(filename: str, index: int, *, _indirect=True) -> Fraction:
|
|
214
|
+
"""Retrieve via ffmpeg, the metadata concerning the fps or the framerate.
|
|
215
|
+
|
|
216
|
+
This function is fast because it reads only the header of the file.
|
|
217
|
+
|
|
218
|
+
Examples
|
|
219
|
+
--------
|
|
220
|
+
>>> from cutcutcodec.core.analysis.ffprobe import _estimate_rate_ffmpeg
|
|
221
|
+
>>> _estimate_rate_ffmpeg("cutcutcodec/examples/audio_5.1_narration.oga", 0)
|
|
222
|
+
Fraction(16000, 1)
|
|
223
|
+
>>> _estimate_rate_ffmpeg("cutcutcodec/examples/video.mp4", 0)
|
|
224
|
+
Fraction(25, 1)
|
|
225
|
+
>>>
|
|
226
|
+
"""
|
|
227
|
+
metadata = get_metadata(filename)
|
|
228
|
+
if not ((stream_meta := metadata.get("streams", [])) and len(stream_meta) > index):
|
|
229
|
+
raise MissingStreamError(f"no stream {index} metadata detected in '{filename}'")
|
|
230
|
+
stream_meta = stream_meta[index]
|
|
231
|
+
|
|
232
|
+
for rate_key in ("r_frame_rate", "sample_rate", "avg_frame_rate"):
|
|
233
|
+
if rate_key in stream_meta:
|
|
234
|
+
try:
|
|
235
|
+
return Fraction(stream_meta[rate_key])
|
|
236
|
+
except ZeroDivisionError:
|
|
237
|
+
continue
|
|
238
|
+
|
|
239
|
+
if _indirect:
|
|
240
|
+
return (
|
|
241
|
+
_estimate_len_ffmpeg(filename, index, _indirect=False)
|
|
242
|
+
/ _estimate_duration_ffmpeg(filename, index, _indirect=False)
|
|
243
|
+
)
|
|
244
|
+
raise MissingInformation(
|
|
245
|
+
f"'ffprobe' did not get a correct framerate in '{filename}' stream {index}"
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _get_streams_type(filename: typing.Union[str, bytes, pathlib.Path]) -> list[str]:
|
|
250
|
+
"""Help ``get_streams_type``."""
|
|
251
|
+
cmd = [
|
|
252
|
+
"ffprobe", "-v", "error",
|
|
253
|
+
"-show_entries", "stream=index,codec_type",
|
|
254
|
+
"-of", "csv=p=0", str(filename),
|
|
255
|
+
]
|
|
256
|
+
try:
|
|
257
|
+
result = subprocess.run(cmd, capture_output=True, check=True)
|
|
258
|
+
except subprocess.CalledProcessError as err:
|
|
259
|
+
raise MissingStreamError(f"'ffprobe' can not open '{filename}'") from err
|
|
260
|
+
if not (indexs_streams := result.stdout.decode().strip().split("\n")):
|
|
261
|
+
raise MissingStreamError(f"'ffprobe' did not find any stream info in '{filename}'")
|
|
262
|
+
|
|
263
|
+
indexs_streams = [ind for ind in indexs_streams if ind]
|
|
264
|
+
streams = {}
|
|
265
|
+
for index_stream in indexs_streams:
|
|
266
|
+
index, stream, *_ = index_stream.split(",")
|
|
267
|
+
index = int(index)
|
|
268
|
+
if streams.get(index, None) is not None and stream != streams[index]:
|
|
269
|
+
raise MissingStreamError(f"index {index} appears twice in '{filename}'")
|
|
270
|
+
if stream not in {"audio", "subtitle", "video"}:
|
|
271
|
+
raise ValueError(
|
|
272
|
+
f"the stream {index} ({stream}) in '{filename}' "
|
|
273
|
+
"not in 'audio', 'video' or 'subtitle'"
|
|
274
|
+
)
|
|
275
|
+
streams[index] = stream
|
|
276
|
+
|
|
277
|
+
if streams.keys() != set(range(len(streams))):
|
|
278
|
+
raise MissingStreamError(f"missing stream index in '{filename}', {streams}")
|
|
279
|
+
|
|
280
|
+
return [streams[i] for i in range(len(streams))]
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _help_slices_metadata_context(filename: pathlib.Path) -> tuple[list[Fraction], Fraction]:
|
|
284
|
+
"""Help ``get_slices_metadata``."""
|
|
285
|
+
if not (data := get_metadata(filename).get("streams", [])):
|
|
286
|
+
raise MissingStreamError(f"no stream metadata detected in '{filename}'")
|
|
287
|
+
times_base = [Fraction(s["time_base"]) for s in data if "time_base" in s]
|
|
288
|
+
if len(times_base) != len(data):
|
|
289
|
+
raise MissingInformation(
|
|
290
|
+
f"the field 'time_base' is not founded for all streams metadata of '{filename}'"
|
|
291
|
+
)
|
|
292
|
+
duration = Fraction(0)
|
|
293
|
+
for stream_index in range(len(times_base)):
|
|
294
|
+
try:
|
|
295
|
+
duration = max(duration, _estimate_duration_ffmpeg(filename, stream_index))
|
|
296
|
+
except MissingInformation:
|
|
297
|
+
continue
|
|
298
|
+
return times_base, duration
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _help_slices_metadata_parse_data(data, sort_new_h, sort_old_h=None):
|
|
302
|
+
"""Help ``get_slices_metadata``."""
|
|
303
|
+
if not isinstance(data, dict):
|
|
304
|
+
data = dict(zip(sort_old_h, data))
|
|
305
|
+
data = [[data.get(h, "N/A") for h in sort_new_h]]
|
|
306
|
+
data = np.array(data, dtype="U")
|
|
307
|
+
return data
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def _map_index_rel_to_abs(filename: str, index: int, stream_type: str) -> int:
|
|
311
|
+
"""Relative stream index to absolute stream index.
|
|
312
|
+
|
|
313
|
+
Examples
|
|
314
|
+
--------
|
|
315
|
+
>>> from cutcutcodec.core.analysis.ffprobe import _map_index_rel_to_abs
|
|
316
|
+
>>> _map_index_rel_to_abs("cutcutcodec/examples/intro.webm", 0, "video")
|
|
317
|
+
0
|
|
318
|
+
>>> _map_index_rel_to_abs("cutcutcodec/examples/intro.webm", 1, "video")
|
|
319
|
+
1
|
|
320
|
+
>>> _map_index_rel_to_abs("cutcutcodec/examples/intro.webm", 0, "audio")
|
|
321
|
+
2
|
|
322
|
+
>>> _map_index_rel_to_abs("cutcutcodec/examples/intro.webm", 1, "audio")
|
|
323
|
+
3
|
|
324
|
+
>>>
|
|
325
|
+
"""
|
|
326
|
+
types = get_streams_type(filename)
|
|
327
|
+
abs_indexs = [i for i, t in enumerate(types) if t == stream_type]
|
|
328
|
+
if index >= len(abs_indexs):
|
|
329
|
+
raise MissingStreamError(
|
|
330
|
+
f"relative {stream_type} index {index} of '{filename}' not in {types}"
|
|
331
|
+
)
|
|
332
|
+
return abs_indexs[index]
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def get_metadata(
|
|
336
|
+
filename: typing.Union[str, bytes, pathlib.Path], ignore_errors=False
|
|
337
|
+
) -> dict[str]:
|
|
338
|
+
"""Call ``ffprobe`` and parse the result as a dictionary.
|
|
339
|
+
|
|
340
|
+
Parameters
|
|
341
|
+
----------
|
|
342
|
+
filename : pathlike
|
|
343
|
+
The pathlike of the file containing streams.
|
|
344
|
+
ignore_errors : boolean, default=False
|
|
345
|
+
If True, returns an empty dict
|
|
346
|
+
rather than throwing an exception if invalid data are detected.
|
|
347
|
+
|
|
348
|
+
Returns
|
|
349
|
+
-------
|
|
350
|
+
metadata : dict
|
|
351
|
+
All the metadata containing in the container and each streams.
|
|
352
|
+
|
|
353
|
+
Examples
|
|
354
|
+
--------
|
|
355
|
+
>>> from pprint import pprint
|
|
356
|
+
>>> from cutcutcodec.core.analysis.ffprobe import get_metadata
|
|
357
|
+
>>> pprint(get_metadata("cutcutcodec/examples/audio_5.1_narration.oga")) # doctest: +ELLIPSIS
|
|
358
|
+
{'format': {'bit_rate': '34982',
|
|
359
|
+
'duration': '8.000000',
|
|
360
|
+
'filename': 'cutcutcodec/examples/audio_5.1_narration.oga',
|
|
361
|
+
'format_long_name': 'Ogg',
|
|
362
|
+
'format_name': 'ogg',
|
|
363
|
+
'nb_programs': 0,
|
|
364
|
+
'nb_streams': 1,
|
|
365
|
+
'probe_score': 100,
|
|
366
|
+
'size': '34982',
|
|
367
|
+
'start_time': '0.000000'},
|
|
368
|
+
'streams': [{'avg_frame_rate': '0/0',
|
|
369
|
+
'bit_rate': '96000',
|
|
370
|
+
'bits_per_sample': 0,
|
|
371
|
+
'channel_layout': '5.1',
|
|
372
|
+
'channels': 6,
|
|
373
|
+
'codec_long_name': 'Vorbis',
|
|
374
|
+
'codec_name': 'vorbis',
|
|
375
|
+
'codec_tag': '0x0000',
|
|
376
|
+
'codec_tag_string': '[0][0][0][0]',
|
|
377
|
+
'codec_type': 'audio',
|
|
378
|
+
'disposition': {'attached_pic': 0,
|
|
379
|
+
...
|
|
380
|
+
'visual_impaired': 0},
|
|
381
|
+
'duration': '8.000000',
|
|
382
|
+
...
|
|
383
|
+
'sample_rate': '16000',
|
|
384
|
+
'start_pts': 0,
|
|
385
|
+
'start_time': '0.000000',
|
|
386
|
+
'tags': {'encoder': 'Lavc59.37.100 libvorbis'},
|
|
387
|
+
'time_base': '1/16000'}]}
|
|
388
|
+
>>>
|
|
389
|
+
"""
|
|
390
|
+
filename = pathlib.Path(filename)
|
|
391
|
+
assert filename.exists(), filename
|
|
392
|
+
assert isinstance(ignore_errors, bool), ignore_errors.__class__.__name__
|
|
393
|
+
|
|
394
|
+
cmd = [
|
|
395
|
+
"ffprobe", "-v", "error",
|
|
396
|
+
"-show_format", "-show_streams", "-show_programs", "-show_chapters",
|
|
397
|
+
"-of", "json", str(filename),
|
|
398
|
+
]
|
|
399
|
+
try:
|
|
400
|
+
result = subprocess.run(cmd, capture_output=True, check=True)
|
|
401
|
+
except subprocess.CalledProcessError as err:
|
|
402
|
+
if ignore_errors:
|
|
403
|
+
return {}
|
|
404
|
+
raise MissingInformation(f"can not open '{filename}' with 'ffprobe'") from err
|
|
405
|
+
if not (meta_str := result.stdout.decode()) and not ignore_errors:
|
|
406
|
+
raise MissingInformation(f"'ffprobe' did not decode '{filename}'")
|
|
407
|
+
try:
|
|
408
|
+
meta_dict = json.loads(meta_str)
|
|
409
|
+
except json.decoder.JSONDecodeError:
|
|
410
|
+
if ignore_errors:
|
|
411
|
+
return {}
|
|
412
|
+
meta_dict = {k: v for k, v in meta_dict.items() if v}
|
|
413
|
+
return meta_dict
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def get_slices_metadata(
|
|
417
|
+
filename: typing.Union[str, bytes, pathlib.Path], slice_type: str = "frame"
|
|
418
|
+
) -> tuple[list[list[str]], list[np.ndarray]]:
|
|
419
|
+
"""Get the packets informations for all streams.
|
|
420
|
+
|
|
421
|
+
Parameters
|
|
422
|
+
----------
|
|
423
|
+
filename : pathlike
|
|
424
|
+
The pathlike of the file containing streams.
|
|
425
|
+
slice_type : str
|
|
426
|
+
The type of slices to decode, 'frame' or 'packet'.
|
|
427
|
+
'frame' is slower but more accurate and informative.
|
|
428
|
+
'packet' is faster but less acurate.
|
|
429
|
+
|
|
430
|
+
Returns
|
|
431
|
+
-------
|
|
432
|
+
headers : list[list[str]]
|
|
433
|
+
For each stream, the name of the columns.
|
|
434
|
+
infos: list[np.ndarray]
|
|
435
|
+
For each stream, the 2d str array.
|
|
436
|
+
Each row correspond to one packet.
|
|
437
|
+
|
|
438
|
+
Examples
|
|
439
|
+
--------
|
|
440
|
+
>>> from pprint import pprint
|
|
441
|
+
>>> from cutcutcodec.core.analysis.ffprobe import get_slices_metadata
|
|
442
|
+
>>> headers, data = (
|
|
443
|
+
... get_slices_metadata("cutcutcodec/examples/audio_5.1_narration.oga", slice_type="packet")
|
|
444
|
+
... )
|
|
445
|
+
>>> pprint(headers) # doctest: +ELLIPSIS
|
|
446
|
+
[['codec_type',
|
|
447
|
+
...
|
|
448
|
+
'stream_index']]
|
|
449
|
+
>>> pprint(data) # doctest: +ELLIPSIS
|
|
450
|
+
[array([['audio', ..., '0'],
|
|
451
|
+
['audio', ..., '0'],
|
|
452
|
+
... dtype='<U15')]
|
|
453
|
+
>>> headers, data = get_slices_metadata("cutcutcodec/examples/video.mp4", slice_type="packet")
|
|
454
|
+
>>> pprint(headers)
|
|
455
|
+
[['codec_type',
|
|
456
|
+
'dts',
|
|
457
|
+
'dts_time',
|
|
458
|
+
'duration',
|
|
459
|
+
'duration_time',
|
|
460
|
+
'flags',
|
|
461
|
+
'pos',
|
|
462
|
+
'pts',
|
|
463
|
+
'pts_time',
|
|
464
|
+
'size',
|
|
465
|
+
'stream_index']]
|
|
466
|
+
>>> pprint(data)
|
|
467
|
+
[array([['video', '-1024', '-0.080000', ..., '0.000000', '5156', '0'],
|
|
468
|
+
['video', '-512', '-0.040000', ..., '0.240000', '845', '0'],
|
|
469
|
+
['video', '0', '0.000000', ..., '0.120000', '372', '0'],
|
|
470
|
+
...,
|
|
471
|
+
['video', '202240', '15.800000', ..., '15.960000', '354', '0'],
|
|
472
|
+
['video', '202752', '15.840000', ..., '15.920000', '247', '0'],
|
|
473
|
+
['video', '203264', '15.880000', ..., '15.880000', '192', '0']],
|
|
474
|
+
dtype='<U9')]
|
|
475
|
+
>>>
|
|
476
|
+
"""
|
|
477
|
+
filename = pathlib.Path(filename)
|
|
478
|
+
assert filename.exists(), filename
|
|
479
|
+
assert isinstance(slice_type, str), slice_type.__class__.__name__
|
|
480
|
+
assert slice_type in {"frame", "packet"}, slice_type
|
|
481
|
+
|
|
482
|
+
# create subprocess, as soon as possible to start calculations
|
|
483
|
+
with subprocess.Popen(
|
|
484
|
+
[
|
|
485
|
+
"ffprobe", "-v", "error",
|
|
486
|
+
f"-show_{slice_type}s",
|
|
487
|
+
"-of", "compact", str(filename)
|
|
488
|
+
],
|
|
489
|
+
stdout=subprocess.PIPE
|
|
490
|
+
) as child:
|
|
491
|
+
|
|
492
|
+
# get context
|
|
493
|
+
times_base, duration = _help_slices_metadata_context(filename)
|
|
494
|
+
|
|
495
|
+
# declaration
|
|
496
|
+
headers_infos = [
|
|
497
|
+
[set() for _ in range(len(times_base))], # contains all headers
|
|
498
|
+
[[] for _ in range(len(times_base))], # contains the dictionary for each streams
|
|
499
|
+
]
|
|
500
|
+
|
|
501
|
+
# display avancement
|
|
502
|
+
with tqdm.tqdm(
|
|
503
|
+
desc=f"Decoding {slice_type} of {pathlib.Path(filename).name}",
|
|
504
|
+
total=float(duration),
|
|
505
|
+
dynamic_ncols=True,
|
|
506
|
+
bar_format="{l_bar}{bar}| {n:.0f}s/{total:.0f}s [{elapsed}<{remaining}]",
|
|
507
|
+
disable=(duration < 60),
|
|
508
|
+
) as progress_bar:
|
|
509
|
+
|
|
510
|
+
# parse result
|
|
511
|
+
while (data := child.stdout.readline()) or child.poll() is None:
|
|
512
|
+
data = data.decode().strip()
|
|
513
|
+
if not data.startswith(slice_type):
|
|
514
|
+
continue
|
|
515
|
+
data = dict((field.split("=")+["N/A"])[:2] for field in data.split("|")[1:])
|
|
516
|
+
data = {k: v for k, v in data.items() if v != "N/A"}
|
|
517
|
+
stream_index = int(data["stream_index"])
|
|
518
|
+
data_keys = set(data)
|
|
519
|
+
sort_all_h = sorted(headers_infos[0][stream_index] | data_keys)
|
|
520
|
+
|
|
521
|
+
# management append new header
|
|
522
|
+
if not data_keys.issubset(headers_infos[0][stream_index]):
|
|
523
|
+
sort_old_h = sorted(headers_infos[0][stream_index])
|
|
524
|
+
headers_infos[1][stream_index] = [
|
|
525
|
+
_help_slices_metadata_parse_data(d.ravel(), sort_all_h, sort_old_h)
|
|
526
|
+
for d in headers_infos[1][stream_index]
|
|
527
|
+
]
|
|
528
|
+
headers_infos[0][stream_index] |= data_keys
|
|
529
|
+
|
|
530
|
+
# append new data
|
|
531
|
+
headers_infos[1][stream_index].append(
|
|
532
|
+
_help_slices_metadata_parse_data(data, sort_all_h)
|
|
533
|
+
)
|
|
534
|
+
if sum(len(inf) for inf in headers_infos[1]) == 500_000: # memory compression
|
|
535
|
+
headers_infos[1] = [[np.vstack(d)] if d else [] for d in headers_infos[1]]
|
|
536
|
+
|
|
537
|
+
# update display
|
|
538
|
+
for time_key in ("best_effort_timestamp", "pts", "pkt_pts", "dts", "pkt_dts"):
|
|
539
|
+
if (time := data.get(time_key, "N/A")) != "N/A":
|
|
540
|
+
if (time := float(int(time) * times_base[stream_index])) > progress_bar.n:
|
|
541
|
+
progress_bar.update(time - progress_bar.n)
|
|
542
|
+
break
|
|
543
|
+
|
|
544
|
+
# close subprocess
|
|
545
|
+
data = child.communicate()
|
|
546
|
+
progress_bar.update(progress_bar.total - progress_bar.n)
|
|
547
|
+
if child.returncode:
|
|
548
|
+
raise OSError(child.returncode, b" and ".join(data).decode())
|
|
549
|
+
|
|
550
|
+
# parse
|
|
551
|
+
headers_infos[0] = [sorted(h) for h in headers_infos[0]]
|
|
552
|
+
headers_infos[1] = [np.vstack(d) if d else [] for d in headers_infos[1]]
|
|
553
|
+
return headers_infos
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
def get_streams_type(
|
|
557
|
+
filename: typing.Union[str, bytes, pathlib.Path], ignore_errors=False
|
|
558
|
+
) -> list[str]:
|
|
559
|
+
"""Retrieve in order the stream types present in the file.
|
|
560
|
+
|
|
561
|
+
Parameters
|
|
562
|
+
----------
|
|
563
|
+
filename : pathlike
|
|
564
|
+
The pathlike of the file containing streams.
|
|
565
|
+
ignore_errors : boolean, default=False
|
|
566
|
+
If True, returns an empty list
|
|
567
|
+
rather than throwing an exception if no valid stream is detected.
|
|
568
|
+
|
|
569
|
+
Returns
|
|
570
|
+
-------
|
|
571
|
+
streams_type : list[str]
|
|
572
|
+
Each item can be "audio", "subtitle" or "video".
|
|
573
|
+
|
|
574
|
+
Raises
|
|
575
|
+
------
|
|
576
|
+
MissingStreamError
|
|
577
|
+
If ``ignore_errors`` is False and if one of the indexes is missing or redondant.
|
|
578
|
+
|
|
579
|
+
Examples
|
|
580
|
+
--------
|
|
581
|
+
>>> from cutcutcodec.core.analysis.ffprobe import get_streams_type
|
|
582
|
+
>>> get_streams_type("cutcutcodec/examples/intro.webm")
|
|
583
|
+
['video', 'video', 'audio', 'audio']
|
|
584
|
+
>>> get_streams_type("cutcutcodec/__main__.py", ignore_errors=True)
|
|
585
|
+
[]
|
|
586
|
+
>>>
|
|
587
|
+
"""
|
|
588
|
+
filename = pathlib.Path(filename)
|
|
589
|
+
assert filename.exists(), filename
|
|
590
|
+
assert isinstance(ignore_errors, bool), ignore_errors.__class__.__name__
|
|
591
|
+
|
|
592
|
+
try:
|
|
593
|
+
return _get_streams_type(filename)
|
|
594
|
+
except MissingStreamError as err:
|
|
595
|
+
if ignore_errors:
|
|
596
|
+
return []
|
|
597
|
+
raise err
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def parse_duration(duration: typing.Union[numbers.Real, str]) -> typing.Union[None, Fraction]:
|
|
601
|
+
"""Try to convert a duration information into a fraction in second.
|
|
602
|
+
|
|
603
|
+
Parameters
|
|
604
|
+
----------
|
|
605
|
+
duration : number or str
|
|
606
|
+
The duration to cast in integer
|
|
607
|
+
|
|
608
|
+
Returns
|
|
609
|
+
-------
|
|
610
|
+
sec_duration : Fraction
|
|
611
|
+
The decoded duration in second.
|
|
612
|
+
|
|
613
|
+
Examples
|
|
614
|
+
--------
|
|
615
|
+
>>> from cutcutcodec.core.analysis.ffprobe import parse_duration
|
|
616
|
+
>>> parse_duration(1.5) # from float
|
|
617
|
+
Fraction(3, 2)
|
|
618
|
+
>>> parse_duration(2) # from integer
|
|
619
|
+
Fraction(2, 1)
|
|
620
|
+
>>> parse_duration(".5") # from float rep
|
|
621
|
+
Fraction(1, 2)
|
|
622
|
+
>>> parse_duration("1.") # from float rep
|
|
623
|
+
Fraction(1, 1)
|
|
624
|
+
>>> parse_duration("1.5") # from complete float rep
|
|
625
|
+
Fraction(3, 2)
|
|
626
|
+
>>> parse_duration("1:01:01") # from h:m:s
|
|
627
|
+
Fraction(3661, 1)
|
|
628
|
+
>>>
|
|
629
|
+
"""
|
|
630
|
+
assert isinstance(duration, (numbers.Real, str)), duration.__class__.__name__
|
|
631
|
+
try:
|
|
632
|
+
return Fraction(duration)
|
|
633
|
+
except ValueError:
|
|
634
|
+
pass
|
|
635
|
+
if (match := re.fullmatch(r"(?P<h>\d+):(?P<m>\d\d):(?P<s>\d*\.?\d+)", duration)):
|
|
636
|
+
return 3600*int(match["h"]) + 60*int(match["m"]) + Fraction(match["s"])
|
|
637
|
+
return None
|