splitmuxsink - robust to unexpected shutdowns

jcbrock jcbrockschmidt at gmail.com
Wed Oct 7 04:12:29 UTC 2020


I kind of got it working. I couldn't get gst-launch to behave so I decided to
jump straight to implementation. Adding a custom muxer with
"reserved-max-duration" and "reserved-moov-update-period" did the trick.
Here's a snippet of Rust code:


const VIDEO_PATH: &str = "split%02d.mp4";
const MAX_SIZE_TIME_SEC: u64 = 35;

fn create_pipeline(device: &String) -> Result<gst::Pipeline, ()> {
    let pipeline = gst::Pipeline::new(None);
    let src = gst::ElementFactory::make("v4l2src", None).unwrap();
    let scale = gst::ElementFactory::make("videoscale", None).unwrap();
    let filter = gst::ElementFactory::make("capsfilter", None).unwrap();
    let conv = gst::ElementFactory::make("videoconvert", None).unwrap();
    let queue = gst::ElementFactory::make("queue", None).unwrap();
    let enc = gst::ElementFactory::make("x264enc", None).unwrap();
    let parse = gst::ElementFactory::make("h264parse", None).unwrap();
    let sink = gst::ElementFactory::make("splitmuxsink", None).unwrap();

    let video_caps =
        gst::Caps::new_simple("video/x-raw", &[("width", &1920i32),
("height", &1080i32)]);

    let max_time_ns = MAX_SIZE_TIME_SEC * 1_000_000_000;
    let mux = gst::ElementFactory::make("mp4mux", None).unwrap();
    mux.set_property("reserved-max-duration", &max_time_ns.to_value())
        .unwrap();
    mux.set_property("reserved-moov-update-period",
&1000000000u64.to_value())
        .unwrap();

    src.set_property_from_str("device", device);
    filter.set_property("caps", &video_caps.to_value()).unwrap();
    enc.set_property_from_str("speed-preset", "ultrafast");
    enc.set_property_from_str("tune", "zerolatency");
    sink.set_property("max-size-time", &max_time_ns.to_value())
        .unwrap();
    mux.set_property("use-robust-muxing", &true);
    sink.set_property_from_str("location", VIDEO_PATH);
    sink.set_property("muxer", &mux).unwrap();

    // Build the pipeline
    let elems = [&src, &scale, &filter, &conv, &queue, &enc, &parse, &sink];
    pipeline.add_many(&elems).unwrap();
    gst::Element::link_many(&elems).unwrap();

    return Ok(pipeline);
}


Killing the process doesn't disrupt the video outputs. However, the length
of the videos are always on 10-second intervals. If the MAX_SIZE_TIME_SEC is
60, videos will be of length 50. If MAX_SIZE_TIME_SEC is length 65, videos
will be of length 65. There doesn't appear to be any frames getting skipped,
however, and experiments with gst-launch-1.0 pipelines with splitmuxsink
have the same behavior. So it's likely nothing to worry about.

If I'm still doing something wrong that someone notices, of course, please
let me know.



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list