Skip to content

Wasm compatible code invoking the underlying FFMPEG API

Notifications You must be signed in to change notification settings

Hrushi20/ffmpeg-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository is the solution to Pretest #2703.

The solution is split into two repositories-

  1. WasmEdge-FFMPEG
    Contains Ffmpeg Plugin that acts as a bridge between WasmEdge and Ffmpeg C API.

  2. ffmpeg-rust
    Uses the WasmEdgeFfmpeg plugin built in WasmEdge-FFMPEG and executes Ffmpeg C API functions.

Project

The wasm function reads the assets/small_bunny_1080p_60fps.mp4 video file and uses the FFmpeg C API to convert the video into grayscale image frames. The frames are generated in assets dir.

Architecture

Video Info Value
Video Duration 2 sec
Frames Per Second 60
No. of frames generated 2 * 60 = 120
Container Format mp4
Pixel Format YUV420p

Note-

First, follow the steps in WasmEdge-FFMPEG repository to build the plugin shared library.

To use the FFMPEG Plugin, follow the below steps-

1. Dependecies-

Witc is a compiler which generates rust code for *.wit files.

2. Generate C API in Rust using Witc

witc plugin wasmedge_ffmpeg.wit > src/generated.rs

generated.rs file is created in src directory.

3. Build Project-

Use cargo to build the project into .wasm

cargo build --target wasm32-wasi --release

4. Execute .wsm file using WasmEdge-

WASMEDGE_PLUGIN_PATH=/usr/local/lib/wasmedge/ wasmedge --dir ./. target/wasm32-wasi/release/ffmpegRust.wasm

WASMEDGE_PLUGIN_PATH takes the path of the shared plugin created in WasmEdge-FFMPEG.

Result-

Result Frame0 Frame68 Frame119

The video is split into grayscale images using Ffmpeg C API in assets dir. The image generated is pgm format. Use appropriate image viewer to see the image.

Generated Rust File- Witc

The above image shows the generated.rs file.

About

Wasm compatible code invoking the underlying FFMPEG API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages