From 9a3ce86c69889682eba3fa640475b86598f6120b Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 21 May 2020 11:00:47 +0200 Subject: [PATCH] registry: allow searching for FOURCC/TWOCC by codec name --- nihav-registry/src/register.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nihav-registry/src/register.rs b/nihav-registry/src/register.rs index 6ae8528..1665b67 100644 --- a/nihav-registry/src/register.rs +++ b/nihav-registry/src/register.rs @@ -317,6 +317,14 @@ pub fn find_codec_from_avi_fourcc(fcc: &[u8;4]) -> Option<&'static str> { None } +/// Returns FOURCC (used in AVI format) for provided codec name. +pub fn find_avi_fourcc(codecname: &str) -> Option<[u8; 4]> { + for (fourcc, name) in AVI_VIDEO_CODEC_REGISTER.iter() { + if *name == codecname { return Some(**fourcc); } + } + None +} + /// Returns known audio codec short name for provided TWOCC (used in WAV and AVI format). pub fn find_codec_from_wav_twocc(tcc: u16) -> Option<&'static str> { for (twocc, name) in WAV_CODEC_REGISTER.iter() { @@ -325,6 +333,14 @@ pub fn find_codec_from_wav_twocc(tcc: u16) -> Option<&'static str> { None } +/// Returns TWOCC (used in WAV and AVI format for provided codec name. +pub fn find_wav_twocc(codecname: &str) -> Option { + for (twocc, name) in WAV_CODEC_REGISTER.iter() { + if *name == codecname { return Some(*twocc); } + } + None +} + /// Returns video codec short name for provided FOURCC (used in MOV format). pub fn find_codec_from_mov_video_fourcc(fcc: &[u8;4]) -> Option<&'static str> { for (fourcc, name) in MOV_VIDEO_CODEC_REGISTER.iter() { -- 2.39.5