*: 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:
Tadas Barzdžius
2018-04-10 17:06:42 +03:00
committed by meh
parent 20c7ef399a
commit 0bcd4550b8
128 changed files with 10643 additions and 10233 deletions

View File

@ -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),
}
}

View File

@ -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());
}
}
}

View File

@ -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),
}
}

View File

@ -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();
}