<commit_before>from .encoders import make_encoder

from gi.repository import Gst

container_registry = {}

def make_pipe(config, name):
	format_info = config['formats'][name]
	container_info = config['containers'][format_info['container']]
	muxer = container_registry[container_info['format']]()
	aenc = make_encoder(container_info['audio'])
	venc = make_encoder(container_info['video'])

	if 'abr' in format_info:
		aenc.set_property('bitrate', format_info['abr'])
	if 'vbr' in format_info:
		venc.set_property('bitrate', format_info['vbr'])

	pipe = Pipe()
	if aenc:
		pipe.set_audio_encoder(aenc)
	if venc:
		pipe.set_video_encoder(venc)
	pipe.set_muxer(muxer)
	pipe.finalize()
	return pipe

class Pipe(Gst.Bin):
	def __init__(self):
		super(Pipe, self).__init__()
		self.venc = None
		self.aenc = None
		self.muxer = None

	def set_audio_encoder(self, aenc):
		self.aenc = aenc
		self.add(aenc)
		self.add_pad(Gst.GhostPad.new('audio', aenc.get_static_pad('sink')))

	def set_video_encoder(self, venc):
		self.venc = venc
		self.add(venc)
		self.add_pad(Gst.GhostPad.new('video', venc.get_static_pad('sink')))

	def set_muxer(self, muxer):
		self.muxer = muxer
		self.add(muxer)
		self.add_pad(Gst.GhostPad.new('src', muxer.get_static_pad('src')))

	def finalize(self):
		if not self.aenc:
			self.set_audio_encoder(Gst.ElementFactory.make('queue', 'paoqueue'))
		self.aenc.link(self.muxer)

		if not self.venc:
			self.set_video_encoder(Gst.ElementFactory.make('queue', 'pvoqueue'))
		self.venc.link(self.muxer)

def flv_make():
	flvmux = Gst.ElementFactory.make('flvmux', None)
	flvmux.set_property('streamable', True)
	return flvmux

def mkv_make():
	return Gst.ElementFactory.make('matroskamux', None)

container_registry['flv'] = flv_make
container_registry['mkv'] = mkv_make<commit_msg>Mark MKV muxing as streamable<commit_after>from .encoders import make_encoder

from gi.repository import Gst

container_registry = {}

def make_pipe(config, name):
	format_info = config['formats'][name]
	container_info = config['containers'][format_info['container']]
	muxer = container_registry[container_info['format']]()
	aenc = make_encoder(container_info['audio'])
	venc = make_encoder(container_info['video'])

	if 'abr' in format_info:
		aenc.set_property('bitrate', format_info['abr'])
	if 'vbr' in format_info:
		venc.set_property('bitrate', format_info['vbr'])

	pipe = Pipe()
	if aenc:
		pipe.set_audio_encoder(aenc)
	if venc:
		pipe.set_video_encoder(venc)
	pipe.set_muxer(muxer)
	pipe.finalize()
	return pipe

class Pipe(Gst.Bin):
	def __init__(self):
		super(Pipe, self).__init__()
		self.venc = None
		self.aenc = None
		self.muxer = None

	def set_audio_encoder(self, aenc):
		self.aenc = aenc
		self.add(aenc)
		self.add_pad(Gst.GhostPad.new('audio', aenc.get_static_pad('sink')))

	def set_video_encoder(self, venc):
		self.venc = venc
		self.add(venc)
		self.add_pad(Gst.GhostPad.new('video', venc.get_static_pad('sink')))

	def set_muxer(self, muxer):
		self.muxer = muxer
		self.add(muxer)
		self.add_pad(Gst.GhostPad.new('src', muxer.get_static_pad('src')))

	def finalize(self):
		if not self.aenc:
			self.set_audio_encoder(Gst.ElementFactory.make('queue', 'paoqueue'))
		self.aenc.link(self.muxer)

		if not self.venc:
			self.set_video_encoder(Gst.ElementFactory.make('queue', 'pvoqueue'))
		self.venc.link(self.muxer)

def flv_make():
	flvmux = Gst.ElementFactory.make('flvmux', None)
	flvmux.set_property('streamable', True)
	return flvmux

def mkv_make():
	mkvmux = Gst.ElementFactory.make('matroskamux', None)
	mkvmux.set_property('streamable', True)
	return mkvmux

container_registry['flv'] = flv_make
container_registry['mkv'] = mkv_make
{'fraction_non_alphanumeric': 0.14648117839607203, 'fraction_numerical': 0.0, 'mean_word_length': 5.77818853974122, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6114390', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1452, 'n_words': 235}