From c471ab9df86b8ff0bc95c5b4db312dccde719148 Mon Sep 17 00:00:00 2001 From: lummax Date: Wed, 14 Oct 2015 16:23:16 +0200 Subject: [PATCH] examples/transcode-audio: extend example with seek ability --- examples/transcode-audio.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/transcode-audio.rs b/examples/transcode-audio.rs index 4486284..fff891b 100644 --- a/examples/transcode-audio.rs +++ b/examples/transcode-audio.rs @@ -90,17 +90,28 @@ fn transcoder>(ictx: &mut format::context::Input, octx: &mut form // // Example 2: Overlay an audio file // transcode-audio in.mp3 out.mp3 "amovie=overlay.mp3 [ov]; [in][ov] amerge [out]" +// +// Example 3: Seek to a specified position (in seconds) +// transcode-audio in.mp3 out.mp3 anull 30 fn main() { 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::().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(); + if let Some(position) = seek { + // If this seek was embedded in the transcoding loop, a call of `flush()` + // for every opened buffer after the successful seek would be advisable. + let position = position * ffmpeg::ffi::AV_TIME_BASE; + ictx.seek(position, ..position).unwrap(); + } + octx.set_metadata(ictx.metadata().to_owned()); octx.write_header().unwrap();