### Installing Go Dependencies for BabitMF (Shell) Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb This snippet installs necessary Go-related system dependencies using `apt` and sets the `GOPATH` environment variable. It is intended to be run once in a Python runtime environment like Colab before proceeding with Go-specific operations. ```shell # (1.1) run this cell first time using python runtime !apt update !apt install golang-go !apt-get install libdw-dev %env GOPATH=/root/go # (1.2) then refresh, it will now use gophernotes. Skip to golang in later cells ``` -------------------------------- ### Installing BMF and ONNX Runtime (Python) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/aesthetic_assessment/aesmod_bmfv3_fin.ipynb This snippet installs the `BabitMF` library and `onnxruntime` using `pip`, which are essential dependencies for running BMF applications and performing ONNX model inference. ```python !pip install BabitMF !pip3 install onnxruntime ``` -------------------------------- ### Downloading Sample BMF Assets (Shell) Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb This snippet downloads a compressed archive of sample video assets from the BabitMF GitHub releases and then extracts its contents, providing media files for testing or demonstration. ```shell !wget https://github.com/BabitMF/bmf/releases/download/files/files.tar.gz !tar -zvxf files.tar.gz ``` -------------------------------- ### Setting Up BMF and Real-ESRGAN Environment (Python) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/video_enhance/bmf-enhance-demo.ipynb This snippet installs essential Python packages for the BMF project, including BabitMF, basicsr, realesrgan, and torchvision. It also installs wurlitzer and loads its extension for capturing C extension module logs, and downloads a file using gdown. ```Python !gdown --fuzzy https://drive.google.com/file/d/1vvUssyc8GC8SPzVdYwRwKc2OvyKGY-Px/view?usp=sharing !pip install BabitMF basicsr==1.4.2 realesrgan torchvision==0.15.2 !pip install wurlitzer %load_ext wurlitzer ``` -------------------------------- ### Installing BabitMF Python Package Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_cpp.ipynb This command installs the `BabitMF` Python package using pip, making the BMF library accessible within the Python environment. It's the primary way to get the BMF Python bindings. ```python !pip install BabitMF ``` -------------------------------- ### Installing BabitMF Python Library Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_python.ipynb This snippet demonstrates how to install the BabitMF Python library using pip, which is the first step to integrate the framework into your Python project or Colab notebook. ```Shell !pip install BabitMF ``` -------------------------------- ### Installing System Dependencies (Linux) - Python Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_cpp.ipynb This snippet updates the package list and installs `libdw-dev`, a development library often required for debugging tools or specific software builds on Linux systems. These are system-level prerequisites for the BMF library. ```python !apt update !apt-get install libdw-dev ``` -------------------------------- ### Implementing Concurrent Synchronous Transcoding with BMF Go SDK Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb This function illustrates a concurrent synchronous video transcoding pipeline using the BMF Go SDK. It sets up decoder, encoder, and pass-through modules and uses Go channels to manage packet flow between the pass-through and encoder stages, enabling parallel processing of video frames. The snippet shows the setup and the goroutine for the pass-through module. ```Go func syncMode() { done := false decoder, err0 := bmf.NewModuleFunctorBuiltin("c_ffmpeg_decoder", map[string]interface{}{ "input_path": "./files/big_bunny_10s_30fps.mp4", }, 0, 1) if decoder == nil { fmt.Printf("Load decoder module failed %v\n", err0) } else { fmt.Printf("Load decoder module successful\n") } encoder, err1 := bmf.NewModuleFunctorBuiltin("c_ffmpeg_encoder", map[string]interface{}{ "output_path": "./output_sync_mode.mp4", }, 1, 0) if encoder == nil { fmt.Printf("Load encoder module failed %v\n", err1) } else { fmt.Printf("Load encoder module successful\n") } pass, err2 := bmf.NewModuleFunctorBuiltin("pass_through", nil, 1, 1) if pass == nil { fmt.Printf("Load pass_through module failed %v\n", err2) } else { fmt.Printf("Load pass_through module successful\n") } passChan := make(chan []*bmf.Packet, 10) encChan := make(chan []*bmf.Packet, 10) fmt.Println("Sync mode") // PassThrough go func() { for opkts_dec := range passChan { eofSet := false // do pass_through module for i := 0; i < len(opkts_dec); i++ { ipkts_pass := []*bmf.Packet{} ipkts_pass = append(ipkts_pass, opkts_dec[i]) if opkts_dec[i].Timestamp() == bmf.EOF { eofSet = true } _, err2 := pass.Execute(ipkts_pass, true) if err2 != nil { fmt.Printf("Pass Through failed! %v\n", err2) break } opkts_pass, err1 := pass.Fetch(0) if err1 != nil { fmt.Printf("Pass Through Fetch failed! error : %v\n", err1) break } // do encoder module for i := 0; i < len(opkts_pass); i++ { encChan <- []*bmf.Packet{opkts_pass[i]} } } if eofSet { fmt.Println("pass done") encChan <- []*bmf.Packet{bmf.GenerateEofPacket()} pass.Free() break } } }() // Encoder go func() { for opkts_pass := range encChan { eofSet := false // do encoder module for i := 0; i < len(opkts_pass); i++ { _, err := encoder.Call([]*bmf.Packet{opkts_pass[i]}) if err != nil { fmt.Printf("encoder call failed! error : %v\n", err) break } if opkts_pass[i].Timestamp() == bmf.EOF { eofSet = true } ``` -------------------------------- ### Locating Project and Library Directories (Bash) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/wasm/README.md This Bash script identifies the absolute paths for the BMF project directory containing HTML demos and the BMF library directory where built-in modules are located. It uses `find` and `realpath` commands to ensure correct paths for subsequent setup steps. ```bash PATH_TO_YOUR_PROJECT=... SERVER_DIRECTORY=$(realpath "$(dirname "$(find $PATH_TO_YOUR_PROJECT -name "demo_copy_module.html")")") LIB_DIRCTORY=$(realpath $(dirname $(find $PATH_TO_YOUR_PROJECT/build/output/bmf/lib -name "libbuiltin_modules.so"))) ``` -------------------------------- ### Verifying BMF Environment Configuration (Shell) Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb This snippet checks the location of the `bmf_env` script, displays its content, and then executes it to ensure the BMF C library environment variables are correctly set up. ```shell ! which bmf_env ! cat /usr/local/bin/bmf_env ! bmf_env ``` -------------------------------- ### Compiling Go Project for BMF Library Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb This Python snippet executes shell commands to compile a Go project. It initializes a new Go module named 'test', tidies up module dependencies, and then builds the `sync_mode.go` file into an executable. This is a prerequisite step before running the Go application. ```Python !go mod init test !go mod tidy !go build sync_mode.go ``` -------------------------------- ### Cloning BMF Source Repository (Python) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/aesthetic_assessment/aesmod_bmfv3_fin.ipynb This snippet clones the official BabitMF GitHub repository, providing access to the BMF source code, including demo modules and examples necessary for development and testing. ```python !git clone https://github.com/BabitMF/bmf.git ``` -------------------------------- ### Importing Libraries and Initializing Logger in Python Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/aesthetic_assessment/aesmod_bmfv3_fin.ipynb This snippet imports necessary libraries for numerical operations, image processing, ONNX runtime, and logging. It also sets up a global logger instance for consistent logging throughout the module. ```Python from module_utils import SyncModule import os import time import json import pdb import os.path as osp import numpy as np os.environ["OMP_NUM_THREADS"] = "8" import onnxruntime as ort import torch import logging import cv2 def get_logger(): return logging.getLogger("main") LOGGER = get_logger() ``` -------------------------------- ### Installing BabitMF Python Package (Shell) Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb This command installs the BabitMF Python library using `pip`, making it available for use within the Python environment. ```shell !pip install BabitMF ``` -------------------------------- ### Downloading and Extracting Sample Video Files Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_python.ipynb This code block illustrates how to download a compressed archive of sample transcoded video files (e.g., Big Bunny) from the BMF GitHub releases and then extract them. These files serve as example input for BMF operations. ```Shell !wget https://github.com/BabitMF/bmf/releases/download/files/files.tar.gz !tar -zvxf files.tar.gz ``` -------------------------------- ### Installing BMF via Pip (Bash) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/transcode/README.md This command installs the BabitMF library using `pip3`, the Python package installer. This is the recommended and simplest way to get BMF set up for Python development. ```bash pip3 install BabitMF ``` -------------------------------- ### Example BMF Multi-Module Configuration Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/LLM_video_preprocessing/README.md An example `module_config.json` demonstrating how to configure the BMF pipeline. It specifies the module execution order, input/output paths, and module-specific options like batch size for LLM captioning. ```JSON { "mode": "aesmod_module,ocr_crop,llm_caption", "input_file": "big_bunny_10s_30fps.mp4", "output_path": "clip_output", "output_configs": [ { "res": "orig", "type": "jpg" }, { "res": "480", "type": "mp4" } ], "ocr_crop": { "pre_module": true }, "aesmod_module": { "entry": "aesmod_module.BMFAesmod", "module_path": "../aesthetic_assessment/", "pre_module": false }, "llm_caption": { "module_path": "../llm_caption/", "pre_module": false, "options": { "batch_size": 6, "multithreading": false } } } ``` -------------------------------- ### Initializing ONNX Runtime Session for BMF Aesthetic Model (Python) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/aesthetic_assessment/aesmod_bmfv3_fin.ipynb This snippet imports necessary modules, constructs the file path to the ONNX aesthetic assessment model, and initializes an ONNX Runtime inference session. This session is used for loading and executing the pre-trained aesthetic model. ```python import bmf import sys import onnxruntime as ort from module_utils import SyncModule import aesmod_module import onnxruntime as ort import os.path as osp model_dir = osp.join(osp.abspath(osp.dirname('__file__')), 'models') aesmod_ort_model_path = osp.realpath(osp.join(model_dir, 'aes_transonnx_update3.onnx')) print(aesmod_ort_model_path) ort_session = ort.InferenceSession(aesmod_ort_model_path) ``` -------------------------------- ### Installing Python Dependencies Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/LLM_video_preprocessing/README.md Installs all required Python packages listed in `requirement.txt`. This is the first step for setting up the project environment. ```Shell pip install -r requirement.txt ``` -------------------------------- ### Downloading BMF ONNX Models and Test Files (Python) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/aesthetic_assessment/aesmod_bmfv3_fin.ipynb This snippet uses `gdown` to download compressed archives containing ONNX models and test video files, then extracts them using `tar`. These files are prerequisites for running BMF aesthetic assessment demos. ```python !gdown --fuzzy https://github.com/BabitMF/bmf/releases/download/files/models.tar.gz !gdown --fuzzy https://github.com/BabitMF/bmf/releases/download/files/files.tar.gz !tar xzvf models.tar.gz !tar xzvf files.tar.gz ``` -------------------------------- ### Copying BMF Modules to Server Directory (Bash) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/wasm/README.md This Bash command creates a `lib` subdirectory within the server's root directory and copies all `.so` (shared object) files, which are the BMF modules, from the build output directory into this new `lib` folder. This makes the modules accessible to the web server for the browser demos. ```bash mkdir $SERVER_DIRECTORY/lib cp $LIB_DIRCTORY/*.so $SERVER_DIRECTORY/lib ``` -------------------------------- ### Setting BMF C/C++ Library Environment Variables (Shell) Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb These commands explicitly set critical environment variables (`C_INCLUDE_PATH`, `CPLUS_INCLUDE_PATH`, `LIBRARY_PATH`, `LD_LIBRARY_PATH`) to point to the BMF C/C++ library includes and binaries, which is essential for Go integration. ```shell %env C_INCLUDE_PATH=/usr/local/lib/python3.10/dist-packages/bmf/include %env CPLUS_INCLUDE_PATH=/usr/local/lib/python3.10/dist-packages/bmf/include %env LIBRARY_PATH=/usr/local/cuda/lib64/stubs:/usr/local/lib/python3.10/dist-packages/bmf/lib %env LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/usr/local/lib/python3.10/dist-packages/bmf/lib ``` -------------------------------- ### Installing FFmpeg and Libraries via APT (Bash) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/transcode/README.md This command installs FFmpeg and its necessary development libraries using `apt install`, ensuring that BMF has the required dependencies for transcoding operations. The `-y` flag confirms the installation automatically. ```bash apt install -y ffmpeg libavcodec-dev libavdevice-dev libavfilter-dev libavformat-dev libavresample-dev libavutil-dev libpostproc-dev libswresample-dev libswscale-dev ``` -------------------------------- ### Copying BMF Aesthetic Assessment Demo Files (Python) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/aesthetic_assessment/aesmod_bmfv3_fin.ipynb This snippet copies Python script files from the BMF aesthetic assessment demo directory to the current working directory, making them accessible for execution and testing. ```python !cp /content/bmf/bmf/demo/aesthetic_assessment/*.py . ``` -------------------------------- ### Executing Go Application in Sync Mode Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb This Python snippet executes the compiled Go application `sync_mode` with the `syncMode` argument. This command initiates the video processing in a general synchronous mode as defined within the Go program. ```Python !./sync_mode syncMode ``` -------------------------------- ### Downloading and Extracting Sample Files - Python Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_cpp.ipynb This snippet downloads a compressed archive (`files.tar.gz`) containing sample media files (e.g., `big_bunny_10s_30fps.mp4`) from the BMF GitHub releases. It then extracts these files, which are used as input for the video processing example. ```python !wget https://github.com/BabitMF/bmf/releases/download/files/files.tar.gz !tar -zvxf files.tar.gz ``` -------------------------------- ### Installing Golang for BMF Module Development Source: https://github.com/babitmf/bmf/blob/master/bmf/test/customize_module/bmf_customize_demo_latest.ipynb This command installs the Golang compiler and associated tools using `apt`. This installation is a prerequisite for developers who plan to create custom modules using the Go programming language within the BMF framework. ```Shell ! apt install golang ``` -------------------------------- ### Checking FFmpeg and Library Versions (Bash) Source: https://github.com/babitmf/bmf/blob/master/bmf/demo/transcode/README.md This snippet uses `apt show` and `grep` to display the installed versions of FFmpeg and its associated development libraries, helping to verify if the current setup meets BMF's requirements. ```bash apt show ffmpeg libavcodec-dev libavdevice-dev libavfilter-dev libavformat-dev libavresample-dev libavutil-dev libpostproc-dev libswresample-dev libswscale-dev | grep "^Package:|^Version:" ``` -------------------------------- ### Displaying Videos in IPython Notebook Source: https://github.com/babitmf/bmf/blob/master/bmf/test/sync_mode/bmf_syncmode_go.ipynb This Python snippet provides a utility function `show_video` to embed local video files directly into an IPython notebook output. It reads a video file, encodes it to a base64 data URL, and generates an HTML `