pub struct Parameters { /* private fields */ }
Implementations§
Source§impl Parameters
impl Parameters
pub unsafe fn wrap( ptr: *mut AVCodecParameters, owner: Option<Rc<dyn Any>>, ) -> Self
pub unsafe fn as_ptr(&self) -> *const AVCodecParameters
Sourcepub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecParameters
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecParameters
Examples found in repository?
examples/remux.rs (line 38)
7fn main() {
8 let input_file = env::args().nth(1).expect("missing input file");
9 let output_file = env::args().nth(2).expect("missing output file");
10
11 ffmpeg::init().unwrap();
12 log::set_level(log::Level::Warning);
13
14 let mut ictx = format::input(&input_file).unwrap();
15 let mut octx = format::output(&output_file).unwrap();
16
17 let mut stream_mapping = vec![0; ictx.nb_streams() as _];
18 let mut ist_time_bases = vec![Rational(0, 1); ictx.nb_streams() as _];
19 let mut ost_index = 0;
20 for (ist_index, ist) in ictx.streams().enumerate() {
21 let ist_medium = ist.parameters().medium();
22 if ist_medium != media::Type::Audio
23 && ist_medium != media::Type::Video
24 && ist_medium != media::Type::Subtitle
25 {
26 stream_mapping[ist_index] = -1;
27 continue;
28 }
29 stream_mapping[ist_index] = ost_index;
30 ist_time_bases[ist_index] = ist.time_base();
31 ost_index += 1;
32 let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
33 ost.set_parameters(ist.parameters());
34 // We need to set codec_tag to 0 lest we run into incompatible codec tag
35 // issues when muxing into a different container format. Unfortunately
36 // there's no high level API to do this (yet).
37 unsafe {
38 (*ost.parameters().as_mut_ptr()).codec_tag = 0;
39 }
40 }
41
42 octx.set_metadata(ictx.metadata().to_owned());
43 octx.write_header().unwrap();
44
45 for (stream, mut packet) in ictx.packets() {
46 let ist_index = stream.index();
47 let ost_index = stream_mapping[ist_index];
48 if ost_index < 0 {
49 continue;
50 }
51 let ost = octx.stream(ost_index as _).unwrap();
52 packet.rescale_ts(ist_time_bases[ist_index], ost.time_base());
53 packet.set_position(-1);
54 packet.set_stream(ost_index as _);
55 packet.write_interleaved(&mut octx).unwrap();
56 }
57
58 octx.write_trailer().unwrap();
59}
More examples
examples/transcode-x264.rs (line 230)
169fn main() {
170 let input_file = env::args().nth(1).expect("missing input file");
171 let output_file = env::args().nth(2).expect("missing output file");
172 let x264_opts = parse_opts(
173 env::args()
174 .nth(3)
175 .unwrap_or_else(|| DEFAULT_X264_OPTS.to_string()),
176 )
177 .expect("invalid x264 options string");
178
179 eprintln!("x264 options: {:?}", x264_opts);
180
181 ffmpeg::init().unwrap();
182 log::set_level(log::Level::Info);
183
184 let mut ictx = format::input(&input_file).unwrap();
185 let mut octx = format::output(&output_file).unwrap();
186
187 format::context::input::dump(&ictx, 0, Some(&input_file));
188
189 let best_video_stream_index = ictx
190 .streams()
191 .best(media::Type::Video)
192 .map(|stream| stream.index());
193 let mut stream_mapping: Vec<isize> = vec![0; ictx.nb_streams() as _];
194 let mut ist_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
195 let mut ost_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
196 let mut transcoders = HashMap::new();
197 let mut ost_index = 0;
198 for (ist_index, ist) in ictx.streams().enumerate() {
199 let ist_medium = ist.parameters().medium();
200 if ist_medium != media::Type::Audio
201 && ist_medium != media::Type::Video
202 && ist_medium != media::Type::Subtitle
203 {
204 stream_mapping[ist_index] = -1;
205 continue;
206 }
207 stream_mapping[ist_index] = ost_index;
208 ist_time_bases[ist_index] = ist.time_base();
209 if ist_medium == media::Type::Video {
210 // Initialize transcoder for video stream.
211 transcoders.insert(
212 ist_index,
213 Transcoder::new(
214 &ist,
215 &mut octx,
216 ost_index as _,
217 x264_opts.to_owned(),
218 Some(ist_index) == best_video_stream_index,
219 )
220 .unwrap(),
221 );
222 } else {
223 // Set up for stream copy for non-video stream.
224 let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
225 ost.set_parameters(ist.parameters());
226 // We need to set codec_tag to 0 lest we run into incompatible codec tag
227 // issues when muxing into a different container format. Unfortunately
228 // there's no high level API to do this (yet).
229 unsafe {
230 (*ost.parameters().as_mut_ptr()).codec_tag = 0;
231 }
232 }
233 ost_index += 1;
234 }
235
236 octx.set_metadata(ictx.metadata().to_owned());
237 format::context::output::dump(&octx, 0, Some(&output_file));
238 octx.write_header().unwrap();
239
240 for (ost_index, _) in octx.streams().enumerate() {
241 ost_time_bases[ost_index] = octx.stream(ost_index as _).unwrap().time_base();
242 }
243
244 for (stream, mut packet) in ictx.packets() {
245 let ist_index = stream.index();
246 let ost_index = stream_mapping[ist_index];
247 if ost_index < 0 {
248 continue;
249 }
250 let ost_time_base = ost_time_bases[ost_index as usize];
251 match transcoders.get_mut(&ist_index) {
252 Some(transcoder) => {
253 transcoder.send_packet_to_decoder(&packet);
254 transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
255 }
256 None => {
257 // Do stream copy on non-video streams.
258 packet.rescale_ts(ist_time_bases[ist_index], ost_time_base);
259 packet.set_position(-1);
260 packet.set_stream(ost_index as _);
261 packet.write_interleaved(&mut octx).unwrap();
262 }
263 }
264 }
265
266 // Flush encoders and decoders.
267 for (ost_index, transcoder) in transcoders.iter_mut() {
268 let ost_time_base = ost_time_bases[*ost_index];
269 transcoder.send_eof_to_decoder();
270 transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
271 transcoder.send_eof_to_encoder();
272 transcoder.receive_and_process_encoded_packets(&mut octx, ost_time_base);
273 }
274
275 octx.write_trailer().unwrap();
276}
Source§impl Parameters
impl Parameters
pub fn new() -> Self
Sourcepub fn medium(&self) -> Type
pub fn medium(&self) -> Type
Examples found in repository?
examples/remux.rs (line 21)
7fn main() {
8 let input_file = env::args().nth(1).expect("missing input file");
9 let output_file = env::args().nth(2).expect("missing output file");
10
11 ffmpeg::init().unwrap();
12 log::set_level(log::Level::Warning);
13
14 let mut ictx = format::input(&input_file).unwrap();
15 let mut octx = format::output(&output_file).unwrap();
16
17 let mut stream_mapping = vec![0; ictx.nb_streams() as _];
18 let mut ist_time_bases = vec![Rational(0, 1); ictx.nb_streams() as _];
19 let mut ost_index = 0;
20 for (ist_index, ist) in ictx.streams().enumerate() {
21 let ist_medium = ist.parameters().medium();
22 if ist_medium != media::Type::Audio
23 && ist_medium != media::Type::Video
24 && ist_medium != media::Type::Subtitle
25 {
26 stream_mapping[ist_index] = -1;
27 continue;
28 }
29 stream_mapping[ist_index] = ost_index;
30 ist_time_bases[ist_index] = ist.time_base();
31 ost_index += 1;
32 let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
33 ost.set_parameters(ist.parameters());
34 // We need to set codec_tag to 0 lest we run into incompatible codec tag
35 // issues when muxing into a different container format. Unfortunately
36 // there's no high level API to do this (yet).
37 unsafe {
38 (*ost.parameters().as_mut_ptr()).codec_tag = 0;
39 }
40 }
41
42 octx.set_metadata(ictx.metadata().to_owned());
43 octx.write_header().unwrap();
44
45 for (stream, mut packet) in ictx.packets() {
46 let ist_index = stream.index();
47 let ost_index = stream_mapping[ist_index];
48 if ost_index < 0 {
49 continue;
50 }
51 let ost = octx.stream(ost_index as _).unwrap();
52 packet.rescale_ts(ist_time_bases[ist_index], ost.time_base());
53 packet.set_position(-1);
54 packet.set_stream(ost_index as _);
55 packet.write_interleaved(&mut octx).unwrap();
56 }
57
58 octx.write_trailer().unwrap();
59}
More examples
examples/transcode-x264.rs (line 199)
169fn main() {
170 let input_file = env::args().nth(1).expect("missing input file");
171 let output_file = env::args().nth(2).expect("missing output file");
172 let x264_opts = parse_opts(
173 env::args()
174 .nth(3)
175 .unwrap_or_else(|| DEFAULT_X264_OPTS.to_string()),
176 )
177 .expect("invalid x264 options string");
178
179 eprintln!("x264 options: {:?}", x264_opts);
180
181 ffmpeg::init().unwrap();
182 log::set_level(log::Level::Info);
183
184 let mut ictx = format::input(&input_file).unwrap();
185 let mut octx = format::output(&output_file).unwrap();
186
187 format::context::input::dump(&ictx, 0, Some(&input_file));
188
189 let best_video_stream_index = ictx
190 .streams()
191 .best(media::Type::Video)
192 .map(|stream| stream.index());
193 let mut stream_mapping: Vec<isize> = vec![0; ictx.nb_streams() as _];
194 let mut ist_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
195 let mut ost_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
196 let mut transcoders = HashMap::new();
197 let mut ost_index = 0;
198 for (ist_index, ist) in ictx.streams().enumerate() {
199 let ist_medium = ist.parameters().medium();
200 if ist_medium != media::Type::Audio
201 && ist_medium != media::Type::Video
202 && ist_medium != media::Type::Subtitle
203 {
204 stream_mapping[ist_index] = -1;
205 continue;
206 }
207 stream_mapping[ist_index] = ost_index;
208 ist_time_bases[ist_index] = ist.time_base();
209 if ist_medium == media::Type::Video {
210 // Initialize transcoder for video stream.
211 transcoders.insert(
212 ist_index,
213 Transcoder::new(
214 &ist,
215 &mut octx,
216 ost_index as _,
217 x264_opts.to_owned(),
218 Some(ist_index) == best_video_stream_index,
219 )
220 .unwrap(),
221 );
222 } else {
223 // Set up for stream copy for non-video stream.
224 let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
225 ost.set_parameters(ist.parameters());
226 // We need to set codec_tag to 0 lest we run into incompatible codec tag
227 // issues when muxing into a different container format. Unfortunately
228 // there's no high level API to do this (yet).
229 unsafe {
230 (*ost.parameters().as_mut_ptr()).codec_tag = 0;
231 }
232 }
233 ost_index += 1;
234 }
235
236 octx.set_metadata(ictx.metadata().to_owned());
237 format::context::output::dump(&octx, 0, Some(&output_file));
238 octx.write_header().unwrap();
239
240 for (ost_index, _) in octx.streams().enumerate() {
241 ost_time_bases[ost_index] = octx.stream(ost_index as _).unwrap().time_base();
242 }
243
244 for (stream, mut packet) in ictx.packets() {
245 let ist_index = stream.index();
246 let ost_index = stream_mapping[ist_index];
247 if ost_index < 0 {
248 continue;
249 }
250 let ost_time_base = ost_time_bases[ost_index as usize];
251 match transcoders.get_mut(&ist_index) {
252 Some(transcoder) => {
253 transcoder.send_packet_to_decoder(&packet);
254 transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
255 }
256 None => {
257 // Do stream copy on non-video streams.
258 packet.rescale_ts(ist_time_bases[ist_index], ost_time_base);
259 packet.set_position(-1);
260 packet.set_stream(ost_index as _);
261 packet.write_interleaved(&mut octx).unwrap();
262 }
263 }
264 }
265
266 // Flush encoders and decoders.
267 for (ost_index, transcoder) in transcoders.iter_mut() {
268 let ost_time_base = ost_time_bases[*ost_index];
269 transcoder.send_eof_to_decoder();
270 transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
271 transcoder.send_eof_to_encoder();
272 transcoder.receive_and_process_encoded_packets(&mut octx, ost_time_base);
273 }
274
275 octx.write_trailer().unwrap();
276}
pub fn id(&self) -> Id
Trait Implementations§
Source§impl Clone for Parameters
impl Clone for Parameters
Source§impl Default for Parameters
impl Default for Parameters
Source§impl Drop for Parameters
impl Drop for Parameters
Source§impl<C: AsRef<Context>> From<C> for Parameters
impl<C: AsRef<Context>> From<C> for Parameters
Source§fn from(context: C) -> Parameters
fn from(context: C) -> Parameters
Converts to this type from the input type.
impl Send for Parameters
Auto Trait Implementations§
impl Freeze for Parameters
impl !RefUnwindSafe for Parameters
impl !Sync for Parameters
impl Unpin for Parameters
impl !UnwindSafe for Parameters
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more