mirror of
https://github.com/encounter/rust-ffmpeg.git
synced 2026-07-10 21:18:39 -07:00
*: format code with rustfmt and fix clippy suggestions
* Add avformat_close_input call to clean up AVFormantContext * Format code with rustfmt * Fix clippy lint double_parens * Fix clippy lint deref_addrof * Fix clippy lint identity_conversion * Fix clippy lint match_ref_pats * Fix clippy lint cast_lossless * Fix clippy lint cmp_null * Fix clippy lint clone_on_ref_ptr * Fix clippy lint map_clone * Fix clippy lint needless_borrow * Fix clippy lint needless_pass_by_value * Fix clippy lints for examples * Fix clippy lint unused_io_amount * Fix clippy lint new_without_default * Ignore inline_always clippy lint * Add vim temp files to .gitignore
This commit is contained in:
@@ -1,2 +1,8 @@
|
||||
# Rust files
|
||||
target
|
||||
Cargo.lock
|
||||
|
||||
# Vim temporary files
|
||||
*.swp
|
||||
*.swo
|
||||
*.swn
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
for (name, _value) in env::vars() {
|
||||
if name.starts_with("DEP_FFMPEG_") {
|
||||
println!(r#"cargo:rustc-cfg=feature="{}""#,
|
||||
name["DEP_FFMPEG_".len() .. name.len()].to_lowercase());
|
||||
}
|
||||
}
|
||||
for (name, _value) in env::vars() {
|
||||
if name.starts_with("DEP_FFMPEG_") {
|
||||
println!(
|
||||
r#"cargo:rustc-cfg=feature="{}""#,
|
||||
name["DEP_FFMPEG_".len()..name.len()].to_lowercase()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+46
-38
@@ -3,50 +3,58 @@ extern crate ffmpeg;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
ffmpeg::init().unwrap();
|
||||
ffmpeg::init().unwrap();
|
||||
|
||||
match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) {
|
||||
Ok(ictx) => {
|
||||
println!("Nb chapters: {}", ictx.nb_chapters());
|
||||
match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) {
|
||||
Ok(ictx) => {
|
||||
println!("Nb chapters: {}", ictx.nb_chapters());
|
||||
|
||||
for chapter in ictx.chapters() {
|
||||
println!("chapter id {}:", chapter.id());
|
||||
println!("\ttime_base: {}", chapter.time_base());
|
||||
println!("\tstart: {}", chapter.start());
|
||||
println!("\tend: {}", chapter.end());
|
||||
for chapter in ictx.chapters() {
|
||||
println!("chapter id {}:", chapter.id());
|
||||
println!("\ttime_base: {}", chapter.time_base());
|
||||
println!("\tstart: {}", chapter.start());
|
||||
println!("\tend: {}", chapter.end());
|
||||
|
||||
for (k, v) in chapter.metadata().iter() {
|
||||
println!("\t{}: {}", k, v);
|
||||
}
|
||||
}
|
||||
for (k, v) in chapter.metadata().iter() {
|
||||
println!("\t{}: {}", k, v);
|
||||
}
|
||||
}
|
||||
|
||||
let mut octx = ffmpeg::format::output(&"test.mkv".to_owned()).expect(&format!("Couldn't open test file"));
|
||||
let mut octx =
|
||||
ffmpeg::format::output(&"test.mkv".to_owned()).expect("Couldn't open test file");
|
||||
|
||||
for chapter in ictx.chapters() {
|
||||
let title = match chapter.metadata().get("title") {
|
||||
Some(title) => String::from(title),
|
||||
None => String::new(),
|
||||
};
|
||||
for chapter in ictx.chapters() {
|
||||
let title = match chapter.metadata().get("title") {
|
||||
Some(title) => String::from(title),
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
match octx.add_chapter(chapter.id(), chapter.time_base(), chapter.start(), chapter.end(), &title) {
|
||||
Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()),
|
||||
Err(error) => println!("Error adding chapter with id: {} - {}", chapter.id(), error),
|
||||
}
|
||||
}
|
||||
match octx.add_chapter(
|
||||
chapter.id(),
|
||||
chapter.time_base(),
|
||||
chapter.start(),
|
||||
chapter.end(),
|
||||
&title,
|
||||
) {
|
||||
Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()),
|
||||
Err(error) => {
|
||||
println!("Error adding chapter with id: {} - {}", chapter.id(), error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("\nOuput: nb chapters: {}", octx.nb_chapters());
|
||||
for chapter in octx.chapters() {
|
||||
println!("chapter id {}:", chapter.id());
|
||||
println!("\ttime_base: {}", chapter.time_base());
|
||||
println!("\tstart: {}", chapter.start());
|
||||
println!("\tend: {}", chapter.end());
|
||||
for (k, v) in chapter.metadata().iter() {
|
||||
println!("\t{}: {}", k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("\nOuput: nb chapters: {}", octx.nb_chapters());
|
||||
for chapter in octx.chapters() {
|
||||
println!("chapter id {}:", chapter.id());
|
||||
println!("\ttime_base: {}", chapter.time_base());
|
||||
println!("\tstart: {}", chapter.start());
|
||||
println!("\tend: {}", chapter.end());
|
||||
for (k, v) in chapter.metadata().iter() {
|
||||
println!("\t{}: {}", k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(error) =>
|
||||
println!("error: {}", error)
|
||||
}
|
||||
Err(error) => println!("error: {}", error),
|
||||
}
|
||||
}
|
||||
|
||||
+88
-99
@@ -3,119 +3,108 @@ extern crate ffmpeg;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
ffmpeg::init().unwrap();
|
||||
ffmpeg::init().unwrap();
|
||||
|
||||
for arg in env::args().skip(1) {
|
||||
if let Some(codec) = ffmpeg::decoder::find_by_name(&arg) {
|
||||
println!("type: decoder");
|
||||
println!("\t id: {:?}", codec.id());
|
||||
println!("\t name: {}", codec.name());
|
||||
println!("\t description: {}", codec.description());
|
||||
println!("\t medium: {:?}", codec.medium());
|
||||
println!("\t capabilities: {:?}", codec.capabilities());
|
||||
for arg in env::args().skip(1) {
|
||||
if let Some(codec) = ffmpeg::decoder::find_by_name(&arg) {
|
||||
println!("type: decoder");
|
||||
println!("\t id: {:?}", codec.id());
|
||||
println!("\t name: {}", codec.name());
|
||||
println!("\t description: {}", codec.description());
|
||||
println!("\t medium: {:?}", codec.medium());
|
||||
println!("\t capabilities: {:?}", codec.capabilities());
|
||||
|
||||
if let Some(profiles) = codec.profiles() {
|
||||
println!("\t profiles: {:?}", profiles.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t profiles: none");
|
||||
}
|
||||
if let Some(profiles) = codec.profiles() {
|
||||
println!("\t profiles: {:?}", profiles.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t profiles: none");
|
||||
}
|
||||
|
||||
if let Ok(video) = codec.video() {
|
||||
if let Some(rates) = video.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
if let Ok(video) = codec.video() {
|
||||
if let Some(rates) = video.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
|
||||
if let Some(formats) = video.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
}
|
||||
if let Some(formats) = video.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(audio) = codec.audio() {
|
||||
if let Some(rates) = audio.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
if let Ok(audio) = codec.audio() {
|
||||
if let Some(rates) = audio.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
|
||||
if let Some(formats) = audio.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
if let Some(formats) = audio.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
|
||||
if let Some(layouts) = audio.channel_layouts() {
|
||||
println!("\t channel_layouts: {:?}", layouts.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t channel_layouts: any");
|
||||
}
|
||||
}
|
||||
if let Some(layouts) = audio.channel_layouts() {
|
||||
println!("\t channel_layouts: {:?}", layouts.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t channel_layouts: any");
|
||||
}
|
||||
}
|
||||
|
||||
println!("\t max_lowres: {:?}", codec.max_lowres());
|
||||
}
|
||||
println!("\t max_lowres: {:?}", codec.max_lowres());
|
||||
}
|
||||
|
||||
if let Some(codec) = ffmpeg::encoder::find_by_name(&arg) {
|
||||
println!("");
|
||||
println!("type: encoder");
|
||||
println!("\t id: {:?}", codec.id());
|
||||
println!("\t name: {}", codec.name());
|
||||
println!("\t description: {}", codec.description());
|
||||
println!("\t medium: {:?}", codec.medium());
|
||||
println!("\t capabilities: {:?}", codec.capabilities());
|
||||
if let Some(codec) = ffmpeg::encoder::find_by_name(&arg) {
|
||||
println!();
|
||||
println!("type: encoder");
|
||||
println!("\t id: {:?}", codec.id());
|
||||
println!("\t name: {}", codec.name());
|
||||
println!("\t description: {}", codec.description());
|
||||
println!("\t medium: {:?}", codec.medium());
|
||||
println!("\t capabilities: {:?}", codec.capabilities());
|
||||
|
||||
if let Some(profiles) = codec.profiles() {
|
||||
println!("\t profiles: {:?}", profiles.collect::<Vec<_>>());
|
||||
}
|
||||
if let Some(profiles) = codec.profiles() {
|
||||
println!("\t profiles: {:?}", profiles.collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
if let Ok(video) = codec.video() {
|
||||
if let Some(rates) = video.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
if let Ok(video) = codec.video() {
|
||||
if let Some(rates) = video.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
|
||||
if let Some(formats) = video.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
}
|
||||
if let Some(formats) = video.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(audio) = codec.audio() {
|
||||
if let Some(rates) = audio.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
if let Ok(audio) = codec.audio() {
|
||||
if let Some(rates) = audio.rates() {
|
||||
println!("\t rates: {:?}", rates.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t rates: any");
|
||||
}
|
||||
|
||||
if let Some(formats) = audio.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
if let Some(formats) = audio.formats() {
|
||||
println!("\t formats: {:?}", formats.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t formats: any");
|
||||
}
|
||||
|
||||
if let Some(layouts) = audio.channel_layouts() {
|
||||
println!("\t channel_layouts: {:?}", layouts.collect::<Vec<_>>());
|
||||
}
|
||||
else {
|
||||
println!("\t channel_layouts: any");
|
||||
}
|
||||
}
|
||||
if let Some(layouts) = audio.channel_layouts() {
|
||||
println!("\t channel_layouts: {:?}", layouts.collect::<Vec<_>>());
|
||||
} else {
|
||||
println!("\t channel_layouts: any");
|
||||
}
|
||||
}
|
||||
|
||||
println!("\t max_lowres: {:?}", codec.max_lowres());
|
||||
}
|
||||
}
|
||||
println!("\t max_lowres: {:?}", codec.max_lowres());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+78
-72
@@ -3,81 +3,87 @@ extern crate ffmpeg;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
ffmpeg::init().unwrap();
|
||||
ffmpeg::init().unwrap();
|
||||
|
||||
match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
|
||||
Ok(context) => {
|
||||
for (k, v) in context.metadata().iter() {
|
||||
println!("{}: {}", k, v);
|
||||
}
|
||||
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
|
||||
println!("Best video stream index: {}", stream.index());
|
||||
}
|
||||
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
|
||||
println!("Best audio stream index: {}", stream.index());
|
||||
}
|
||||
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
|
||||
println!("Best subtitle stream index: {}", stream.index());
|
||||
}
|
||||
match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
|
||||
Ok(context) => {
|
||||
for (k, v) in context.metadata().iter() {
|
||||
println!("{}: {}", k, v);
|
||||
}
|
||||
|
||||
println!("duration (seconds): {:.2}", context.duration() as f64 / ffmpeg::ffi::AV_TIME_BASE as f64);
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
|
||||
println!("Best video stream index: {}", stream.index());
|
||||
}
|
||||
|
||||
for stream in context.streams() {
|
||||
println!("stream index {}:", stream.index());
|
||||
println!("\ttime_base: {}", stream.time_base());
|
||||
println!("\tstart_time: {}", stream.start_time());
|
||||
println!("\tduration (stream timebase): {}", stream.duration());
|
||||
println!("\tduration (seconds): {:.2}", stream.duration() as f64 * f64::from(stream.time_base()));
|
||||
println!("\tframes: {}", stream.frames());
|
||||
println!("\tdisposition: {:?}", stream.disposition());
|
||||
println!("\tdiscard: {:?}", stream.discard());
|
||||
println!("\trate: {}", stream.rate());
|
||||
|
||||
let codec = stream.codec();
|
||||
println!("\tmedium: {:?}", codec.medium());
|
||||
println!("\tid: {:?}", codec.id());
|
||||
|
||||
if codec.medium() == ffmpeg::media::Type::Video {
|
||||
if let Ok(video) = codec.decoder().video() {
|
||||
println!("\tbit_rate: {}", video.bit_rate());
|
||||
println!("\tmax_rate: {}", video.max_bit_rate());
|
||||
println!("\tdelay: {}", video.delay());
|
||||
println!("\tvideo.width: {}", video.width());
|
||||
println!("\tvideo.height: {}", video.height());
|
||||
println!("\tvideo.format: {:?}", video.format());
|
||||
println!("\tvideo.has_b_frames: {}", video.has_b_frames());
|
||||
println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
|
||||
println!("\tvideo.color_space: {:?}", video.color_space());
|
||||
println!("\tvideo.color_range: {:?}", video.color_range());
|
||||
println!("\tvideo.color_primaries: {:?}", video.color_primaries());
|
||||
println!("\tvideo.color_transfer_characteristic: {:?}", video.color_transfer_characteristic());
|
||||
println!("\tvideo.chroma_location: {:?}", video.chroma_location());
|
||||
println!("\tvideo.references: {}", video.references());
|
||||
println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
|
||||
}
|
||||
}
|
||||
else if codec.medium() == ffmpeg::media::Type::Audio {
|
||||
if let Ok(audio) = codec.decoder().audio() {
|
||||
println!("\tbit_rate: {}", audio.bit_rate());
|
||||
println!("\tmax_rate: {}", audio.max_bit_rate());
|
||||
println!("\tdelay: {}", audio.delay());
|
||||
println!("\taudio.rate: {}", audio.rate());
|
||||
println!("\taudio.channels: {}", audio.channels());
|
||||
println!("\taudio.format: {:?}", audio.format());
|
||||
println!("\taudio.frames: {}", audio.frames());
|
||||
println!("\taudio.align: {}", audio.align());
|
||||
println!("\taudio.channel_layout: {:?}", audio.channel_layout());
|
||||
println!("\taudio.frame_start: {:?}", audio.frame_start());
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
|
||||
println!("Best audio stream index: {}", stream.index());
|
||||
}
|
||||
|
||||
}
|
||||
if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
|
||||
println!("Best subtitle stream index: {}", stream.index());
|
||||
}
|
||||
|
||||
Err(error) =>
|
||||
println!("error: {}", error)
|
||||
}
|
||||
println!(
|
||||
"duration (seconds): {:.2}",
|
||||
context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
|
||||
);
|
||||
|
||||
for stream in context.streams() {
|
||||
println!("stream index {}:", stream.index());
|
||||
println!("\ttime_base: {}", stream.time_base());
|
||||
println!("\tstart_time: {}", stream.start_time());
|
||||
println!("\tduration (stream timebase): {}", stream.duration());
|
||||
println!(
|
||||
"\tduration (seconds): {:.2}",
|
||||
stream.duration() as f64 * f64::from(stream.time_base())
|
||||
);
|
||||
println!("\tframes: {}", stream.frames());
|
||||
println!("\tdisposition: {:?}", stream.disposition());
|
||||
println!("\tdiscard: {:?}", stream.discard());
|
||||
println!("\trate: {}", stream.rate());
|
||||
|
||||
let codec = stream.codec();
|
||||
println!("\tmedium: {:?}", codec.medium());
|
||||
println!("\tid: {:?}", codec.id());
|
||||
|
||||
if codec.medium() == ffmpeg::media::Type::Video {
|
||||
if let Ok(video) = codec.decoder().video() {
|
||||
println!("\tbit_rate: {}", video.bit_rate());
|
||||
println!("\tmax_rate: {}", video.max_bit_rate());
|
||||
println!("\tdelay: {}", video.delay());
|
||||
println!("\tvideo.width: {}", video.width());
|
||||
println!("\tvideo.height: {}", video.height());
|
||||
println!("\tvideo.format: {:?}", video.format());
|
||||
println!("\tvideo.has_b_frames: {}", video.has_b_frames());
|
||||
println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
|
||||
println!("\tvideo.color_space: {:?}", video.color_space());
|
||||
println!("\tvideo.color_range: {:?}", video.color_range());
|
||||
println!("\tvideo.color_primaries: {:?}", video.color_primaries());
|
||||
println!(
|
||||
"\tvideo.color_transfer_characteristic: {:?}",
|
||||
video.color_transfer_characteristic()
|
||||
);
|
||||
println!("\tvideo.chroma_location: {:?}", video.chroma_location());
|
||||
println!("\tvideo.references: {}", video.references());
|
||||
println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
|
||||
}
|
||||
} else if codec.medium() == ffmpeg::media::Type::Audio {
|
||||
if let Ok(audio) = codec.decoder().audio() {
|
||||
println!("\tbit_rate: {}", audio.bit_rate());
|
||||
println!("\tmax_rate: {}", audio.max_bit_rate());
|
||||
println!("\tdelay: {}", audio.delay());
|
||||
println!("\taudio.rate: {}", audio.rate());
|
||||
println!("\taudio.channels: {}", audio.channels());
|
||||
println!("\taudio.format: {:?}", audio.format());
|
||||
println!("\taudio.frames: {}", audio.frames());
|
||||
println!("\taudio.align: {}", audio.align());
|
||||
println!("\taudio.channel_layout: {:?}", audio.channel_layout());
|
||||
println!("\taudio.frame_start: {:?}", audio.frame_start());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(error) => println!("error: {}", error),
|
||||
}
|
||||
}
|
||||
|
||||
+167
-109
@@ -3,87 +3,121 @@ extern crate ffmpeg;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
use ffmpeg::{format, codec, frame, media, filter};
|
||||
use ffmpeg::{codec, filter, format, frame, media};
|
||||
use ffmpeg::{rescale, Rescale};
|
||||
|
||||
fn filter(spec: &str, decoder: &codec::decoder::Audio, encoder: &codec::encoder::Audio) -> Result<filter::Graph, ffmpeg::Error> {
|
||||
let mut filter = filter::Graph::new();
|
||||
fn filter(
|
||||
spec: &str,
|
||||
decoder: &codec::decoder::Audio,
|
||||
encoder: &codec::encoder::Audio,
|
||||
) -> Result<filter::Graph, ffmpeg::Error> {
|
||||
let mut filter = filter::Graph::new();
|
||||
|
||||
let args = format!("time_base={}:sample_rate={}:sample_fmt={}:channel_layout=0x{:x}",
|
||||
decoder.time_base(), decoder.rate(), decoder.format().name(), decoder.channel_layout().bits());
|
||||
let args = format!(
|
||||
"time_base={}:sample_rate={}:sample_fmt={}:channel_layout=0x{:x}",
|
||||
decoder.time_base(),
|
||||
decoder.rate(),
|
||||
decoder.format().name(),
|
||||
decoder.channel_layout().bits()
|
||||
);
|
||||
|
||||
try!(filter.add(&filter::find("abuffer").unwrap(), "in", &args));
|
||||
try!(filter.add(&filter::find("abuffersink").unwrap(), "out", ""));
|
||||
filter.add(&filter::find("abuffer").unwrap(), "in", &args)?;
|
||||
filter.add(&filter::find("abuffersink").unwrap(), "out", "")?;
|
||||
|
||||
{
|
||||
let mut out = filter.get("out").unwrap();
|
||||
{
|
||||
let mut out = filter.get("out").unwrap();
|
||||
|
||||
out.set_sample_format(encoder.format());
|
||||
out.set_channel_layout(encoder.channel_layout());
|
||||
out.set_sample_rate(encoder.rate());
|
||||
}
|
||||
out.set_sample_format(encoder.format());
|
||||
out.set_channel_layout(encoder.channel_layout());
|
||||
out.set_sample_rate(encoder.rate());
|
||||
}
|
||||
|
||||
try!(try!(try!(filter.output("in", 0)).input("out", 0)).parse(spec));
|
||||
try!(filter.validate());
|
||||
filter.output("in", 0)?.input("out", 0)?.parse(spec)?;
|
||||
filter.validate()?;
|
||||
|
||||
println!("{}", filter.dump());
|
||||
println!("{}", filter.dump());
|
||||
|
||||
if let Some(codec) = encoder.codec() {
|
||||
if !codec.capabilities().contains(ffmpeg::codec::capabilities::VARIABLE_FRAME_SIZE) {
|
||||
filter.get("out").unwrap().sink().set_frame_size(encoder.frame_size());
|
||||
}
|
||||
}
|
||||
if let Some(codec) = encoder.codec() {
|
||||
if !codec
|
||||
.capabilities()
|
||||
.contains(ffmpeg::codec::capabilities::VARIABLE_FRAME_SIZE)
|
||||
{
|
||||
filter
|
||||
.get("out")
|
||||
.unwrap()
|
||||
.sink()
|
||||
.set_frame_size(encoder.frame_size());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(filter)
|
||||
Ok(filter)
|
||||
}
|
||||
|
||||
struct Transcoder {
|
||||
stream: usize,
|
||||
filter: filter::Graph,
|
||||
decoder: codec::decoder::Audio,
|
||||
encoder: codec::encoder::Audio,
|
||||
stream: usize,
|
||||
filter: filter::Graph,
|
||||
decoder: codec::decoder::Audio,
|
||||
encoder: codec::encoder::Audio,
|
||||
}
|
||||
|
||||
fn transcoder<P: AsRef<Path>>(ictx: &mut format::context::Input, octx: &mut format::context::Output, path: &P, filter_spec: &str) -> Result<Transcoder, ffmpeg::Error> {
|
||||
let input = ictx.streams().best(media::Type::Audio).expect("could not find best audio stream");
|
||||
let mut decoder = try!(input.codec().decoder().audio());
|
||||
let codec = try!(ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio)).expect("failed to find encoder").audio());
|
||||
let global = octx.format().flags().contains(ffmpeg::format::flag::GLOBAL_HEADER);
|
||||
fn transcoder<P: AsRef<Path>>(
|
||||
ictx: &mut format::context::Input,
|
||||
octx: &mut format::context::Output,
|
||||
path: &P,
|
||||
filter_spec: &str,
|
||||
) -> Result<Transcoder, ffmpeg::Error> {
|
||||
let input = ictx.streams()
|
||||
.best(media::Type::Audio)
|
||||
.expect("could not find best audio stream");
|
||||
let mut decoder = input.codec().decoder().audio()?;
|
||||
let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
|
||||
.expect("failed to find encoder")
|
||||
.audio()?;
|
||||
let global = octx.format()
|
||||
.flags()
|
||||
.contains(ffmpeg::format::flag::GLOBAL_HEADER);
|
||||
|
||||
try!(decoder.set_parameters(input.parameters()));
|
||||
decoder.set_parameters(input.parameters())?;
|
||||
|
||||
let mut output = try!(octx.add_stream(codec));
|
||||
let mut encoder = try!(output.codec().encoder().audio());
|
||||
let mut output = octx.add_stream(codec)?;
|
||||
let mut encoder = output.codec().encoder().audio()?;
|
||||
|
||||
let channel_layout = codec.channel_layouts()
|
||||
.map(|cls| cls.best(decoder.channel_layout().channels()))
|
||||
.unwrap_or(ffmpeg::channel_layout::STEREO);
|
||||
let channel_layout = codec
|
||||
.channel_layouts()
|
||||
.map(|cls| cls.best(decoder.channel_layout().channels()))
|
||||
.unwrap_or(ffmpeg::channel_layout::STEREO);
|
||||
|
||||
if global {
|
||||
encoder.set_flags(ffmpeg::codec::flag::GLOBAL_HEADER);
|
||||
}
|
||||
if global {
|
||||
encoder.set_flags(ffmpeg::codec::flag::GLOBAL_HEADER);
|
||||
}
|
||||
|
||||
encoder.set_rate(decoder.rate() as i32);
|
||||
encoder.set_channel_layout(channel_layout);
|
||||
encoder.set_channels(channel_layout.channels());
|
||||
encoder.set_format(codec.formats().expect("unknown supported formats").next().unwrap());
|
||||
encoder.set_bit_rate(decoder.bit_rate());
|
||||
encoder.set_max_bit_rate(decoder.max_bit_rate());
|
||||
encoder.set_rate(decoder.rate() as i32);
|
||||
encoder.set_channel_layout(channel_layout);
|
||||
encoder.set_channels(channel_layout.channels());
|
||||
encoder.set_format(
|
||||
codec
|
||||
.formats()
|
||||
.expect("unknown supported formats")
|
||||
.next()
|
||||
.unwrap(),
|
||||
);
|
||||
encoder.set_bit_rate(decoder.bit_rate());
|
||||
encoder.set_max_bit_rate(decoder.max_bit_rate());
|
||||
|
||||
encoder.set_time_base((1, decoder.rate() as i32));
|
||||
output.set_time_base((1, decoder.rate() as i32));
|
||||
encoder.set_time_base((1, decoder.rate() as i32));
|
||||
output.set_time_base((1, decoder.rate() as i32));
|
||||
|
||||
let encoder = try!(encoder.open_as(codec));
|
||||
output.set_parameters(&encoder);
|
||||
let encoder = encoder.open_as(codec)?;
|
||||
output.set_parameters(&encoder);
|
||||
|
||||
let filter = try!(filter(filter_spec, &decoder, &encoder));
|
||||
let filter = filter(filter_spec, &decoder, &encoder)?;
|
||||
|
||||
Ok(Transcoder {
|
||||
stream: input.index(),
|
||||
filter: filter,
|
||||
decoder: decoder,
|
||||
encoder: encoder,
|
||||
})
|
||||
Ok(Transcoder {
|
||||
stream: input.index(),
|
||||
filter: filter,
|
||||
decoder: decoder,
|
||||
encoder: encoder,
|
||||
})
|
||||
}
|
||||
|
||||
// Transcode the `best` audio stream of the input file into a the output file while applying a
|
||||
@@ -98,70 +132,94 @@ fn transcoder<P: AsRef<Path>>(ictx: &mut format::context::Input, octx: &mut form
|
||||
// Example 3: Seek to a specified position (in seconds)
|
||||
// transcode-audio in.mp3 out.mp3 anull 30
|
||||
fn main() {
|
||||
ffmpeg::init().unwrap();
|
||||
ffmpeg::init().unwrap();
|
||||
|
||||
let input = env::args().nth(1).expect("missing input");
|
||||
let output = env::args().nth(2).expect("missing output");
|
||||
let filter = env::args().nth(3).unwrap_or("anull".to_owned());
|
||||
let seek = env::args().nth(4).and_then(|s| s.parse::<i64>().ok());
|
||||
let input = env::args().nth(1).expect("missing input");
|
||||
let output = env::args().nth(2).expect("missing output");
|
||||
let filter = env::args().nth(3).unwrap_or_else(|| "anull".to_owned());
|
||||
let seek = env::args().nth(4).and_then(|s| s.parse::<i64>().ok());
|
||||
|
||||
let mut ictx = format::input(&input).unwrap();
|
||||
let mut octx = format::output(&output).unwrap();
|
||||
let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap();
|
||||
let mut ictx = format::input(&input).unwrap();
|
||||
let mut octx = format::output(&output).unwrap();
|
||||
let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap();
|
||||
|
||||
if let Some(position) = seek {
|
||||
// If the position was given in seconds, rescale it to ffmpegs base timebase.
|
||||
let position = position.rescale((1, 1), rescale::TIME_BASE);
|
||||
// If this seek was embedded in the transcoding loop, a call of `flush()`
|
||||
// for every opened buffer after the successful seek would be advisable.
|
||||
ictx.seek(position, ..position).unwrap();
|
||||
}
|
||||
if let Some(position) = seek {
|
||||
// If the position was given in seconds, rescale it to ffmpegs base timebase.
|
||||
let position = position.rescale((1, 1), rescale::TIME_BASE);
|
||||
// If this seek was embedded in the transcoding loop, a call of `flush()`
|
||||
// for every opened buffer after the successful seek would be advisable.
|
||||
ictx.seek(position, ..position).unwrap();
|
||||
}
|
||||
|
||||
octx.set_metadata(ictx.metadata().to_owned());
|
||||
octx.write_header().unwrap();
|
||||
octx.set_metadata(ictx.metadata().to_owned());
|
||||
octx.write_header().unwrap();
|
||||
|
||||
let in_time_base = transcoder.decoder.time_base();
|
||||
let out_time_base = octx.stream(0).unwrap().time_base();
|
||||
let in_time_base = transcoder.decoder.time_base();
|
||||
let out_time_base = octx.stream(0).unwrap().time_base();
|
||||
|
||||
let mut decoded = frame::Audio::empty();
|
||||
let mut encoded = ffmpeg::Packet::empty();
|
||||
let mut decoded = frame::Audio::empty();
|
||||
let mut encoded = ffmpeg::Packet::empty();
|
||||
|
||||
for (stream, mut packet) in ictx.packets() {
|
||||
if stream.index() == transcoder.stream {
|
||||
packet.rescale_ts(stream.time_base(), in_time_base);
|
||||
for (stream, mut packet) in ictx.packets() {
|
||||
if stream.index() == transcoder.stream {
|
||||
packet.rescale_ts(stream.time_base(), in_time_base);
|
||||
|
||||
if let Ok(true) = transcoder.decoder.decode(&packet, &mut decoded) {
|
||||
let timestamp = decoded.timestamp();
|
||||
decoded.set_pts(timestamp);
|
||||
if let Ok(true) = transcoder.decoder.decode(&packet, &mut decoded) {
|
||||
let timestamp = decoded.timestamp();
|
||||
decoded.set_pts(timestamp);
|
||||
|
||||
transcoder.filter.get("in").unwrap().source().add(&decoded).unwrap();
|
||||
transcoder
|
||||
.filter
|
||||
.get("in")
|
||||
.unwrap()
|
||||
.source()
|
||||
.add(&decoded)
|
||||
.unwrap();
|
||||
|
||||
while let Ok(..) = transcoder.filter.get("out").unwrap().sink().frame(&mut decoded) {
|
||||
if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
|
||||
encoded.set_stream(0);
|
||||
encoded.rescale_ts(in_time_base, out_time_base);
|
||||
encoded.write_interleaved(&mut octx).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while let Ok(..) = transcoder
|
||||
.filter
|
||||
.get("out")
|
||||
.unwrap()
|
||||
.sink()
|
||||
.frame(&mut decoded)
|
||||
{
|
||||
if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
|
||||
encoded.set_stream(0);
|
||||
encoded.rescale_ts(in_time_base, out_time_base);
|
||||
encoded.write_interleaved(&mut octx).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transcoder.filter.get("in").unwrap().source().flush().unwrap();
|
||||
transcoder
|
||||
.filter
|
||||
.get("in")
|
||||
.unwrap()
|
||||
.source()
|
||||
.flush()
|
||||
.unwrap();
|
||||
|
||||
while let Ok(..) = transcoder.filter.get("out").unwrap().sink().frame(&mut decoded) {
|
||||
if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
|
||||
encoded.set_stream(0);
|
||||
encoded.rescale_ts(in_time_base, out_time_base);
|
||||
encoded.write_interleaved(&mut octx).unwrap();
|
||||
}
|
||||
}
|
||||
while let Ok(..) = transcoder
|
||||
.filter
|
||||
.get("out")
|
||||
.unwrap()
|
||||
.sink()
|
||||
.frame(&mut decoded)
|
||||
{
|
||||
if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
|
||||
encoded.set_stream(0);
|
||||
encoded.rescale_ts(in_time_base, out_time_base);
|
||||
encoded.write_interleaved(&mut octx).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(true) = transcoder.encoder.flush(&mut encoded) {
|
||||
encoded.set_stream(0);
|
||||
encoded.rescale_ts(in_time_base, out_time_base);
|
||||
encoded.write_interleaved(&mut octx).unwrap();
|
||||
}
|
||||
if let Ok(true) = transcoder.encoder.flush(&mut encoded) {
|
||||
encoded.set_stream(0);
|
||||
encoded.rescale_ts(in_time_base, out_time_base);
|
||||
encoded.write_interleaved(&mut octx).unwrap();
|
||||
}
|
||||
|
||||
octx.write_trailer().unwrap();
|
||||
octx.write_trailer().unwrap();
|
||||
}
|
||||
|
||||
+92
-95
@@ -1,152 +1,149 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use {ChannelLayout, format};
|
||||
use super::codec::Codec;
|
||||
use ffi::*;
|
||||
use {format, ChannelLayout};
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
pub struct Audio {
|
||||
codec: Codec,
|
||||
codec: Codec,
|
||||
}
|
||||
|
||||
impl Audio {
|
||||
pub unsafe fn new(codec: Codec) -> Audio {
|
||||
Audio {
|
||||
codec: codec,
|
||||
}
|
||||
}
|
||||
pub unsafe fn new(codec: Codec) -> Audio {
|
||||
Audio { codec: codec }
|
||||
}
|
||||
}
|
||||
|
||||
impl Audio {
|
||||
pub fn rates(&self) -> Option<RateIter> {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).supported_samplerates.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(RateIter::new((*self.codec.as_ptr()).supported_samplerates))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn rates(&self) -> Option<RateIter> {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).supported_samplerates.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(RateIter::new((*self.codec.as_ptr()).supported_samplerates))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn formats(&self) -> Option<FormatIter> {
|
||||
unsafe {
|
||||
if (*self.codec.as_ptr()).sample_fmts.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(FormatIter::new((*self.codec.as_ptr()).sample_fmts))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn formats(&self) -> Option<FormatIter> {
|
||||
unsafe {
|
||||
if (*self.codec.as_ptr()).sample_fmts.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(FormatIter::new((*self.codec.as_ptr()).sample_fmts))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channel_layouts(&self) -> Option<ChannelLayoutIter> {
|
||||
unsafe {
|
||||
if (*self.codec.as_ptr()).channel_layouts.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(ChannelLayoutIter::new((*self.codec.as_ptr()).channel_layouts))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn channel_layouts(&self) -> Option<ChannelLayoutIter> {
|
||||
unsafe {
|
||||
if (*self.codec.as_ptr()).channel_layouts.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(ChannelLayoutIter::new(
|
||||
(*self.codec.as_ptr()).channel_layouts,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Audio {
|
||||
type Target = Codec;
|
||||
type Target = Codec;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.codec
|
||||
}
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.codec
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RateIter {
|
||||
ptr: *const i32,
|
||||
ptr: *const i32,
|
||||
}
|
||||
|
||||
impl RateIter {
|
||||
pub fn new(ptr: *const i32) -> Self {
|
||||
RateIter { ptr: ptr }
|
||||
}
|
||||
pub fn new(ptr: *const i32) -> Self {
|
||||
RateIter { ptr: ptr }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for RateIter {
|
||||
type Item = i32;
|
||||
type Item = i32;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if *self.ptr == 0 {
|
||||
return None;
|
||||
}
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if *self.ptr == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let rate = *self.ptr;
|
||||
self.ptr = self.ptr.offset(1);
|
||||
let rate = *self.ptr;
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(rate)
|
||||
}
|
||||
}
|
||||
Some(rate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FormatIter {
|
||||
ptr: *const AVSampleFormat,
|
||||
ptr: *const AVSampleFormat,
|
||||
}
|
||||
|
||||
impl FormatIter {
|
||||
pub fn new(ptr: *const AVSampleFormat) -> Self {
|
||||
FormatIter { ptr: ptr }
|
||||
}
|
||||
pub fn new(ptr: *const AVSampleFormat) -> Self {
|
||||
FormatIter { ptr: ptr }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for FormatIter {
|
||||
type Item = format::Sample;
|
||||
type Item = format::Sample;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if *self.ptr == AVSampleFormat::AV_SAMPLE_FMT_NONE {
|
||||
return None;
|
||||
}
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if *self.ptr == AVSampleFormat::AV_SAMPLE_FMT_NONE {
|
||||
return None;
|
||||
}
|
||||
|
||||
let format = (*self.ptr).into();
|
||||
self.ptr = self.ptr.offset(1);
|
||||
let format = (*self.ptr).into();
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(format)
|
||||
}
|
||||
}
|
||||
Some(format)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ChannelLayoutIter {
|
||||
ptr: *const u64,
|
||||
ptr: *const u64,
|
||||
}
|
||||
|
||||
impl ChannelLayoutIter {
|
||||
pub fn new(ptr: *const u64) -> Self {
|
||||
ChannelLayoutIter { ptr: ptr }
|
||||
}
|
||||
pub fn new(ptr: *const u64) -> Self {
|
||||
ChannelLayoutIter { ptr: ptr }
|
||||
}
|
||||
|
||||
pub fn best(self, max: i32) -> ChannelLayout {
|
||||
self.fold(::channel_layout::MONO, |acc, cur|
|
||||
if cur.channels() > acc.channels() && cur.channels() <= max {
|
||||
cur
|
||||
}
|
||||
else {
|
||||
acc
|
||||
})
|
||||
}
|
||||
pub fn best(self, max: i32) -> ChannelLayout {
|
||||
self.fold(::channel_layout::MONO, |acc, cur| {
|
||||
if cur.channels() > acc.channels() && cur.channels() <= max {
|
||||
cur
|
||||
} else {
|
||||
acc
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for ChannelLayoutIter {
|
||||
type Item = ChannelLayout;
|
||||
type Item = ChannelLayout;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if *self.ptr == 0 {
|
||||
return None;
|
||||
}
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if *self.ptr == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let layout = ChannelLayout::from_bits_truncate(*self.ptr);
|
||||
self.ptr = self.ptr.offset(1);
|
||||
let layout = ChannelLayout::from_bits_truncate(*self.ptr);
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(layout)
|
||||
}
|
||||
}
|
||||
Some(layout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-37
@@ -1,48 +1,48 @@
|
||||
use ffi::*;
|
||||
use ffi::AVAudioServiceType::*;
|
||||
use ffi::*;
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
||||
pub enum AudioService {
|
||||
Main,
|
||||
Effects,
|
||||
VisuallyImpaired,
|
||||
HearingImpaired,
|
||||
Dialogue,
|
||||
Commentary,
|
||||
Emergency,
|
||||
VoiceOver,
|
||||
Karaoke,
|
||||
Main,
|
||||
Effects,
|
||||
VisuallyImpaired,
|
||||
HearingImpaired,
|
||||
Dialogue,
|
||||
Commentary,
|
||||
Emergency,
|
||||
VoiceOver,
|
||||
Karaoke,
|
||||
}
|
||||
|
||||
impl From<AVAudioServiceType> for AudioService {
|
||||
fn from(value: AVAudioServiceType) -> Self {
|
||||
match value {
|
||||
AV_AUDIO_SERVICE_TYPE_MAIN => AudioService::Main,
|
||||
AV_AUDIO_SERVICE_TYPE_EFFECTS => AudioService::Effects,
|
||||
AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED => AudioService::VisuallyImpaired,
|
||||
AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED => AudioService::HearingImpaired,
|
||||
AV_AUDIO_SERVICE_TYPE_DIALOGUE => AudioService::Dialogue,
|
||||
AV_AUDIO_SERVICE_TYPE_COMMENTARY => AudioService::Commentary,
|
||||
AV_AUDIO_SERVICE_TYPE_EMERGENCY => AudioService::Emergency,
|
||||
AV_AUDIO_SERVICE_TYPE_VOICE_OVER => AudioService::VoiceOver,
|
||||
AV_AUDIO_SERVICE_TYPE_KARAOKE => AudioService::Karaoke,
|
||||
AV_AUDIO_SERVICE_TYPE_NB => AudioService::Main
|
||||
}
|
||||
}
|
||||
fn from(value: AVAudioServiceType) -> Self {
|
||||
match value {
|
||||
AV_AUDIO_SERVICE_TYPE_MAIN => AudioService::Main,
|
||||
AV_AUDIO_SERVICE_TYPE_EFFECTS => AudioService::Effects,
|
||||
AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED => AudioService::VisuallyImpaired,
|
||||
AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED => AudioService::HearingImpaired,
|
||||
AV_AUDIO_SERVICE_TYPE_DIALOGUE => AudioService::Dialogue,
|
||||
AV_AUDIO_SERVICE_TYPE_COMMENTARY => AudioService::Commentary,
|
||||
AV_AUDIO_SERVICE_TYPE_EMERGENCY => AudioService::Emergency,
|
||||
AV_AUDIO_SERVICE_TYPE_VOICE_OVER => AudioService::VoiceOver,
|
||||
AV_AUDIO_SERVICE_TYPE_KARAOKE => AudioService::Karaoke,
|
||||
AV_AUDIO_SERVICE_TYPE_NB => AudioService::Main,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<AVAudioServiceType> for AudioService {
|
||||
fn into(self) -> AVAudioServiceType {
|
||||
match self {
|
||||
AudioService::Main => AV_AUDIO_SERVICE_TYPE_MAIN,
|
||||
AudioService::Effects => AV_AUDIO_SERVICE_TYPE_EFFECTS,
|
||||
AudioService::VisuallyImpaired => AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED,
|
||||
AudioService::HearingImpaired => AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED,
|
||||
AudioService::Dialogue => AV_AUDIO_SERVICE_TYPE_DIALOGUE,
|
||||
AudioService::Commentary => AV_AUDIO_SERVICE_TYPE_COMMENTARY,
|
||||
AudioService::Emergency => AV_AUDIO_SERVICE_TYPE_EMERGENCY,
|
||||
AudioService::VoiceOver => AV_AUDIO_SERVICE_TYPE_VOICE_OVER,
|
||||
AudioService::Karaoke => AV_AUDIO_SERVICE_TYPE_KARAOKE
|
||||
}
|
||||
}
|
||||
fn into(self) -> AVAudioServiceType {
|
||||
match self {
|
||||
AudioService::Main => AV_AUDIO_SERVICE_TYPE_MAIN,
|
||||
AudioService::Effects => AV_AUDIO_SERVICE_TYPE_EFFECTS,
|
||||
AudioService::VisuallyImpaired => AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED,
|
||||
AudioService::HearingImpaired => AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED,
|
||||
AudioService::Dialogue => AV_AUDIO_SERVICE_TYPE_DIALOGUE,
|
||||
AudioService::Commentary => AV_AUDIO_SERVICE_TYPE_COMMENTARY,
|
||||
AudioService::Emergency => AV_AUDIO_SERVICE_TYPE_EMERGENCY,
|
||||
AudioService::VoiceOver => AV_AUDIO_SERVICE_TYPE_VOICE_OVER,
|
||||
AudioService::Karaoke => AV_AUDIO_SERVICE_TYPE_KARAOKE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-19
@@ -1,23 +1,23 @@
|
||||
use libc::c_uint;
|
||||
use ffi::*;
|
||||
use libc::c_uint;
|
||||
|
||||
bitflags! {
|
||||
pub struct Capabilities: c_uint {
|
||||
const DRAW_HORIZ_BAND = AV_CODEC_CAP_DRAW_HORIZ_BAND;
|
||||
const DR1 = AV_CODEC_CAP_DR1;
|
||||
const TRUNCATED = AV_CODEC_CAP_TRUNCATED;
|
||||
const DELAY = AV_CODEC_CAP_DELAY;
|
||||
const SMALL_LAST_FRAME = AV_CODEC_CAP_SMALL_LAST_FRAME;
|
||||
const HWACCEL_VDPAU = AV_CODEC_CAP_HWACCEL_VDPAU;
|
||||
const SUBFRAMES = AV_CODEC_CAP_SUBFRAMES;
|
||||
const EXPERIMENTAL = AV_CODEC_CAP_EXPERIMENTAL;
|
||||
const CHANNEL_CONF = AV_CODEC_CAP_CHANNEL_CONF;
|
||||
const FRAME_THREADS = AV_CODEC_CAP_FRAME_THREADS;
|
||||
const SLICE_THREADS = AV_CODEC_CAP_SLICE_THREADS;
|
||||
const PARAM_CHANGE = AV_CODEC_CAP_PARAM_CHANGE;
|
||||
const AUTO_THREADS = AV_CODEC_CAP_AUTO_THREADS;
|
||||
const VARIABLE_FRAME_SIZE = AV_CODEC_CAP_VARIABLE_FRAME_SIZE;
|
||||
const INTRA_ONLY = AV_CODEC_CAP_INTRA_ONLY;
|
||||
const LOSSLESS = AV_CODEC_CAP_LOSSLESS;
|
||||
}
|
||||
pub struct Capabilities: c_uint {
|
||||
const DRAW_HORIZ_BAND = AV_CODEC_CAP_DRAW_HORIZ_BAND;
|
||||
const DR1 = AV_CODEC_CAP_DR1;
|
||||
const TRUNCATED = AV_CODEC_CAP_TRUNCATED;
|
||||
const DELAY = AV_CODEC_CAP_DELAY;
|
||||
const SMALL_LAST_FRAME = AV_CODEC_CAP_SMALL_LAST_FRAME;
|
||||
const HWACCEL_VDPAU = AV_CODEC_CAP_HWACCEL_VDPAU;
|
||||
const SUBFRAMES = AV_CODEC_CAP_SUBFRAMES;
|
||||
const EXPERIMENTAL = AV_CODEC_CAP_EXPERIMENTAL;
|
||||
const CHANNEL_CONF = AV_CODEC_CAP_CHANNEL_CONF;
|
||||
const FRAME_THREADS = AV_CODEC_CAP_FRAME_THREADS;
|
||||
const SLICE_THREADS = AV_CODEC_CAP_SLICE_THREADS;
|
||||
const PARAM_CHANGE = AV_CODEC_CAP_PARAM_CHANGE;
|
||||
const AUTO_THREADS = AV_CODEC_CAP_AUTO_THREADS;
|
||||
const VARIABLE_FRAME_SIZE = AV_CODEC_CAP_VARIABLE_FRAME_SIZE;
|
||||
const INTRA_ONLY = AV_CODEC_CAP_INTRA_ONLY;
|
||||
const LOSSLESS = AV_CODEC_CAP_LOSSLESS;
|
||||
}
|
||||
}
|
||||
|
||||
+87
-106
@@ -1,147 +1,128 @@
|
||||
use std::ffi::CStr;
|
||||
use std::str::from_utf8_unchecked;
|
||||
|
||||
use super::{Audio, Capabilities, Id, Profile, Video};
|
||||
use ffi::*;
|
||||
use super::{Id, Video, Audio, Capabilities, Profile};
|
||||
use ::{Error, media};
|
||||
use {media, Error};
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
pub struct Codec {
|
||||
ptr: *mut AVCodec,
|
||||
ptr: *mut AVCodec,
|
||||
}
|
||||
|
||||
unsafe impl Send for Codec { }
|
||||
unsafe impl Sync for Codec { }
|
||||
unsafe impl Send for Codec {}
|
||||
unsafe impl Sync for Codec {}
|
||||
|
||||
impl Codec {
|
||||
pub unsafe fn wrap(ptr: *mut AVCodec) -> Self {
|
||||
Codec { ptr: ptr }
|
||||
}
|
||||
pub unsafe fn wrap(ptr: *mut AVCodec) -> Self {
|
||||
Codec { ptr: ptr }
|
||||
}
|
||||
|
||||
pub unsafe fn as_ptr(&self) -> *const AVCodec {
|
||||
self.ptr as *const _
|
||||
}
|
||||
pub unsafe fn as_ptr(&self) -> *const AVCodec {
|
||||
self.ptr as *const _
|
||||
}
|
||||
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodec {
|
||||
self.ptr
|
||||
}
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodec {
|
||||
self.ptr
|
||||
}
|
||||
}
|
||||
|
||||
impl Codec {
|
||||
pub fn is_encoder(&self) -> bool {
|
||||
unsafe {
|
||||
av_codec_is_encoder(self.as_ptr()) != 0
|
||||
}
|
||||
}
|
||||
pub fn is_encoder(&self) -> bool {
|
||||
unsafe { av_codec_is_encoder(self.as_ptr()) != 0 }
|
||||
}
|
||||
|
||||
pub fn is_decoder(&self) -> bool {
|
||||
unsafe {
|
||||
av_codec_is_decoder(self.as_ptr()) != 0
|
||||
}
|
||||
}
|
||||
pub fn is_decoder(&self) -> bool {
|
||||
unsafe { av_codec_is_decoder(self.as_ptr()) != 0 }
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe {
|
||||
from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes())
|
||||
}
|
||||
}
|
||||
pub fn name(&self) -> &str {
|
||||
unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) }
|
||||
}
|
||||
|
||||
pub fn description(&self) -> &str {
|
||||
unsafe {
|
||||
from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes())
|
||||
}
|
||||
}
|
||||
pub fn description(&self) -> &str {
|
||||
unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) }
|
||||
}
|
||||
|
||||
pub fn medium(&self) -> media::Type {
|
||||
unsafe {
|
||||
media::Type::from((*self.as_ptr()).type_)
|
||||
}
|
||||
}
|
||||
pub fn medium(&self) -> media::Type {
|
||||
unsafe { media::Type::from((*self.as_ptr()).type_) }
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Id {
|
||||
unsafe {
|
||||
Id::from((*self.as_ptr()).id)
|
||||
}
|
||||
}
|
||||
pub fn id(&self) -> Id {
|
||||
unsafe { Id::from((*self.as_ptr()).id) }
|
||||
}
|
||||
|
||||
pub fn is_video(&self) -> bool {
|
||||
self.medium() == media::Type::Video
|
||||
}
|
||||
pub fn is_video(&self) -> bool {
|
||||
self.medium() == media::Type::Video
|
||||
}
|
||||
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
unsafe {
|
||||
if self.medium() == media::Type::Video {
|
||||
Ok(Video::new(self))
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
unsafe {
|
||||
if self.medium() == media::Type::Video {
|
||||
Ok(Video::new(self))
|
||||
} else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_audio(&self) -> bool {
|
||||
self.medium() == media::Type::Audio
|
||||
}
|
||||
pub fn is_audio(&self) -> bool {
|
||||
self.medium() == media::Type::Audio
|
||||
}
|
||||
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
unsafe {
|
||||
if self.medium() == media::Type::Audio {
|
||||
Ok(Audio::new(self))
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
unsafe {
|
||||
if self.medium() == media::Type::Audio {
|
||||
Ok(Audio::new(self))
|
||||
} else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_lowres(&self) -> i32 {
|
||||
unsafe {
|
||||
av_codec_get_max_lowres(self.as_ptr())
|
||||
}
|
||||
}
|
||||
pub fn max_lowres(&self) -> i32 {
|
||||
unsafe { av_codec_get_max_lowres(self.as_ptr()) }
|
||||
}
|
||||
|
||||
pub fn capabilities(&self) -> Capabilities {
|
||||
unsafe {
|
||||
Capabilities::from_bits_truncate((*self.as_ptr()).capabilities as u32)
|
||||
}
|
||||
}
|
||||
pub fn capabilities(&self) -> Capabilities {
|
||||
unsafe { Capabilities::from_bits_truncate((*self.as_ptr()).capabilities as u32) }
|
||||
}
|
||||
|
||||
pub fn profiles(&self) -> Option<ProfileIter> {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).profiles.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(ProfileIter::new(self.id(), (*self.as_ptr()).profiles))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn profiles(&self) -> Option<ProfileIter> {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).profiles.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(ProfileIter::new(self.id(), (*self.as_ptr()).profiles))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ProfileIter {
|
||||
id: Id,
|
||||
ptr: *const AVProfile,
|
||||
id: Id,
|
||||
ptr: *const AVProfile,
|
||||
}
|
||||
|
||||
impl ProfileIter {
|
||||
pub fn new(id: Id, ptr: *const AVProfile) -> Self {
|
||||
ProfileIter { id: id, ptr: ptr }
|
||||
}
|
||||
pub fn new(id: Id, ptr: *const AVProfile) -> Self {
|
||||
ProfileIter { id: id, ptr: ptr }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for ProfileIter {
|
||||
type Item = Profile;
|
||||
type Item = Profile;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if (*self.ptr).profile == FF_PROFILE_UNKNOWN {
|
||||
return None;
|
||||
}
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if (*self.ptr).profile == FF_PROFILE_UNKNOWN {
|
||||
return None;
|
||||
}
|
||||
|
||||
let profile = Profile::from((self.id, (*self.ptr).profile));
|
||||
self.ptr = self.ptr.offset(1);
|
||||
let profile = Profile::from((self.id, (*self.ptr).profile));
|
||||
self.ptr = self.ptr.offset(1);
|
||||
|
||||
Some(profile)
|
||||
}
|
||||
}
|
||||
Some(profile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -1,37 +1,37 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
||||
pub enum Compliance {
|
||||
VeryStrict,
|
||||
Strict,
|
||||
Normal,
|
||||
Unofficial,
|
||||
Experimental,
|
||||
VeryStrict,
|
||||
Strict,
|
||||
Normal,
|
||||
Unofficial,
|
||||
Experimental,
|
||||
}
|
||||
|
||||
impl From<c_int> for Compliance {
|
||||
fn from(value: c_int) -> Self {
|
||||
match value {
|
||||
FF_COMPLIANCE_VERY_STRICT => Compliance::VeryStrict,
|
||||
FF_COMPLIANCE_STRICT => Compliance::Strict,
|
||||
FF_COMPLIANCE_NORMAL => Compliance::Normal,
|
||||
FF_COMPLIANCE_UNOFFICIAL => Compliance::Unofficial,
|
||||
FF_COMPLIANCE_EXPERIMENTAL => Compliance::Experimental,
|
||||
fn from(value: c_int) -> Self {
|
||||
match value {
|
||||
FF_COMPLIANCE_VERY_STRICT => Compliance::VeryStrict,
|
||||
FF_COMPLIANCE_STRICT => Compliance::Strict,
|
||||
FF_COMPLIANCE_NORMAL => Compliance::Normal,
|
||||
FF_COMPLIANCE_UNOFFICIAL => Compliance::Unofficial,
|
||||
FF_COMPLIANCE_EXPERIMENTAL => Compliance::Experimental,
|
||||
|
||||
_ => Compliance::Normal
|
||||
}
|
||||
}
|
||||
_ => Compliance::Normal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<c_int> for Compliance {
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
Compliance::VeryStrict => FF_COMPLIANCE_VERY_STRICT,
|
||||
Compliance::Strict => FF_COMPLIANCE_STRICT,
|
||||
Compliance::Normal => FF_COMPLIANCE_NORMAL,
|
||||
Compliance::Unofficial => FF_COMPLIANCE_UNOFFICIAL,
|
||||
Compliance::Experimental => FF_COMPLIANCE_EXPERIMENTAL
|
||||
}
|
||||
}
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
Compliance::VeryStrict => FF_COMPLIANCE_VERY_STRICT,
|
||||
Compliance::Strict => FF_COMPLIANCE_STRICT,
|
||||
Compliance::Normal => FF_COMPLIANCE_NORMAL,
|
||||
Compliance::Unofficial => FF_COMPLIANCE_UNOFFICIAL,
|
||||
Compliance::Experimental => FF_COMPLIANCE_EXPERIMENTAL,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+112
-105
@@ -1,142 +1,149 @@
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use ::media;
|
||||
use ::{Codec, Error};
|
||||
use super::{Flags, Id, Debug, Compliance, threading, Parameters};
|
||||
use super::decoder::Decoder;
|
||||
use super::encoder::Encoder;
|
||||
use super::{threading, Compliance, Debug, Flags, Id, Parameters};
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
use media;
|
||||
use {Codec, Error};
|
||||
|
||||
pub struct Context {
|
||||
ptr: *mut AVCodecContext,
|
||||
owner: Option<Rc<Drop>>,
|
||||
ptr: *mut AVCodecContext,
|
||||
owner: Option<Rc<Drop>>,
|
||||
}
|
||||
|
||||
unsafe impl Send for Context { }
|
||||
unsafe impl Send for Context {}
|
||||
|
||||
impl Context {
|
||||
pub unsafe fn wrap(ptr: *mut AVCodecContext, owner: Option<Rc<Drop>>) -> Self {
|
||||
Context { ptr: ptr, owner: owner }
|
||||
}
|
||||
pub unsafe fn wrap(ptr: *mut AVCodecContext, owner: Option<Rc<Drop>>) -> Self {
|
||||
Context {
|
||||
ptr: ptr,
|
||||
owner: owner,
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn as_ptr(&self) -> *const AVCodecContext {
|
||||
self.ptr as *const _
|
||||
}
|
||||
pub unsafe fn as_ptr(&self) -> *const AVCodecContext {
|
||||
self.ptr as *const _
|
||||
}
|
||||
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecContext {
|
||||
self.ptr
|
||||
}
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecContext {
|
||||
self.ptr
|
||||
}
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
Context { ptr: avcodec_alloc_context3(ptr::null()), owner: None }
|
||||
}
|
||||
}
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
Context {
|
||||
ptr: avcodec_alloc_context3(ptr::null()),
|
||||
owner: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decoder(self) -> Decoder {
|
||||
Decoder(self)
|
||||
}
|
||||
pub fn decoder(self) -> Decoder {
|
||||
Decoder(self)
|
||||
}
|
||||
|
||||
pub fn encoder(self) -> Encoder {
|
||||
Encoder(self)
|
||||
}
|
||||
pub fn encoder(self) -> Encoder {
|
||||
Encoder(self)
|
||||
}
|
||||
|
||||
pub fn codec(&self) -> Option<Codec> {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).codec.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Codec::wrap((*self.as_ptr()).codec as *mut _))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn codec(&self) -> Option<Codec> {
|
||||
unsafe {
|
||||
if (*self.as_ptr()).codec.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(Codec::wrap((*self.as_ptr()).codec as *mut _))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn medium(&self) -> media::Type {
|
||||
unsafe {
|
||||
media::Type::from((*self.as_ptr()).codec_type)
|
||||
}
|
||||
}
|
||||
pub fn medium(&self) -> media::Type {
|
||||
unsafe { media::Type::from((*self.as_ptr()).codec_type) }
|
||||
}
|
||||
|
||||
pub fn set_flags(&mut self, value: Flags) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).flags = value.bits() as c_int;
|
||||
}
|
||||
}
|
||||
pub fn set_flags(&mut self, value: Flags) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).flags = value.bits() as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Id {
|
||||
unsafe {
|
||||
Id::from((*self.as_ptr()).codec_id)
|
||||
}
|
||||
}
|
||||
pub fn id(&self) -> Id {
|
||||
unsafe { Id::from((*self.as_ptr()).codec_id) }
|
||||
}
|
||||
|
||||
pub fn compliance(&mut self, value: Compliance) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).strict_std_compliance = value.into();
|
||||
}
|
||||
}
|
||||
pub fn compliance(&mut self, value: Compliance) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).strict_std_compliance = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn debug(&mut self, value: Debug) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).debug = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn debug(&mut self, value: Debug) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).debug = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_threading(&mut self, config: threading::Config) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).thread_type = config.kind.into();
|
||||
(*self.as_mut_ptr()).thread_count = config.count as c_int;
|
||||
(*self.as_mut_ptr()).thread_safe_callbacks = if config.safe { 1 } else { 0 };
|
||||
}
|
||||
}
|
||||
pub fn set_threading(&mut self, config: threading::Config) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).thread_type = config.kind.into();
|
||||
(*self.as_mut_ptr()).thread_count = config.count as c_int;
|
||||
(*self.as_mut_ptr()).thread_safe_callbacks = if config.safe { 1 } else { 0 };
|
||||
}
|
||||
}
|
||||
|
||||
pub fn threading(&self) -> threading::Config {
|
||||
unsafe {
|
||||
threading::Config {
|
||||
kind: threading::Type::from((*self.as_ptr()).active_thread_type),
|
||||
count: (*self.as_ptr()).thread_count as usize,
|
||||
safe: (*self.as_ptr()).thread_safe_callbacks != 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn threading(&self) -> threading::Config {
|
||||
unsafe {
|
||||
threading::Config {
|
||||
kind: threading::Type::from((*self.as_ptr()).active_thread_type),
|
||||
count: (*self.as_ptr()).thread_count as usize,
|
||||
safe: (*self.as_ptr()).thread_safe_callbacks != 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_parameters<P: Into<Parameters>>(&mut self, parameters: P) -> Result<(), Error> {
|
||||
let parameters = parameters.into();
|
||||
pub fn set_parameters<P: Into<Parameters>>(&mut self, parameters: P) -> Result<(), Error> {
|
||||
let parameters = parameters.into();
|
||||
|
||||
unsafe {
|
||||
match avcodec_parameters_to_context(self.as_mut_ptr(), parameters.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
match avcodec_parameters_to_context(self.as_mut_ptr(), parameters.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Context {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Context {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
if self.owner.is_none() {
|
||||
avcodec_free_context(&mut self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
if self.owner.is_none() {
|
||||
avcodec_free_context(&mut self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Context {
|
||||
fn clone(&self) -> Self {
|
||||
let mut ctx = Context::new();
|
||||
ctx.clone_from(self);
|
||||
fn clone(&self) -> Self {
|
||||
let mut ctx = Context::new();
|
||||
ctx.clone_from(self);
|
||||
|
||||
ctx
|
||||
}
|
||||
ctx
|
||||
}
|
||||
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
unsafe {
|
||||
avcodec_copy_context(self.as_mut_ptr(), source.as_ptr());
|
||||
}
|
||||
}
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
unsafe {
|
||||
avcodec_copy_context(self.as_mut_ptr(), source.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-21
@@ -1,25 +1,25 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
bitflags! {
|
||||
pub struct Debug: c_int {
|
||||
const PICT_INFO = FF_DEBUG_PICT_INFO;
|
||||
const RC = FF_DEBUG_RC;
|
||||
const BITSTREAM = FF_DEBUG_BITSTREAM;
|
||||
const MB_TYPE = FF_DEBUG_MB_TYPE;
|
||||
const QP = FF_DEBUG_QP;
|
||||
const MV = FF_DEBUG_MV;
|
||||
const DCT_COEFF = FF_DEBUG_DCT_COEFF;
|
||||
const SKIP = FF_DEBUG_SKIP;
|
||||
const STARTCODE = FF_DEBUG_STARTCODE;
|
||||
const PTS = FF_DEBUG_PTS;
|
||||
const ER = FF_DEBUG_ER;
|
||||
const MMCO = FF_DEBUG_MMCO;
|
||||
const BUGS = FF_DEBUG_BUGS;
|
||||
const VIS_QP = FF_DEBUG_VIS_QP;
|
||||
const VIS_MB_TYPE = FF_DEBUG_VIS_MB_TYPE;
|
||||
const BUFFERS = FF_DEBUG_BUFFERS;
|
||||
const THREADS = FF_DEBUG_THREADS;
|
||||
const NOMC = FF_DEBUG_NOMC;
|
||||
}
|
||||
pub struct Debug: c_int {
|
||||
const PICT_INFO = FF_DEBUG_PICT_INFO;
|
||||
const RC = FF_DEBUG_RC;
|
||||
const BITSTREAM = FF_DEBUG_BITSTREAM;
|
||||
const MB_TYPE = FF_DEBUG_MB_TYPE;
|
||||
const QP = FF_DEBUG_QP;
|
||||
const MV = FF_DEBUG_MV;
|
||||
const DCT_COEFF = FF_DEBUG_DCT_COEFF;
|
||||
const SKIP = FF_DEBUG_SKIP;
|
||||
const STARTCODE = FF_DEBUG_STARTCODE;
|
||||
const PTS = FF_DEBUG_PTS;
|
||||
const ER = FF_DEBUG_ER;
|
||||
const MMCO = FF_DEBUG_MMCO;
|
||||
const BUGS = FF_DEBUG_BUGS;
|
||||
const VIS_QP = FF_DEBUG_VIS_QP;
|
||||
const VIS_MB_TYPE = FF_DEBUG_VIS_MB_TYPE;
|
||||
const BUFFERS = FF_DEBUG_BUFFERS;
|
||||
const THREADS = FF_DEBUG_THREADS;
|
||||
const NOMC = FF_DEBUG_NOMC;
|
||||
}
|
||||
}
|
||||
|
||||
+86
-95
@@ -1,132 +1,123 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
use super::Opened;
|
||||
use ::{packet, Error, AudioService, ChannelLayout};
|
||||
use ::frame;
|
||||
use ::util::format;
|
||||
use ::codec::Context;
|
||||
use codec::Context;
|
||||
use frame;
|
||||
use util::format;
|
||||
use {packet, AudioService, ChannelLayout, Error};
|
||||
|
||||
pub struct Audio(pub Opened);
|
||||
|
||||
impl Audio {
|
||||
pub fn decode<P: packet::Ref>(&mut self, packet: &P, out: &mut frame::Audio) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
pub fn decode<P: packet::Ref>(
|
||||
&mut self,
|
||||
packet: &P,
|
||||
out: &mut frame::Audio,
|
||||
) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
|
||||
match avcodec_decode_audio4(self.as_mut_ptr(), out.as_mut_ptr(), &mut got, packet.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
match avcodec_decode_audio4(
|
||||
self.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
&mut got,
|
||||
packet.as_ptr(),
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rate(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).sample_rate as u32
|
||||
}
|
||||
}
|
||||
pub fn rate(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).sample_rate as u32 }
|
||||
}
|
||||
|
||||
pub fn channels(&self) -> u16 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).channels as u16
|
||||
}
|
||||
}
|
||||
pub fn channels(&self) -> u16 {
|
||||
unsafe { (*self.as_ptr()).channels as u16 }
|
||||
}
|
||||
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe {
|
||||
format::Sample::from((*self.as_ptr()).sample_fmt)
|
||||
}
|
||||
}
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe { format::Sample::from((*self.as_ptr()).sample_fmt) }
|
||||
}
|
||||
|
||||
pub fn request_format(&mut self, value: format::Sample) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).request_sample_fmt = value.into();
|
||||
}
|
||||
}
|
||||
pub fn request_format(&mut self, value: format::Sample) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).request_sample_fmt = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn frames(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).frame_number as usize
|
||||
}
|
||||
}
|
||||
pub fn frames(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).frame_number as usize }
|
||||
}
|
||||
|
||||
pub fn align(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).block_align as usize
|
||||
}
|
||||
}
|
||||
pub fn align(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).block_align as usize }
|
||||
}
|
||||
|
||||
pub fn channel_layout(&self) -> ChannelLayout {
|
||||
unsafe {
|
||||
ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout)
|
||||
}
|
||||
}
|
||||
pub fn channel_layout(&self) -> ChannelLayout {
|
||||
unsafe { ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) }
|
||||
}
|
||||
|
||||
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).request_channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn request_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).request_channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio_service(&mut self) -> AudioService {
|
||||
unsafe {
|
||||
AudioService::from((*self.as_mut_ptr()).audio_service_type)
|
||||
}
|
||||
}
|
||||
pub fn audio_service(&mut self) -> AudioService {
|
||||
unsafe { AudioService::from((*self.as_mut_ptr()).audio_service_type) }
|
||||
}
|
||||
|
||||
pub fn max_bit_rate(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).rc_max_rate as usize
|
||||
}
|
||||
}
|
||||
pub fn max_bit_rate(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).rc_max_rate as usize }
|
||||
}
|
||||
|
||||
pub fn frame_size(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).frame_size as u32
|
||||
}
|
||||
}
|
||||
pub fn frame_size(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).frame_size as u32 }
|
||||
}
|
||||
|
||||
pub fn frame_start(&self) -> Option<usize> {
|
||||
unsafe {
|
||||
match (*self.as_ptr()).timecode_frame_start {
|
||||
-1 => None,
|
||||
n => Some(n as usize)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn frame_start(&self) -> Option<usize> {
|
||||
unsafe {
|
||||
match (*self.as_ptr()).timecode_frame_start {
|
||||
-1 => None,
|
||||
n => Some(n as usize),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Audio {
|
||||
type Target = Opened;
|
||||
type Target = Opened;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Audio {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Audio {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Audio {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,16 +1,16 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
bitflags! {
|
||||
pub struct Check: c_int {
|
||||
const CRC = AV_EF_CRCCHECK;
|
||||
const BISTREAM = AV_EF_BITSTREAM;
|
||||
const BUFFER = AV_EF_BUFFER;
|
||||
const EXPLODE = AV_EF_EXPLODE;
|
||||
pub struct Check: c_int {
|
||||
const CRC = AV_EF_CRCCHECK;
|
||||
const BISTREAM = AV_EF_BITSTREAM;
|
||||
const BUFFER = AV_EF_BUFFER;
|
||||
const EXPLODE = AV_EF_EXPLODE;
|
||||
|
||||
const IGNORE_ERROR = AV_EF_IGNORE_ERR;
|
||||
const CAREFUL = AV_EF_CAREFUL;
|
||||
const COMPLIANT = AV_EF_COMPLIANT;
|
||||
const AGGRESSIVE = AV_EF_AGGRESSIVE;
|
||||
}
|
||||
const IGNORE_ERROR = AV_EF_IGNORE_ERR;
|
||||
const CAREFUL = AV_EF_CAREFUL;
|
||||
const COMPLIANT = AV_EF_COMPLIANT;
|
||||
const AGGRESSIVE = AV_EF_AGGRESSIVE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
bitflags! {
|
||||
pub struct Conceal: c_int {
|
||||
const GUESS_MVS = FF_EC_GUESS_MVS;
|
||||
const DEBLOCK = FF_EC_DEBLOCK;
|
||||
const FAVOR_INTER = FF_EC_FAVOR_INTER;
|
||||
}
|
||||
pub struct Conceal: c_int {
|
||||
const GUESS_MVS = FF_EC_GUESS_MVS;
|
||||
const DEBLOCK = FF_EC_DEBLOCK;
|
||||
const FAVOR_INTER = FF_EC_FAVOR_INTER;
|
||||
}
|
||||
}
|
||||
|
||||
+105
-108
@@ -1,142 +1,139 @@
|
||||
use std::ptr;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
|
||||
use super::{Audio, Check, Conceal, Opened, Subtitle, Video};
|
||||
use codec::{traits, Context};
|
||||
use ffi::*;
|
||||
use codec::{Context, traits};
|
||||
use super::{Opened, Video, Audio, Subtitle, Conceal, Check};
|
||||
use ::{Error, Discard, Rational, Dictionary};
|
||||
use {Dictionary, Discard, Error, Rational};
|
||||
|
||||
pub struct Decoder(pub Context);
|
||||
|
||||
impl Decoder {
|
||||
pub fn open(mut self) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open(mut self) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as<D: traits::Decoder>(mut self, codec: D) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.decoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open_as<D: traits::Decoder>(mut self, codec: D) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.decoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as_with<D: traits::Decoder>(mut self, codec: D, options: Dictionary) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.decoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
pub fn open_as_with<D: traits::Decoder>(
|
||||
mut self,
|
||||
codec: D,
|
||||
options: Dictionary,
|
||||
) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.decoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
match res {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.video())
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.video())
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.audio())
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.audio())
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subtitle(self) -> Result<Subtitle, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.subtitle())
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
pub fn subtitle(self) -> Result<Subtitle, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.subtitle())
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn conceal(&mut self, value: Conceal) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).error_concealment = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn conceal(&mut self, value: Conceal) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).error_concealment = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check(&mut self, value: Check) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).err_recognition = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn check(&mut self, value: Check) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).err_recognition = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip_loop_filter(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_loop_filter = value.into();
|
||||
}
|
||||
}
|
||||
pub fn skip_loop_filter(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_loop_filter = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip_idct(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_idct = value.into();
|
||||
}
|
||||
}
|
||||
pub fn skip_idct(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_idct = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip_frame(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_frame = value.into();
|
||||
}
|
||||
}
|
||||
pub fn skip_frame(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_frame = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe {
|
||||
Rational::from((*self.as_ptr()).time_base)
|
||||
}
|
||||
}
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Decoder {
|
||||
type Target = Context;
|
||||
type Target = Context;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Decoder {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Decoder {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Decoder {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
+20
-22
@@ -23,38 +23,36 @@ pub use self::opened::Opened;
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
use ffi::*;
|
||||
use codec::Context;
|
||||
use ::Codec;
|
||||
use codec::Id;
|
||||
use ffi::*;
|
||||
use Codec;
|
||||
|
||||
pub fn new() -> Decoder {
|
||||
Context::new().decoder()
|
||||
Context::new().decoder()
|
||||
}
|
||||
|
||||
pub fn find(id: Id) -> Option<Codec> {
|
||||
unsafe {
|
||||
let ptr = avcodec_find_decoder(id.into());
|
||||
unsafe {
|
||||
let ptr = avcodec_find_decoder(id.into());
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_by_name(name: &str) -> Option<Codec> {
|
||||
unsafe {
|
||||
let name = CString::new(name).unwrap();
|
||||
let ptr = avcodec_find_decoder_by_name(name.as_ptr());
|
||||
unsafe {
|
||||
let name = CString::new(name).unwrap();
|
||||
let ptr = avcodec_find_decoder_by_name(name.as_ptr());
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+67
-77
@@ -1,109 +1,99 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use super::{Audio, Decoder, Subtitle, Video};
|
||||
use codec::{Context, Profile};
|
||||
use ffi::*;
|
||||
use super::{Video, Audio, Subtitle, Decoder};
|
||||
use ::codec::{Profile, Context};
|
||||
use ::{Error, Rational};
|
||||
use ::media;
|
||||
use media;
|
||||
use {Error, Rational};
|
||||
|
||||
pub struct Opened(pub Decoder);
|
||||
|
||||
impl Opened {
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
if self.medium() == media::Type::Video {
|
||||
Ok(Video(self))
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
if self.medium() == media::Type::Video {
|
||||
Ok(Video(self))
|
||||
} else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
if self.medium() == media::Type::Audio {
|
||||
Ok(Audio(self))
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
if self.medium() == media::Type::Audio {
|
||||
Ok(Audio(self))
|
||||
} else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subtitle(self) -> Result<Subtitle, Error> {
|
||||
if self.medium() == media::Type::Subtitle {
|
||||
Ok(Subtitle(self))
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
pub fn subtitle(self) -> Result<Subtitle, Error> {
|
||||
if self.medium() == media::Type::Subtitle {
|
||||
Ok(Subtitle(self))
|
||||
} else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bit_rate(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).bit_rate as usize
|
||||
}
|
||||
}
|
||||
pub fn bit_rate(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).bit_rate as usize }
|
||||
}
|
||||
|
||||
pub fn delay(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).delay as usize
|
||||
}
|
||||
}
|
||||
pub fn delay(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).delay as usize }
|
||||
}
|
||||
|
||||
pub fn profile(&self) -> Profile {
|
||||
unsafe {
|
||||
Profile::from((self.id(), (*self.as_ptr()).profile))
|
||||
}
|
||||
}
|
||||
pub fn profile(&self) -> Profile {
|
||||
unsafe { Profile::from((self.id(), (*self.as_ptr()).profile)) }
|
||||
}
|
||||
|
||||
pub fn frame_rate(&self) -> Option<Rational> {
|
||||
unsafe {
|
||||
let value = (*self.as_ptr()).framerate;
|
||||
pub fn frame_rate(&self) -> Option<Rational> {
|
||||
unsafe {
|
||||
let value = (*self.as_ptr()).framerate;
|
||||
|
||||
if value == (AVRational { num: 0, den: 1 }) {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Rational::from(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if value == (AVRational { num: 0, den: 1 }) {
|
||||
None
|
||||
} else {
|
||||
Some(Rational::from(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flush(&mut self) {
|
||||
unsafe {
|
||||
avcodec_flush_buffers(self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
pub fn flush(&mut self) {
|
||||
unsafe {
|
||||
avcodec_flush_buffers(self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Opened {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
avcodec_close(self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
avcodec_close(self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Opened {
|
||||
type Target = Decoder;
|
||||
type Target = Decoder;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Opened {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Opened {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Opened {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
bitflags! {
|
||||
pub struct Flags: c_int {
|
||||
const CODED_ORDER = SLICE_FLAG_CODED_ORDER;
|
||||
const ALLOW_FIELD = SLICE_FLAG_ALLOW_FIELD;
|
||||
const ALLOW_PLANE = SLICE_FLAG_ALLOW_PLANE;
|
||||
}
|
||||
pub struct Flags: c_int {
|
||||
const CODED_ORDER = SLICE_FLAG_CODED_ORDER;
|
||||
const ALLOW_FIELD = SLICE_FLAG_ALLOW_FIELD;
|
||||
const ALLOW_PLANE = SLICE_FLAG_ALLOW_PLANE;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user