/usr/share/doc/ruby-gstreamer/examples/framestep1.rb is in ruby-gstreamer 2.2.5-4build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | #!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# This sample code is a port of
# gstreamer/tests/examples/stepping/framestep1.c. It is licensed
# under the terms of the GNU Library General Public License, version
# 2 or (at your option) later.
#
# Copyright (C) 2013 Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
require "gst"
def event_loop(pipe)
running = true
bus = pipe.bus
while running
message = bus.timed_pop_filtered(Gst::CLOCK_TIME_NONE, Gst::MessageType::ANY)
raise "message nil" if message.nil?
case message.type
when Gst::MessageType::EOS
puts "got EOS"
running = false
when Gst::MessageType::WARNING
warning, debug = message.parse_warning
puts "Debugging info: #{debug || 'none'}"
puts "Warning: #{warning.message}"
when Gst::MessageType::ERROR
error, debug = message.parse_error
puts "Debugging info: #{debug || 'none'}"
puts "Error: #{error.message}"
running = false
when Gst::MessageType::STEP_DONE
format, amount, rate, flush, intermediate, duration, eos =
message.parse_step_done
if format == Gst::Format::DEFAULT
puts "step done: #{gst_time(duration)} skipped in #{gst_time(amount)} frames"
else
puts "step done: #{gst_time(duration)} skipped"
end
running = false
end
end
end
def gst_time(time)
Time.at(time / 1000000000.0).utc.strftime("%H:%M:%S.%N")
end
# create a new bin to hold the elements
bin = Gst::Pipeline.new("pipeline")
raise "'pipeline' gstreamer plugin missing" if bin.nil?
# create a fake source
videotestsrc = Gst::ElementFactory.make("videotestsrc", "videotestsrc")
raise "'videotestsrc' gstreamer plugin missing" if videotestsrc.nil?
videotestsrc.num_buffers = 10
# and a fake sink
appsink = Gst::ElementFactory.make("appsink", "appsink")
raise "'appsink' gstreamer plugin missing" if appsink.nil?
appsink.emit_signals = true
appsink.sync = true
appsink.signal_connect("new-preroll") do |appsink|
# signalled when a new preroll buffer is available
sample = appsink.pull_preroll
puts "have new-preroll sample #{sample}, timestamp #{gst_time(sample.buffer.pts)}"
Gst::FlowReturn::OK
end
# add objects to the main pipeline
bin << videotestsrc << appsink
# link the elements
videotestsrc >> appsink
# go to the PAUSED state and wait for preroll
puts "prerolling first frame"
bin.pause
bin.get_state(Gst::CLOCK_TIME_NONE)
# step two frames, flush so that new preroll is queued
puts "stepping three frames"
unless bin.send_event(Gst::Event.new(Gst::Format::BUFFERS, 2, 1.0, true, false))
raise "Failed to send STEP event!"
end
# blocks and returns when we received the step done message
event_loop(bin)
# wait for step to really complete
bin.get_state(Gst::CLOCK_TIME_NONE)
result, pos = bin.query_position(Gst::Format::TIME)
puts "stepped two frames, now at #{gst_time(pos)}"
# step 3 frames, flush so that new preroll is queued
puts "stepping 120 milliseconds"
unless bin.send_event(Gst::Event.new(Gst::Format::TIME, 120 * Gst::MSECOND, 1.0,
true, false))
raise "Failed to send STEP event!"
end
# blocks and returns when we received the step done message
event_loop(bin)
# wait for step to really complete
bin.get_state(Gst::CLOCK_TIME_NONE)
result, pos = bin.query_position(Gst::Format::TIME)
puts "stepped 120ms frames, now at #{gst_time(pos)}"
puts "playing until EOS"
bin.play
# Run event loop listening for bus messages until EOS or ERROR
event_loop(bin)
puts "finished"
# stop the bin
bin.stop
|