2020-05-13 17:13:28 +00:00
|
|
|
// Copyright (C) 2020 Natanael Mojica <neithanmo@gmail.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
2022-01-15 19:18:47 +00:00
|
|
|
//
|
2022-03-14 08:22:53 +00:00
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
2020-05-13 17:13:28 +00:00
|
|
|
|
|
|
|
use gst::prelude::*;
|
|
|
|
|
2021-06-04 17:06:24 +00:00
|
|
|
const ENCODE_PIPELINE: &str = "videotestsrc is-live=false num-buffers=1 ! videoconvert ! video/x-raw, format=RGB, width=160, height=120 !
|
2020-05-13 17:13:28 +00:00
|
|
|
rspngenc compression-level=2 filter=4 ! filesink location=frame.png";
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
gstrspng::plugin_register_static().expect("Failed to register gif plugin");
|
|
|
|
|
2023-12-04 14:54:00 +00:00
|
|
|
let pipeline = gst::parse::launch(ENCODE_PIPELINE).unwrap();
|
2021-04-12 12:49:54 +00:00
|
|
|
let bus = pipeline.bus().unwrap();
|
2020-05-13 17:13:28 +00:00
|
|
|
|
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Playing)
|
|
|
|
.expect("Failed to set pipeline state to playing");
|
|
|
|
|
2021-06-04 17:06:24 +00:00
|
|
|
for msg in bus.iter_timed(gst::ClockTime::NONE) {
|
2020-05-13 17:13:28 +00:00
|
|
|
use gst::MessageView;
|
|
|
|
|
|
|
|
match msg.view() {
|
|
|
|
MessageView::Eos(..) => break,
|
|
|
|
MessageView::Error(err) => {
|
|
|
|
println!(
|
|
|
|
"Error from {:?}: {} ({:?})",
|
2021-04-12 12:49:54 +00:00
|
|
|
err.src().map(|s| s.path_string()),
|
|
|
|
err.error(),
|
|
|
|
err.debug()
|
2020-05-13 17:13:28 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Null)
|
|
|
|
.expect("Failed to set pipeline state to null");
|
|
|
|
}
|