#level #codec #helper #frame-rate

video-levels

Helper for working with levels in video codecs

3 releases (1 stable)

1.0.0 Apr 25, 2024
0.1.1 Feb 29, 2024
0.1.0 Feb 29, 2024

#35 in Video

Download history 5567/week @ 2024-06-14 4474/week @ 2024-06-21 7895/week @ 2024-06-28 5165/week @ 2024-07-05 1762/week @ 2024-07-12 3553/week @ 2024-07-19 2856/week @ 2024-07-26 2517/week @ 2024-08-02 8127/week @ 2024-08-09 5132/week @ 2024-08-16 13249/week @ 2024-08-23 6850/week @ 2024-08-30 12045/week @ 2024-09-06 2877/week @ 2024-09-13 11378/week @ 2024-09-20 17082/week @ 2024-09-27

44,639 downloads per month

MIT license

43KB
1K SLoC

Codec video level tool in Rust

If you've had to configure encoders of various kinds, you've probably stumbled upon level tables. These are fun until you realize you have to copy this stuff into your code manually or "JUST SET LEVEL 5.2 BRO" which... sadly is more true than you think. Since I didn't want to to that I ended up writing this small helper tool that just has all this in code with sane checking so you can find the right level at runtime.

use video_levels::hevc::{LevelSelector, Profile, Tier};

let level = LevelSelector::new()
    .width(1920)
    .height(1080)
    .framerate(60.0)
    .tier(Tier::Main)
    .profile(Profile::Main)
    .select();

println!("Level: {:?}", level.unwrap().id());

But hey, your fancy MediaTek garbage dump android phone hardware decodeder doesn't support every level in the world? The TL;DR of what you want to do is clamp up to the level required by your configuration (width,height,fps etc) and then clamp up to a level that allows you headroom for your application. This is as easy as:

use video_levels::hevc::{LevelSelector, Profile, Tier};

let level = LevelSelector::new()
    .width(3840)
    .height(2160)
    .framerate(60.0)
    .tier(Tier::Main)
    .profile(Profile::Main)
    // Clamping between L4 and L5.2
    .clamp(Level::L4, Level::L5_2)
    .select();

println!("Level: {:?}", level.unwrap().id());

AV1 is equally easy

use video_levels::AV1::{LevelSelector};

let level = LevelSelector::new()
    .width(3840)
    .height(2160)
    .framerate(60.0)
    .select();

println!("Level: {:?}", level.unwrap().id());

Why?

after going insane reading wikipedia and the ITU specs I was like... yeah ok i don't want to do this again

Progress

  • HEVC
  • AV1
  • H264 (Dreading this one lol)
  • Make selector a trait

Contributing

m8 just open a PR with some gucchimucchi code and I'll review it.

KADSBUGGEL

License

MIT -> go wild

Acknowledgements

ridley combs for help

Dependencies

~315KB