How to create video thumbnails with Python and Gstreamer

前端 未结 4 692
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 03:15

I\'d like to create thumbnails for MPEG-4 AVC videos using Gstreamer and Python. Essentially:

  1. Open the video file
  2. Seek to a certain point in time (e.g
4条回答
  •  一向
    一向 (楼主)
    2020-12-19 03:58

    An example in Vala, with GStreamer 1.0 :

    var playbin = Gst.ElementFactory.make ("playbin", null);
    playbin.set ("uri", "file:///path/to/file");
    // some code here.
    var caps = Gst.Caps.from_string("image/png");
    Gst.Sample sample;
    Signal.emit_by_name(playbin, "convert-sample", caps, out sample);
    if(sample == null)
        return;
    var sample_caps = sample.get_caps ();
    if(sample_caps == null)
        return;
    unowned Gst.Structure structure = sample_caps.get_structure(0);
    int width = (int)structure.get_value ("width");
    int height = (int)structure.get_value ("height");
    var memory = sample.get_buffer().get_memory (0);
    Gst.MapInfo info;
    memory.map (out info, Gst.MapFlags.READ);
    uint8[] data = info.data;
    

提交回复
热议问题