Skip to main content

ffmpeg_next/codec/
traits.rs

1use super::{decoder, encoder};
2use crate::Codec;
3use crate::codec::{Audio, Id, Video};
4
5pub trait Decoder {
6    fn decoder(self) -> Option<Codec>;
7}
8
9impl Decoder for &str {
10    fn decoder(self) -> Option<Codec> {
11        decoder::find_by_name(self)
12    }
13}
14
15impl Decoder for Id {
16    fn decoder(self) -> Option<Codec> {
17        decoder::find(self)
18    }
19}
20
21impl Decoder for Codec {
22    fn decoder(self) -> Option<Codec> {
23        if self.is_decoder() { Some(self) } else { None }
24    }
25}
26
27impl Decoder for Option<Codec> {
28    fn decoder(self) -> Option<Codec> {
29        self.and_then(|c| c.decoder())
30    }
31}
32
33impl Decoder for Audio {
34    fn decoder(self) -> Option<Codec> {
35        if self.is_decoder() { Some(*self) } else { None }
36    }
37}
38
39impl Decoder for Video {
40    fn decoder(self) -> Option<Codec> {
41        if self.is_decoder() { Some(*self) } else { None }
42    }
43}
44
45pub trait Encoder {
46    fn encoder(self) -> Option<Codec>;
47}
48
49impl Encoder for &str {
50    fn encoder(self) -> Option<Codec> {
51        encoder::find_by_name(self)
52    }
53}
54
55impl Encoder for Id {
56    fn encoder(self) -> Option<Codec> {
57        encoder::find(self)
58    }
59}
60
61impl Encoder for Codec {
62    fn encoder(self) -> Option<Codec> {
63        if self.is_encoder() { Some(self) } else { None }
64    }
65}
66
67impl Encoder for Option<Codec> {
68    fn encoder(self) -> Option<Codec> {
69        self.and_then(|c| c.encoder())
70    }
71}
72
73impl Encoder for Audio {
74    fn encoder(self) -> Option<Codec> {
75        if self.is_encoder() { Some(*self) } else { None }
76    }
77}
78
79impl Encoder for Video {
80    fn encoder(self) -> Option<Codec> {
81        if self.is_encoder() { Some(*self) } else { None }
82    }
83}