Encodebin problem
narcisse doudieu siewe
wambenarcisse at yahoo.fr
Sat Sep 14 22:18:43 PDT 2013
Hi,
could you explain me how encodebin work?? I have a pipeline like:
filesrc-->decodebin->encodebin->filesink the video stream should be past-throught an progressreport element
but this pipeline could not work. my code: is a python code
import gi
gi.require_version('Gst', '1.0')
gi.require_version('Gtk', '3.0')
gi.require_version('GLib', '2.0')
gi.require_version('Gio', '2.0')
gi.require_version('GstPbutils', '1.0')
from gi.repository import Gst, Gtk, GLib, Gdk, GdkPixbuf, GstPbutils, GObject, Gio
from gi.repository.Gtk import *
from gi.repository.GLib import *
import time
import Utilities
def job_clear_onclick(button, tree):
store = tree.get_model()
l_ = len(store)
if l_ == 0:
return
i = 0
it = store.get_iter_first()
while( i < l_ ):
if it == None:
return
test = store[i][1]
if test == True:
store.remove(it)
l_ = len(store)
else:
i+=1
it = store.iter_next(it)
class Job:
def __init__(self, win):
self.audio_pad_num = 0
self.video_pad_num = 0
self.mpeg_version = GObject.Value()
self.mpeg_version.init(int)
self.mpeg_version.set_int(4)
self.win = win
self.tree_view = win.tree_view
self.tree = self.tree_view.get_model()
self.file_pos = 0 #current file processed by the applicaion
self.it = None # point to the current row
self.title = None
self.path = None
self.busy = False
self.folder = None
self.count = 0
self.stop = False
#sets encode bin profile
self.caps = Gst.Caps.from_string("video/w-msvideo")
self.container = GstPbutils.EncodingContainerProfile.new("AVI_CONVERTER", "AVI_PROFILE", self.caps, None)
#sets audio profile
self.caps_audio = Gst.Caps.from_string("audio/mpeg")
#self.caps_audio.set_value("mpegversion", self.mpeg_version)
self.audio_profile = GstPbutils.EncodingAudioProfile.new(self.caps_audio, None, None, 0)
#sets video profile
self.caps_video = Gst.Caps.from_string("video/mpeg")
#self.caps_video.set_value("mpegversion", self.mpeg_version)
self.video_profile = GstPbutils.EncodingVideoProfile.new(self.caps_video, None, None, 0)
#add stream pipeline for the converter
self.container.add_profile(self.video_profile)
self.container.add_profile(self.audio_profile)
self.pipe = Gst.Pipeline()#self.win.pipe
self.pipe.set_name("pipe1")
self.src = Gst.ElementFactory.make("filesrc", "src")
self.decode = Gst.ElementFactory.make("decodebin", "decode")
self.videoconvert = Gst.ElementFactory.make("videoconvert", "videoconvert")
self.audioconvert = Gst.ElementFactory.make("audioconvert", "audioconvert")
self.decode.connect("pad-added", self.pad_added_on_decode)
self.decode.connect("unknown-type", self.unknown)
#sets encoding profile for the encoder
self.encode = Gst.ElementFactory.make("encodebin", "encode")
self.sink = Gst.ElementFactory.make("filesink", "sink")
self.progress = Gst.ElementFactory.make("progressreport", "progress")
self.pipe.add(self.src)
self.pipe.add(self.progress)
self.pipe.add(self.decode)
self.play = Gst.ElementFactory.make("playbin", "play")
self.pipe.add(self.play)
#self.pipe.add(self.videoconvert)
#self.pipe.add(self.audioconvert)
#self.progress.set_property("silent", False)
#self.progress.set_property("update-freq", 3)
self.pipe.add(self.encode)
#self.vid = Gst.ElementFactory.make("autovideosink", "vid")
#self.pipe.add(self.vid)
#self.aud = Gst.ElementFactory.make("autoaudiosink", "aud")
#self.pipe.add(self.aud)
#self.pipe.add(self.sink)
self.encode.set_property("profile", self.container)
self.src.link(self.decode)
#self.progress.link(self.decode)
#self.videoconvert.link(self.progress)
self.encode.link(self.play)
self.bus = self.pipe.get_bus()
self.bus.add_signal_watch()
self.bus.connect("message", self.watch_on_bus)
self.dialog_info = Gtk.MessageDialog(self.win, Gtk.MessageType.INFO, Gtk.DialogFlags.MODAL, Gtk.ButtonsType.OK, "Des elements sont en cours de traitement")
self.dialog_info.format_secondary_text("Veuillez attendre")
#query name
self.format_name = Gst.Format.PERCENT.value_name
self.progress.set_property("format", self.format_name)
def watch_on_bus(self, bus, msg):
print("donne meme non l ami\n")
self.count +=1
if msg.type == Gst.MessageType.EOS:
self.pipe.set_state(Gst.State.NULL)
self.pipe.get_state(1000000000)
self.it = self.tree.iter_next(self.it)
if self.it == None and self.tree.get_iter_first() != None:
self.win.add_movie.unset_state_flags(Gtk.StateFlags.INSENSITIVE)
self.win.clear_movie.unset_state_flags(Gtk.StateFlags.INSENSITIVE)
self.count = 0
self.busy = False
return
self.path, self.title = self.tree[self.it][4], self.tree[self.it][2]
self.src.set_property("location", self.path)
title = self.title.split(".avi")[0]
dst_file = self.folder+"/"+title+".avi"
print(dst_file+"\n")
print(title+"\n")
print(self.path+"\n")
self.sink.set_property("location", dst_file)
self.pipe.set_state(Gst.State.PLAYING)
self.pipe.get_state(1000000000)
if (msg.src.get_name() == "progress"):
if msg.get_structure().get_name() == "progress":
print("ici c est ok\n")
print("la aussi c est ok")
perc = msg.get_structure().get_int("percent")[1]
self.tree[self.it][3] = perc
def unknown(self, decode, caps):
print("unknown type\n")
def pad_added_on_decode(self, decod, new_pad):
print("salu salu salu\n")
caps_repr = new_pad.query_caps(None).to_string()
print(caps_repr)
if caps_repr.startswith("video"):
print("ambiance aussi\n")
pad_sink = self.videoconvert.get_static_pad("sink")
pad_src = self.videoconvert.get_static_pad("src")
#pad_sink = self.videoconvert.get_static_pad("sink")
#pad_src = self.videoconvert.get_static_pad("src")
pad1 = self.encode.get_compatible_pad(new_pad, None)
#pad_prog_src = self.progress.get_static_pad("src")
if pad1.is_linked() == True:
return
if pad1 == None:
pad1 = self.encode.get_request_pad("video_"+str(self.video_pad_num))
self.video_pad_num +=1
new_pad.link(pad_sink)
pad_src.link(pad1)
#pad_prog_src.link(pad1)
#if caps_repr.startswith("audio"):
# print("ambiance aussi\n")
# pad_sink = self.aud.get_static_pad("sink")
# new_pad.link(pad_sink)
if caps_repr.startswith("audio"):
print("test3\n")
#pad_sink = self.audioconvert.get_static_pad("sink")
#pad_src = self.audioconvert.get_static_pad("src")
pad1 = self.encode.get_compatible_pad(new_pad, None)
if pad1.is_linked() == True:
return
if pad1 == None:
pad1 = self.encode.get_request_pad("audio_"+str(self.audio_pad_num))
self.audio_pad_num +=1
new_pad.link(pad1)
#pad_src.link(pad1)
print("test4\n")
def job_stop_onclick(self, but):
if self.win.choice == 0 and self.stop == False:
self.pipe.set_state(Gst.State.NULL)
self.pipe.get_state(1000000000)
if self.win.clear_movie.get_state_flags() == Gtk.StateFlags.INSENSITIVE:
self.win.clear_movie.unset_state_flags(Gtk.StateFlags.INSENSITIVE)
self.win.add_movie.unset_state_flags(Gtk.StateFlags.INSENSITIVE)
self.stop = True
self.busy = False
def job_convert_onclick(self, but):
if self.busy == True:
self.dialog_info.run()
self.dialog_info.hide()
return
self.it = self.tree.get_iter_first()
if self.it == None:
return
self.win.choice = 0
self.stop = False
self.win.add_movie.set_state_flags(Gtk.StateFlags.INSENSITIVE, True)
self.win.clear_movie.set_state_flags(Gtk.StateFlags.INSENSITIVE, True)
self.busy = True
self.video_pad_num = 0
self.audio_pad_num = 0
self.win.cell_rend3.set_property("visible", True)
self.title, self.path = self.tree[self.it][2], self.tree[self.it][4]
self.src.set_property("location", self.path)
print(self.path)
title = self.title.split(".avi")[0]
dst_file = self.folder+"/"+title+".avi"
self.sink.set_property("location", dst_file)
self.pipe.set_state(Gst.State.PLAYING)
self.pipe.get_state(1000000000)
print("looooool\n")
def containerprofile_set( container_profile, name_, description_, format_, preset_):
container_profile.set_name(name_)
container_profile.set_description(description_)
container_profile.set_format(format_)
container_profile.set_preset(preset_)
def audio_video_profile_set(audio_video, format_, preset_, restriction_, presence_):
audio_video.set_format(format_)
audio_video.set_preset(preset_)
audio_video.set_restriction(restriction_)
audio_video.set_presence(presence_)
could I directly link decodebin and encodebin toghether or I need some element?? thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20130915/1cf96b36/attachment-0001.html>
More information about the gstreamer-devel
mailing list