def main(): input = HTTPSInput(name='Demo HTTPS input', host=HTTPS_INPUT_HOST) input = bitmovin.inputs.HTTPS.create(input).resource output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Demo S3 Output') output = bitmovin.outputs.S3.create(output).resource encoding = Encoding(name='Python Example - Create AV1 Encoding', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource video_input_stream = StreamInput(input_id=input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_codec_configuration = OpusCodecConfiguration(name='Demo Opus Codec Configuration', bitrate=audio_bitrate, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.OPUS.create(audio_codec_configuration).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Demo Audio Stream') audio_stream = bitmovin.encodings.Stream.create(object_=audio_stream, encoding_id=encoding.id).resource for profile in encoding_profiles: video_codec_configuration = AV1CodecConfiguration( name='Demo AV1 Codec Configuration {}p @ {}bps'.format(profile['height'], profile['bitrate']), bitrate=profile['bitrate'], rate=profile['fps'], width=None, height=profile['height'] ) video_codec_configuration = bitmovin.codecConfigurations.AV1.create(video_codec_configuration).resource video_stream = Stream(codec_configuration_id=video_codec_configuration.id, input_streams=[video_input_stream], name='Demo AV1 Stream {}p @ {}bps'.format(profile['height'], profile['bitrate'])) video_stream = bitmovin.encodings.Stream.create(object_=video_stream, encoding_id=encoding.id).resource create_muxing(encoding, output, video_stream, audio_stream) bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished(encoding_id=encoding.id) except BitmovinError as bitmovin_error: print('Exception occurred while waiting for encoding to finish: {}'.format(bitmovin_error))
def _get_https_input_multiple_audio_tracks_second(self): http_input_settings = self.settings.get('sampleObjects').get('inputs').get('http')\ .get('4fa9fec1-b75e-4e2c-a01b-6e0cb7e3cf3e') input_file = http_input_settings.get('files').get( '7fd49d67-562b-4027-8e94-59b125bb2ef7') self.assertIsNotNone(input_file) https_input = HTTPSInput( host=http_input_settings.get('host'), name='Sample HTTPS input multiple audio tracks 2') return https_input, input_file
def _get_https_input_multiple_audio_tracks(self): http_input_settings = self.settings.get('sampleObjects').get('inputs').get('http')\ .get('4fa9fec1-b75e-4e2c-a01b-6e0cb7e3cf3e') input_file = http_input_settings.get('files').get( '1c08c700-abcb-41f8-9cb7-3387503c1e50') self.assertIsNotNone(input_file) https_input = HTTPSInput( host=http_input_settings.get('host'), name='Sample HTTPS input multiple audio tracks') return https_input, input_file
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(host=HTTPS_INPUT_HOST, name='retrieve_audio_language_from_analysis HTTPS input') https_input = bitmovin.inputs.HTTPS.create(https_input).resource analysis = Analysis(path=HTTPS_INPUT_PATH, cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) analysis_resource = bitmovin.inputs.HTTPS.analyze(input_id=https_input.id, analysis_object=analysis).resource analysis_status = None try: analysis_status = bitmovin.inputs.HTTPS.wait_until_analysis_finished(input_id=https_input.id, analysis_id=analysis_resource.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for analysis to finish: {}".format(bitmovin_error)) sys.exit(100) analysis_details = bitmovin.inputs.HTTPS.retrieve_analysis_details( input_id=https_input.id, analysis_id=analysis_resource.id).resource # type: AnalysisDetails audio_stream_details = analysis_details.audioStreams for analysis_audio_stream in audio_stream_details: print_audio_stream_details(analysis_audio_stream)
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding( name='example hls progressive ts encoding with various id3 tags', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration_480p = H264CodecConfiguration( name='example_video_codec_configuration_480p', bitrate=1200000, height=480, profile=H264Profile.MAIN, rate=None) video_codec_configuration_480p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_480p).resource video_codec_configuration_360p = H264CodecConfiguration( name='example_video_codec_configuration_360p', bitrate=800000, height=360, profile=H264Profile.MAIN, rate=None) video_codec_configuration_360p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_360p).resource audio_codec_configuration = AACCodecConfiguration( name='example_audio_codec_configuration_english', bitrate=128000, rate=44100) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create( audio_codec_configuration).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) video_stream_480p = Stream( codec_configuration_id=video_codec_configuration_480p.id, input_streams=[video_input_stream], name='Sample Stream 480p') video_stream_480p = bitmovin.encodings.Stream.create( object_=video_stream_480p, encoding_id=encoding.id).resource video_stream_360p = Stream( codec_configuration_id=video_codec_configuration_360p.id, input_streams=[video_input_stream], name='Sample Stream 360p') video_stream_360p = bitmovin.encodings.Stream.create( object_=video_stream_360p, encoding_id=encoding.id).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Sample Stream AUDIO') audio_stream = bitmovin.encodings.Stream.create( object_=audio_stream, encoding_id=encoding.id).resource acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) video_muxing_stream_480p = MuxingStream(video_stream_480p.id) video_muxing_stream_360p = MuxingStream(video_stream_360p.id) audio_muxing_stream = MuxingStream(audio_stream.id) muxing_480p_path = '480p' muxing_480p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + muxing_480p_path, acl=[acl_entry]) muxing_480p = ProgressiveTSMuxing( segment_length=4, filename='progressive.ts', streams=[video_muxing_stream_480p, audio_muxing_stream], outputs=[muxing_480p_output], name='Sample Muxing 480p') muxing_480p = bitmovin.encodings.Muxing.ProgressiveTS.create( object_=muxing_480p, encoding_id=encoding.id).resource muxing_360p_path = '360p' muxing_360p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + muxing_360p_path, acl=[acl_entry]) muxing_360p = ProgressiveTSMuxing( segment_length=4, filename='progressive.ts', streams=[video_muxing_stream_360p, audio_muxing_stream], outputs=[muxing_360p_output], name='Sample Muxing 360p') muxing_360p = bitmovin.encodings.Muxing.ProgressiveTS.create( object_=muxing_360p, encoding_id=encoding.id).resource raw_id3_tag_1 = RawID3Tag( position_mode=ID3TagPositionMode.TIME, time=1.0, bytes_=base64.b64encode(b'My awesome Raw ID3 Tag #1').decode('utf-8'), name='Raw ID3 #1', description='Just some descriptive information') raw_id3_tag_2 = RawID3Tag( position_mode=ID3TagPositionMode.TIME, time=2.0, bytes_=base64.b64encode(b'My awesome Raw ID3 Tag #2').decode('utf-8'), name='Raw ID3 #2', description='Just some descriptive information') frame_id_id3_tag_1 = FrameIdID3Tag( position_mode=ID3TagPositionMode.TIME, time=5.12, frame_id='ABCD', bytes_=base64.b64encode(b'My awesome FrameId ID3 Tag #1').decode( 'utf-8'), name='FrameId ID3 #1', description='Just some descriptive information') frame_id_id3_tag_2 = FrameIdID3Tag( position_mode=ID3TagPositionMode.TIME, time=6.3422172, frame_id='EFGH', bytes_=base64.b64encode(b'My awesome FrameId ID3 Tag #2').decode( 'utf-8'), name='FrameId ID3 #2', description='Just some descriptive information') plain_text_id3_tag_1 = PlainTextID3Tag( position_mode=ID3TagPositionMode.TIME, time=8.34, frame_id='IJKL', text='My awesome PlainText ID3 Tag #1', name='PlainText ID3 #1', description='Just some descriptive information') plain_text_id3_tag_2 = PlainTextID3Tag( position_mode=ID3TagPositionMode.TIME, time=9.013, frame_id='MNOP', text='My awesome PlainText ID3 Tag #2', name='PlainText ID3 #2', description='Just some descriptive information') bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.Raw.create( object_=raw_id3_tag_1, encoding_id=encoding.id, muxing_id=muxing_360p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.Raw.create( object_=raw_id3_tag_1, encoding_id=encoding.id, muxing_id=muxing_480p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.Raw.create( object_=raw_id3_tag_2, encoding_id=encoding.id, muxing_id=muxing_360p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.Raw.create( object_=raw_id3_tag_2, encoding_id=encoding.id, muxing_id=muxing_480p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.FrameId.create( object_=frame_id_id3_tag_1, encoding_id=encoding.id, muxing_id=muxing_360p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.FrameId.create( object_=frame_id_id3_tag_1, encoding_id=encoding.id, muxing_id=muxing_480p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.FrameId.create( object_=frame_id_id3_tag_2, encoding_id=encoding.id, muxing_id=muxing_360p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.FrameId.create( object_=frame_id_id3_tag_2, encoding_id=encoding.id, muxing_id=muxing_480p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.PlainText.create( object_=plain_text_id3_tag_1, encoding_id=encoding.id, muxing_id=muxing_360p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.PlainText.create( object_=plain_text_id3_tag_1, encoding_id=encoding.id, muxing_id=muxing_480p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.PlainText.create( object_=plain_text_id3_tag_2, encoding_id=encoding.id, muxing_id=muxing_360p.id) bitmovin.encodings.Muxing.ProgressiveTS.ID3Tags.PlainText.create( object_=plain_text_id3_tag_2, encoding_id=encoding.id, muxing_id=muxing_480p.id) bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) manifest_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) hls_manifest = HlsManifest( manifest_name='master.m3u8', outputs=[manifest_output], name='Sample HLS Manifest - Master - ProgressiveTS+ID3') hls_manifest = bitmovin.manifests.HLS.create(object_=hls_manifest).resource variant_stream_480p = VariantStream( closed_captions='NONE', segment_path='{}/'.format(muxing_480p_path), uri='480p.m3u8', encoding_id=encoding.id, stream_id=video_stream_480p.id, muxing_id=muxing_480p.id) variant_stream_480p = bitmovin.manifests.HLS.VariantStream.create( manifest_id=hls_manifest.id, object_=variant_stream_480p) variant_stream_360p = VariantStream( closed_captions='NONE', segment_path='{}/'.format(muxing_360p_path), uri='360p.m3u8', encoding_id=encoding.id, stream_id=video_stream_360p.id, muxing_id=muxing_360p.id) variant_stream_360p = bitmovin.manifests.HLS.VariantStream.create( manifest_id=hls_manifest.id, object_=variant_stream_360p) bitmovin.manifests.HLS.start(manifest_id=hls_manifest.id) try: bitmovin.manifests.HLS.wait_until_finished(manifest_id=hls_manifest.id) except BitmovinError as bitmovin_error: print( "Exception occurred while waiting for HLS manifest creation to finish: {}" .format(bitmovin_error))
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='example encoding', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration_1080p = H264CodecConfiguration( name='example_video_codec_configuration_1080p', bitrate=4800000, rate=25.0, width=1920, height=1080, profile=H264Profile.HIGH) video_codec_configuration_1080p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_1080p).resource video_codec_configuration_720p = H264CodecConfiguration( name='example_video_codec_configuration_720p', bitrate=2400000, rate=25.0, width=1280, height=720, profile=H264Profile.HIGH) video_codec_configuration_720p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_720p).resource audio_codec_configuration = AACCodecConfiguration( name='example_audio_codec_configuration_english', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create( audio_codec_configuration).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) video_stream_1080p = Stream( codec_configuration_id=video_codec_configuration_1080p.id, input_streams=[video_input_stream], name='Sample Stream 1080p') video_stream_1080p = bitmovin.encodings.Stream.create( object_=video_stream_1080p, encoding_id=encoding.id).resource video_stream_720p = Stream( codec_configuration_id=video_codec_configuration_720p.id, input_streams=[video_input_stream], name='Sample Stream 720p') video_stream_720p = bitmovin.encodings.Stream.create( object_=video_stream_720p, encoding_id=encoding.id).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Sample Stream AUDIO') audio_stream = bitmovin.encodings.Stream.create( object_=audio_stream, encoding_id=encoding.id).resource audio_mix_filter = AudioMixFilter( name="Audio Mix Channel", channel_layout=AudioMixFilterChannelLayout.CL_STEREO) audio_mix_channel_1 = AudioMixChannel( channel_number=0, source_channels=[ AudioMixSourceChannel( channel_number=0, channel_type=AudioMixFilterChannelType.CHANNEL_NUMBER) ]) audio_mix_channel_2 = AudioMixChannel( channel_number=1, source_channels=[ AudioMixSourceChannel( channel_number=1, channel_type=AudioMixFilterChannelType.CHANNEL_NUMBER) ]) audio_mix_filter.audio_mix_channels = [ audio_mix_channel_1, audio_mix_channel_2 ] audio_mix_filter = bitmovin.filters.AudioMix.create( object_=audio_mix_filter).resource stream_filter = [StreamFilter(id=audio_mix_filter.id, position=0)] bitmovin.encodings.Stream.Filter.create(encoding_id=encoding.id, stream_id=audio_stream.id, stream_filter=stream_filter) acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id) video_muxing_stream_720p = MuxingStream(video_stream_720p.id) audio_muxing_stream = MuxingStream(audio_stream.id) video_muxing_1080p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/1080p/', acl=[acl_entry]) video_muxing_1080p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_1080p], outputs=[video_muxing_1080p_output], name='Sample Muxing 1080p') video_muxing_1080p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_1080p, encoding_id=encoding.id).resource video_muxing_720p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/720p/', acl=[acl_entry]) video_muxing_720p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_720p], outputs=[video_muxing_720p_output], name='Sample Muxing 720p') video_muxing_720p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_720p, encoding_id=encoding.id).resource audio_muxing_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'audio/', acl=[acl_entry]) audio_muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[audio_muxing_stream], outputs=[audio_muxing_output], name='Sample Muxing AUDIO') audio_muxing = bitmovin.encodings.Muxing.FMP4.create( object_=audio_muxing, encoding_id=encoding.id).resource bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) manifest_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) dash_manifest = DashManifest( manifest_name='example_manifest_sintel_dash.mpd', outputs=[manifest_output], name='Sample DASH Manifest') dash_manifest = bitmovin.manifests.DASH.create(dash_manifest).resource period = Period() period = bitmovin.manifests.DASH.add_period( object_=period, manifest_id=dash_manifest.id).resource video_adaptation_set = VideoAdaptationSet() video_adaptation_set = bitmovin.manifests.DASH.add_video_adaptation_set( object_=video_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource audio_adaptation_set = AudioAdaptationSet(lang='en') audio_adaptation_set = bitmovin.manifests.DASH.add_audio_adaptation_set( object_=audio_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource fmp4_representation_1080p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_1080p.id, segment_path='video/1080p/') fmp4_representation_1080p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_1080p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_720p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_720p.id, segment_path='video/720p/') fmp4_representation_720p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_720p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_audio = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=audio_muxing.id, segment_path='audio/') fmp4_representation_audio = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_audio, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=audio_adaptation_set.id).resource bitmovin.manifests.DASH.start(manifest_id=dash_manifest.id) try: bitmovin.manifests.DASH.wait_until_finished( manifest_id=dash_manifest.id) except BitmovinError as bitmovin_error: print( "Exception occurred while waiting for manifest creation to finish: {}" .format(bitmovin_error))
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(name='create_simple_encoding_vp9 HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, cloud_region=AWSCloudRegion.US_EAST_1, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='example VP9 encoding', cloud_region=CloudRegion.AWS_US_EAST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration_1080p = VP9CodecConfiguration( name='example_video_codec_configuration_1080p', bitrate=3600000, rate=25.0, width=1920, height=1080) video_codec_configuration_1080p = bitmovin.codecConfigurations.VP9.create( video_codec_configuration_1080p).resource video_codec_configuration_720p = VP9CodecConfiguration( name='example_video_codec_configuration_720p', bitrate=1800000, rate=25.0, width=1280, height=720) video_codec_configuration_720p = bitmovin.codecConfigurations.VP9.create( video_codec_configuration_720p).resource audio_codec_configuration = AACCodecConfiguration( name='example_audio_codec_configuration_english', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create( audio_codec_configuration).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) video_stream_1080p = Stream( codec_configuration_id=video_codec_configuration_1080p.id, input_streams=[video_input_stream], name='Sample Stream 1080p') video_stream_1080p = bitmovin.encodings.Stream.create( object_=video_stream_1080p, encoding_id=encoding.id).resource video_stream_720p = Stream( codec_configuration_id=video_codec_configuration_720p.id, input_streams=[video_input_stream], name='Sample Stream 720p') video_stream_720p = bitmovin.encodings.Stream.create( object_=video_stream_720p, encoding_id=encoding.id).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Sample Stream AUDIO') audio_stream = bitmovin.encodings.Stream.create( object_=audio_stream, encoding_id=encoding.id).resource acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id) video_muxing_stream_720p = MuxingStream(video_stream_720p.id) audio_muxing_stream = MuxingStream(audio_stream.id) video_muxing_1080p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/1080p/', acl=[acl_entry]) video_muxing_1080p = WebMMuxing(segment_length=4, segment_naming='seg_%number%.chk', init_segment_name='init.hdr', streams=[video_muxing_stream_1080p], outputs=[video_muxing_1080p_output], name='Sample Muxing 1080p') video_muxing_1080p = bitmovin.encodings.Muxing.WebM.create( object_=video_muxing_1080p, encoding_id=encoding.id).resource video_muxing_720p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/720p/', acl=[acl_entry]) video_muxing_720p = WebMMuxing(segment_length=4, segment_naming='seg_%number%.chk', init_segment_name='init.hdr', streams=[video_muxing_stream_720p], outputs=[video_muxing_720p_output], name='Sample Muxing 720p') video_muxing_720p = bitmovin.encodings.Muxing.WebM.create( object_=video_muxing_720p, encoding_id=encoding.id).resource audio_muxing_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'audio/', acl=[acl_entry]) audio_muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[audio_muxing_stream], outputs=[audio_muxing_output], name='Sample Muxing AUDIO') audio_muxing = bitmovin.encodings.Muxing.FMP4.create( object_=audio_muxing, encoding_id=encoding.id).resource bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) manifest_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) dash_manifest = DashManifest(manifest_name='example_manifest_vp9.mpd', outputs=[manifest_output], name='Sample DASH Manifest') dash_manifest = bitmovin.manifests.DASH.create(dash_manifest).resource period = Period() period = bitmovin.manifests.DASH.add_period( object_=period, manifest_id=dash_manifest.id).resource video_adaptation_set = VideoAdaptationSet() video_adaptation_set = bitmovin.manifests.DASH.add_video_adaptation_set( object_=video_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource audio_adaptation_set = AudioAdaptationSet(lang='en') audio_adaptation_set = bitmovin.manifests.DASH.add_audio_adaptation_set( object_=audio_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource webm_representation_1080p = WebMRepresentation( type=WebMRepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_1080p.id, segment_path='video/1080p/') webm_representation_1080p = bitmovin.manifests.DASH.add_webm_representation( object_=webm_representation_1080p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource webm_representation_720p = WebMRepresentation( type=WebMRepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_720p.id, segment_path='video/720p/') webm_representation_720p = bitmovin.manifests.DASH.add_webm_representation( object_=webm_representation_720p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_audio = FMP4Representation( type=FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=audio_muxing.id, segment_path='audio/') fmp4_representation_audio = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_audio, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=audio_adaptation_set.id).resource bitmovin.manifests.DASH.start(manifest_id=dash_manifest.id) try: bitmovin.manifests.DASH.wait_until_finished( manifest_id=dash_manifest.id) except BitmovinError as bitmovin_error: print( "Exception occurred while waiting for manifest creation to finish: {}" .format(bitmovin_error))
def main(): bitmovin = Bitmovin(api_key=API_KEY) # Create an HTTPs input. This resource is then used as base URL for the input file. https_input = HTTPSInput(name='HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource # Create an S3 Output. This will be used as target bucket for the muxings, sprites and manifests s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource # Create an Encoding. This will run in AWS_EU_WEST_1. This is the base entity used to configure the encoding. encoding = Encoding(name='HEVC Encoding with Python', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource encoding_configs = [] # Iterate over all encoding profiles and create the H265 configuration with the defined height and bitrate. # If you want to extend the config you have to set the values here as well. for encoding_profile in hevc_encoding_profiles: encoding_config = dict(profile=encoding_profile) codec = H265CodecConfiguration( name='H265 Codec {}p {}k Configuration'.format( encoding_profile.get('height'), encoding_profile.get('bitrate')), bitrate=encoding_profile.get('bitrate') * 1000, height=encoding_profile.get('height'), rate=encoding_profile.get('fps'), profile=encoding_profile.get('profile')) encoding_config['codec'] = bitmovin.codecConfigurations.H265.create( codec).resource encoding_configs.append(encoding_config) # Also the AAC configuration has to be created, which will be later on used to create the streams. audio_codec_configuration = AACCodecConfiguration( name='AAC Codec Configuration', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create( audio_codec_configuration).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) # With the configurations and the input file streams are now created and muxed later on. for encoding_config in encoding_configs: encoding_profile = encoding_config.get('profile') video_stream = Stream( codec_configuration_id=encoding_config.get('codec').id, input_streams=[video_input_stream], name='Stream {}p_{}k'.format(encoding_profile.get('height'), encoding_profile.get('bitrate'))) encoding_config['stream'] = bitmovin.encodings.Stream.create( object_=video_stream, encoding_id=encoding.id).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Audio Stream') audio_stream = bitmovin.encodings.Stream.create( object_=audio_stream, encoding_id=encoding.id).resource acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) # Create FMP4 muxings which are later used for the DASH manifest. The current settings will set a segment length # of 4 seconds. for encoding_config in encoding_configs: encoding_profile = encoding_config.get('profile') video_muxing_stream = MuxingStream(encoding_config.get('stream').id) video_muxing_output = EncodingOutput( output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/{}p_{}k/'.format(encoding_profile.get('height'), encoding_profile.get('bitrate')), acl=[acl_entry]) video_muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream], outputs=[video_muxing_output], name='FMP4 Muxing {}p_{}k'.format( encoding_profile.get('height'), encoding_profile.get('bitrate'))) encoding_config['fmp4_muxing'] = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing, encoding_id=encoding.id).resource audio_muxing_stream = MuxingStream(audio_stream.id) audio_muxing_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'audio/', acl=[acl_entry]) audio_fmp4_muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[audio_muxing_stream], outputs=[audio_muxing_output], name='Audio FMP4 Muxing') audio_fmp4_muxing = bitmovin.encodings.Muxing.FMP4.create( object_=audio_fmp4_muxing, encoding_id=encoding.id).resource bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id, check_interval=5) except BitmovinError as bitmovin_error: print('Exception occurred while waiting for encoding to finish: {}'. format(bitmovin_error)) # Specify the output for manifest which will be in the OUTPUT_BASE_PATH. manifest_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) # Create a DASH manifest and add one period with an adapation set for audio and video dash_manifest = DashManifest(manifest_name='stream.mpd', outputs=[manifest_output], name='DASH Manifest') dash_manifest = bitmovin.manifests.DASH.create(dash_manifest).resource period = Period() period = bitmovin.manifests.DASH.add_period( object_=period, manifest_id=dash_manifest.id).resource video_adaptation_set = VideoAdaptationSet() video_adaptation_set = bitmovin.manifests.DASH.add_video_adaptation_set( object_=video_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource audio_adaptation_set = AudioAdaptationSet(lang='en') audio_adaptation_set = bitmovin.manifests.DASH.add_audio_adaptation_set( object_=audio_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource # Add all representation to the video adaption set for encoding_config in encoding_configs: encoding_profile = encoding_config.get('profile') muxing = encoding_config.get('fmp4_muxing') fmp4_representation_1080p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=muxing.id, segment_path='video/{}p_{}k/'.format( encoding_profile.get('height'), encoding_profile.get('bitrate'))) encoding_config[ 'dash'] = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_1080p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_audio = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=audio_fmp4_muxing.id, segment_path='audio/') bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_audio, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=audio_adaptation_set.id) bitmovin.manifests.DASH.start(manifest_id=dash_manifest.id) # Create a HLS manifest and add one period with an adapation set for audio and video hls_manifest = HlsManifest(manifest_name='stream.m3u8', outputs=[manifest_output], name='HLS Manifest') hls_manifest = bitmovin.manifests.HLS.create(hls_manifest).resource audio_media = AudioMedia(name='HLS Audio Media', group_id='audio', segment_path='audio/', encoding_id=encoding.id, stream_id=audio_stream.id, muxing_id=audio_fmp4_muxing.id, language='en', uri='audio.m3u8') bitmovin.manifests.HLS.AudioMedia.create(manifest_id=hls_manifest.id, object_=audio_media) # Add all representation to the video adaption set for encoding_config in encoding_configs: encoding_profile = encoding_config.get('profile') stream = encoding_config.get('stream') muxing = encoding_config.get('fmp4_muxing') variant_stream = VariantStream(audio='audio', closed_captions='NONE', segment_path='video/{}p_{}k/'.format( encoding_profile.get('height'), encoding_profile.get('bitrate')), uri='video_{}p_{}k.m3u8'.format( encoding_profile.get('height'), encoding_profile.get('bitrate')), encoding_id=encoding.id, stream_id=stream.id, muxing_id=muxing.id) bitmovin.manifests.HLS.VariantStream.create( manifest_id=hls_manifest.id, object_=variant_stream) bitmovin.manifests.HLS.start(manifest_id=hls_manifest.id) try: bitmovin.manifests.DASH.wait_until_finished( manifest_id=dash_manifest.id, check_interval=1) except BitmovinError as bitmovin_error: print( 'Exception occurred while waiting for manifest creation to finish: {}' .format(bitmovin_error)) try: bitmovin.manifests.HLS.wait_until_finished(manifest_id=hls_manifest.id, check_interval=1) except BitmovinError as bitmovin_error: print( 'Exception occurred while waiting for manifest creation to finish: {}' .format(bitmovin_error))
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='example webm encoding', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1, encoder_version='BETA') encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration_1080p = VP9CodecConfiguration(name='example_video_codec_configuration_1080p', bitrate=4800000, rate=25.0, width=1920, height=1080, tile_columns=2, quality=VP9Quality.GOOD) video_codec_configuration_1080p = bitmovin.codecConfigurations.VP9.create(video_codec_configuration_1080p).resource audio_codec_configuration = OpusCodecConfiguration(name='example_audio_codec_configuration_english', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.Opus.create(audio_codec_configuration).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) video_stream_1080p = Stream(codec_configuration_id=video_codec_configuration_1080p.id, input_streams=[video_input_stream], name='Sample Stream 1080p') video_stream_1080p = bitmovin.encodings.Stream.create(object_=video_stream_1080p, encoding_id=encoding.id).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Sample Stream AUDIO') audio_stream = bitmovin.encodings.Stream.create(object_=audio_stream, encoding_id=encoding.id).resource audio_muxing_stream = MuxingStream(audio_stream.id) video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id) acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) webm_muxing_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) webm_muxing = ProgressiveWebMMuxing(streams=[video_muxing_stream_1080p, audio_muxing_stream], filename='myfile.webm', outputs=[webm_muxing_output], name='Sample WebM Muxing 1080p') webm_muxing = bitmovin.encodings.Muxing.ProgressiveWebM.create(object_=webm_muxing, encoding_id=encoding.id).resource bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished(encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}".format(bitmovin_error)) print("File successfully encoded")
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='example encoding', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1, encoder_version='BETA') encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration_1080p = H264CodecConfiguration( name='example_video_codec_configuration_1080p', bitrate=4800000, rate=25.0, width=1920, height=1080, profile=H264Profile.HIGH) video_codec_configuration_1080p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_1080p).resource audio_codec_configuration = AACCodecConfiguration( name='example_audio_codec_configuration_english', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create( audio_codec_configuration).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) video_stream_1080p = Stream( codec_configuration_id=video_codec_configuration_1080p.id, input_streams=[video_input_stream], name='Sample Stream 1080p') video_stream_1080p = bitmovin.encodings.Stream.create( object_=video_stream_1080p, encoding_id=encoding.id).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Sample Stream AUDIO') audio_stream = bitmovin.encodings.Stream.create( object_=audio_stream, encoding_id=encoding.id).resource audio_muxing_stream = MuxingStream(audio_stream.id) video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id) acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) mp4_muxing_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) progressive_ts_muxing = ProgressiveTSMuxing( streams=[video_muxing_stream_1080p, audio_muxing_stream], segment_length=4.0, filename='myCoolTsMuxing.ts', outputs=[mp4_muxing_output], name='Sample Progressive TS Muxing 1080p', description='This is a Progressive TS muxing') progressive_ts_muxing = bitmovin.encodings.Muxing.ProgressiveTS.create( object_=progressive_ts_muxing, encoding_id=encoding.id).resource bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) progressive_ts_muxing_information = bitmovin.encodings.Muxing.ProgressiveTS.retrieve_information( encoding_id=encoding.id, muxing_id=progressive_ts_muxing.id).resource print_muxing_information( progressive_ts_muxing_information=progressive_ts_muxing_information)
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=HTTPS_INPUT_HOST) s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') input = bitmovin.inputs.HTTPS.create(https_input).resource output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='example encoding', cloud_region=CLOUD_REGION, infrastructure_id=INFRASTRUCTURE_ID, encoder_version=ENCODER_VERSION) encoding = bitmovin.encodings.Encoding.create(encoding).resource ########################## # qualities video_qualities = [ # {'width': 1280, 'height': 720, 'br': 2400000, 'bframes': None, 'profile': H264Profile.HIGH, 'level': None}, # {'width': 854, 'height': 480, 'br': 1200000, 'bframes': None, 'profile': H264Profile.HIGH, 'level': None}, { 'width': 640, 'height': 360, 'br': 800000, 'bframes': None, 'profile': H264Profile.HIGH, 'level': None }, ] audio_qualities = [ { 'bitrate': 128000, 'rate': 48000 }, ] ########################## # configurations video_configs = [] audio_configs = [] for video_quality in video_qualities: config = H264CodecConfiguration(name='h264_{}x{}_{}'.format( video_quality['width'], video_quality['height'], video_quality['br']), rate=None, width=video_quality['width'], height=video_quality['height'], bitrate=video_quality['br'], bframes=video_quality['bframes'], profile=video_quality['profile'], level=video_quality['level']) config = bitmovin.codecConfigurations.H264.create(config).resource video_configs.append(config) for video_quality in audio_qualities: config = AACCodecConfiguration(name='aac_{}_{}'.format( video_quality['bitrate'], video_quality['rate']), bitrate=video_quality['bitrate'], rate=video_quality['rate']) config = bitmovin.codecConfigurations.AAC.create(config).resource audio_configs.append(config) video_input_stream = StreamInput(input_id=input.id, input_path=INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=input.id, input_path=INPUT_PATH, selection_mode=SelectionMode.AUTO) ########################## # streams video_streams = [] audio_streams = [] for video_config in video_configs: stream = Stream(codec_configuration_id=video_config.id, input_streams=[video_input_stream], name='{}_stream'.format(video_config.name)) stream = bitmovin.encodings.Stream.create( object_=stream, encoding_id=encoding.id).resource video_streams.append(stream) for video_config in audio_configs: stream = Stream(codec_configuration_id=video_config.id, input_streams=[audio_input_stream], name='{}_stream'.format(video_config.name)) stream = bitmovin.encodings.Stream.create( object_=stream, encoding_id=encoding.id).resource audio_streams.append(stream) acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) ########################## # muxing_streams video_muxing_streams = [] audio_muxing_streams = [] for stream in video_streams: muxing_stream = MuxingStream(stream.id) video_muxing_streams.append({'mux': muxing_stream, 'stream': stream}) for stream in audio_streams: muxing_stream = MuxingStream(stream.id) audio_muxing_streams.append({'mux': muxing_stream, 'stream': stream}) ########################## # dash muxings video_fmp4_muxings = [] audio_fmp4_muxings = [] for video_muxing_stream in video_muxing_streams: stream = video_muxing_stream['stream'] muxing = video_muxing_stream['mux'] video_path = 'video_dash/{}/'.format(stream.name) encoding_output = EncodingOutput(output_id=output.id, output_path=OUTPUT_BASE_PATH + video_path, acl=[acl_entry]) stream_array = [muxing] muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=stream_array, outputs=[encoding_output], name='dash_video_muxing_{}'.format(stream.name)) created_muxing = bitmovin.encodings.Muxing.FMP4.create( object_=muxing, encoding_id=encoding.id).resource video_fmp4_muxings.append({ 'muxing': created_muxing, 'stream': stream, 'muxing_stream': muxing, 'output': encoding_output, 'video_path': video_path }) for audio_muxing_stream in audio_muxing_streams: stream = audio_muxing_stream['stream'] muxing = audio_muxing_stream['mux'] audio_path = 'audio_dash/{}/'.format(stream.name) encoding_output = EncodingOutput(output_id=output.id, output_path=OUTPUT_BASE_PATH + audio_path, acl=[acl_entry]) stream_array = [muxing] muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=stream_array, outputs=[encoding_output], name='dash_audio_muxing_{}'.format(stream.name)) created_muxing = bitmovin.encodings.Muxing.FMP4.create( object_=muxing, encoding_id=encoding.id).resource audio_fmp4_muxings.append({ 'muxing': created_muxing, 'stream': stream, 'muxing_stream': muxing, 'output': encoding_output, 'audio_path': audio_path }) bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) manifest_output = EncodingOutput(output_id=output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) ########################## # dash manifest dash_manifest = DashManifest(manifest_name=DASH_MANIFEST_NAME, outputs=[manifest_output], name='Sample DASH Manifest') dash_manifest = bitmovin.manifests.DASH.create(dash_manifest).resource period = Period() period = bitmovin.manifests.DASH.add_period( object_=period, manifest_id=dash_manifest.id).resource video_adaptation_set = VideoAdaptationSet() video_adaptation_set = bitmovin.manifests.DASH.add_video_adaptation_set( object_=video_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource audio_adaptation_set = AudioAdaptationSet(lang='en') audio_adaptation_set = bitmovin.manifests.DASH.add_audio_adaptation_set( object_=audio_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource for video_fmp4_muxing in video_fmp4_muxings: muxing = video_fmp4_muxing['muxing'] encoding_output = video_fmp4_muxing['output'] video_path = video_fmp4_muxing['video_path'] video_fmp4_representation = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=muxing.id, segment_path=video_path) video_fmp4_representation = bitmovin.manifests.DASH.add_fmp4_representation( object_=video_fmp4_representation, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource for audio_fmp4_muxing in audio_fmp4_muxings: muxing = audio_fmp4_muxing['muxing'] encoding_output = audio_fmp4_muxing['output'] audio_path = audio_fmp4_muxing['audio_path'] audio_fmp4_representation = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=muxing.id, segment_path=audio_path) audio_fmp4_representation = bitmovin.manifests.DASH.add_fmp4_representation( object_=audio_fmp4_representation, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=audio_adaptation_set.id).resource bitmovin.manifests.DASH.start(manifest_id=dash_manifest.id) try: bitmovin.manifests.DASH.wait_until_finished( manifest_id=dash_manifest.id) except BitmovinError as bitmovin_error: print( 'Exception occurred while waiting for manifest creation to finish: {}' .format(bitmovin_error)) print('DASH Manifest download URL: {}'.format(S3_PUBLIC_BASE_URL + '/' + S3_OUTPUT_BUCKETNAME + '/' + OUTPUT_BASE_PATH + DASH_MANIFEST_NAME))
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput( host=HTTPS_INPUT_HOST, name='multiple_audio_dash_mpd_auto_analysis HTTPS input') https_input = bitmovin.inputs.HTTPS.create(https_input).resource gcs_output = GCSOutput(access_key=GCS_OUTPUT_ACCESSKEY, secret_key=GCS_OUTPUT_SECRETKEY, bucket_name=GCS_OUTPUT_BUCKETNAME) gcs_output = bitmovin.outputs.GCS.create(gcs_output).resource analysis = Analysis(path=HTTPS_INPUT_PATH, cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) analysis_resource = bitmovin.inputs.HTTPS.analyze( input_id=https_input.id, analysis_object=analysis).resource analysis_status = None try: analysis_status = bitmovin.inputs.HTTPS.wait_until_analysis_finished( input_id=https_input.id, analysis_id=analysis_resource.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for analysis to finish: {}". format(bitmovin_error)) sys.exit(100) analysis_details = bitmovin.inputs.HTTPS.retrieve_analysis_details( input_id=https_input.id, analysis_id=analysis_resource.id).resource # type: AnalysisDetails video_stream_details = analysis_details.videoStreams audio_stream_details = analysis_details.audioStreams if (len(video_stream_details) < 1): print('No video stream found.') sys.exit(200) print_input_file_information(audio_stream_details=audio_stream_details, video_stream_details=video_stream_details) encoding = Encoding(name='example encoding', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration_1080p = H264CodecConfiguration( name='example_video_codec_configuration_1080p', bitrate=4800000, rate=25.0, width=1920, height=1080, profile=H264Profile.HIGH) video_codec_configuration_1080p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_1080p).resource video_codec_configuration_720p = H264CodecConfiguration( name='example_video_codec_configuration_720p', bitrate=2400000, rate=25.0, width=1280, height=720, profile=H264Profile.HIGH) video_codec_configuration_720p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_720p).resource video_codec_configuration_480p = H264CodecConfiguration( name='example_video_codec_configuration_480p', bitrate=1200000, rate=25.0, width=854, height=480, profile=H264Profile.HIGH) video_codec_configuration_480p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_480p).resource video_codec_configuration_360p = H264CodecConfiguration( name='example_video_codec_configuration_360p', bitrate=800000, rate=25.0, width=640, height=360, profile=H264Profile.HIGH) video_codec_configuration_360p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_360p).resource video_codec_configuration_240p = H264CodecConfiguration( name='example_video_codec_configuration_240p', bitrate=400000, rate=25.0, width=426, height=240, profile=H264Profile.HIGH) video_codec_configuration_240p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_240p).resource print('Created FullHD Video Profile H264 Codec Configurations') # use the position of the first video stream which was found in the analysis video_position = video_stream_details[0].position print( 'Video Stream is at position {} of input file.'.format(video_position)) video_input_stream = StreamInput( input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.POSITION_ABSOLUTE, position=video_position) video_stream_1080p = Stream( codec_configuration_id=video_codec_configuration_1080p.id, input_streams=[video_input_stream], name='Sample Video Stream 1080p') video_stream_1080p = bitmovin.encodings.Stream.create( object_=video_stream_1080p, encoding_id=encoding.id).resource video_stream_720p = Stream( codec_configuration_id=video_codec_configuration_720p.id, input_streams=[video_input_stream], name='Sample Video Stream 720p') video_stream_720p = bitmovin.encodings.Stream.create( object_=video_stream_720p, encoding_id=encoding.id).resource video_stream_480p = Stream( codec_configuration_id=video_codec_configuration_480p.id, input_streams=[video_input_stream], name='Sample Video Stream 480p') video_stream_480p = bitmovin.encodings.Stream.create( object_=video_stream_480p, encoding_id=encoding.id).resource video_stream_360p = Stream( codec_configuration_id=video_codec_configuration_360p.id, input_streams=[video_input_stream], name='Sample Video Stream 360p') video_stream_360p = bitmovin.encodings.Stream.create( object_=video_stream_360p, encoding_id=encoding.id).resource video_stream_240p = Stream( codec_configuration_id=video_codec_configuration_240p.id, input_streams=[video_input_stream], name='Sample Video Stream 240p') video_stream_240p = bitmovin.encodings.Stream.create( object_=video_stream_240p, encoding_id=encoding.id).resource print('Created FullHD Video Profile Streams') video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id) video_muxing_stream_720p = MuxingStream(video_stream_720p.id) video_muxing_stream_480p = MuxingStream(video_stream_480p.id) video_muxing_stream_360p = MuxingStream(video_stream_360p.id) video_muxing_stream_240p = MuxingStream(video_stream_240p.id) acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) video_muxing_1080p_output = EncodingOutput(output_id=gcs_output.id, output_path=OUTPUT_BASE_PATH + 'video/1080p/', acl=[acl_entry]) video_muxing_1080p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_1080p], outputs=[video_muxing_1080p_output], name='Sample Video Muxing 1080p') video_muxing_1080p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_1080p, encoding_id=encoding.id).resource video_muxing_720p_output = EncodingOutput(output_id=gcs_output.id, output_path=OUTPUT_BASE_PATH + 'video/720p/', acl=[acl_entry]) video_muxing_720p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_720p], outputs=[video_muxing_720p_output], name='Sample Video Muxing 720p') video_muxing_720p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_720p, encoding_id=encoding.id).resource video_muxing_480p_output = EncodingOutput(output_id=gcs_output.id, output_path=OUTPUT_BASE_PATH + 'video/480p/', acl=[acl_entry]) video_muxing_480p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_480p], outputs=[video_muxing_480p_output], name='Sample Video Muxing 480p') video_muxing_480p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_480p, encoding_id=encoding.id).resource video_muxing_360p_output = EncodingOutput(output_id=gcs_output.id, output_path=OUTPUT_BASE_PATH + 'video/360p/', acl=[acl_entry]) video_muxing_360p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_360p], outputs=[video_muxing_360p_output], name='Sample Video Muxing 360p') video_muxing_360p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_360p, encoding_id=encoding.id).resource video_muxing_240p_output = EncodingOutput(output_id=gcs_output.id, output_path=OUTPUT_BASE_PATH + 'video/240p/', acl=[acl_entry]) video_muxing_240p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_240p], outputs=[video_muxing_240p_output], name='Sample Video Muxing 240p') video_muxing_240p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_240p, encoding_id=encoding.id).resource print('Created FullHD Video Profile Muxings') audio_muxings = [] audio_muxing_mpd_information = [] for analysis_audio_stream in audio_stream_details: print( 'Found audio stream at position {} with channel layout {}'.format( analysis_audio_stream.position, analysis_audio_stream.channelFormat)) bitrate = 128000 if analysis_audio_stream.channelFormat not in ('STEREO', 'MONO'): bitrate = 256000 audio_codec_config = AACCodecConfiguration( name='example_audio_codec_conf_pos{}'.format( analysis_audio_stream.position), bitrate=bitrate, rate=analysis_audio_stream.sampleRate) audio_codec_config = bitmovin.codecConfigurations.AAC.create( audio_codec_config).resource print('Created AAC Codec Config for audio stream') audio_input_stream = StreamInput( input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.POSITION_ABSOLUTE, position=analysis_audio_stream.position) audio_stream = Stream(codec_configuration_id=audio_codec_config.id, input_streams=[audio_input_stream], name='Sample Audio Stream') audio_stream = bitmovin.encodings.Stream.create( object_=audio_stream, encoding_id=encoding.id).resource print('Created audio stream') segment_path = 'audio/{}_{}/'.format( analysis_audio_stream.language, analysis_audio_stream.channelFormat) audio_muxing_output = EncodingOutput(output_id=gcs_output.id, output_path=OUTPUT_BASE_PATH + segment_path, acl=[acl_entry]) audio_muxing_stream = MuxingStream(audio_stream.id) audio_muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[audio_muxing_stream], outputs=[audio_muxing_output], name='Sample Video Stream') audio_muxing = bitmovin.encodings.Muxing.FMP4.create( object_=audio_muxing, encoding_id=encoding.id).resource print('Created audio Muxing') audio_muxings.append(audio_muxing) audio_muxing_mpd_information.append({ 'lang': analysis_audio_stream.language, 'channel_layout': analysis_audio_stream.channelFormat, 'muxing_id': audio_muxing.id, 'segment_path': segment_path }) print('Starting encoding...') bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) manifest_output = EncodingOutput(output_id=gcs_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) dash_manifest = DashManifest(manifest_name='example_manifest_dash.mpd', outputs=[manifest_output], name='Sample DASH Manifest') dash_manifest = bitmovin.manifests.DASH.create(dash_manifest).resource period = Period() period = bitmovin.manifests.DASH.add_period( object_=period, manifest_id=dash_manifest.id).resource video_adaptation_set = VideoAdaptationSet() video_adaptation_set = bitmovin.manifests.DASH.add_video_adaptation_set( object_=video_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource fmp4_representation_1080p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_1080p.id, segment_path='video/1080p/') fmp4_representation_1080p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_1080p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_720p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_720p.id, segment_path='video/720p/') fmp4_representation_720p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_720p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_480p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_480p.id, segment_path='video/480p/') fmp4_representation_480p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_480p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_360p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_360p.id, segment_path='video/360p/') fmp4_representation_360p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_360p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_240p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_240p.id, segment_path='video/240p/') fmp4_representation_240p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_240p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource for information in audio_muxing_mpd_information: lang = information.get('lang') channel_layout = information.get('channel_layout') muxing_id = information.get('muxing_id') segment_path = information.get('segment_path') audio_adaptation_set_lang_name = '{} {}'.format( lang, channel_layout).upper() audio_adaptation_set = AudioAdaptationSet( lang=audio_adaptation_set_lang_name) audio_adaptation_set = bitmovin.manifests.DASH.add_audio_adaptation_set( object_=audio_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource fmp4_representation_audio = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=muxing_id, segment_path=segment_path) fmp4_representation_audio = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_audio, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=audio_adaptation_set.id).resource print('Starting DASH Manifest creation...') bitmovin.manifests.DASH.start(manifest_id=dash_manifest.id) try: bitmovin.manifests.DASH.wait_until_finished( manifest_id=dash_manifest.id) except BitmovinError as bitmovin_error: print( "Exception occurred while waiting for manifest creation to finish: {}" .format(bitmovin_error))
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='example hls fmp4 fairplay encoding', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration_1080p = H264CodecConfiguration( name='example_video_codec_configuration_1080p', bitrate=4800000, rate=25.0, width=1920, height=1080, profile=H264Profile.HIGH) video_codec_configuration_1080p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_1080p).resource video_codec_configuration_720p = H264CodecConfiguration( name='example_video_codec_configuration_720p', bitrate=2400000, rate=25.0, width=1280, height=720, profile=H264Profile.HIGH) video_codec_configuration_720p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_720p).resource audio_codec_configuration = AACCodecConfiguration( name='example_audio_codec_configuration_english', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create( audio_codec_configuration).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) video_stream_1080p = Stream( codec_configuration_id=video_codec_configuration_1080p.id, input_streams=[video_input_stream], name='Sample Stream 1080p') video_stream_1080p = bitmovin.encodings.Stream.create( object_=video_stream_1080p, encoding_id=encoding.id).resource video_stream_720p = Stream( codec_configuration_id=video_codec_configuration_720p.id, input_streams=[video_input_stream], name='Sample Stream 720p') video_stream_720p = bitmovin.encodings.Stream.create( object_=video_stream_720p, encoding_id=encoding.id).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Sample Stream AUDIO') audio_stream = bitmovin.encodings.Stream.create( object_=audio_stream, encoding_id=encoding.id).resource acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id) video_muxing_stream_720p = MuxingStream(video_stream_720p.id) audio_muxing_stream = MuxingStream(audio_stream.id) video_muxing_1080p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/1080p/', acl=[acl_entry]) video_muxing_1080p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_1080p], outputs=[video_muxing_1080p_output], name='Sample Muxing 1080p') video_muxing_1080p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_1080p, encoding_id=encoding.id).resource video_muxing_720p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/720p/', acl=[acl_entry]) video_muxing_720p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_720p], outputs=[video_muxing_720p_output], name='Sample Muxing 720p') video_muxing_720p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_720p, encoding_id=encoding.id).resource audio_muxing_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'audio/', acl=[acl_entry]) audio_muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[audio_muxing_stream], outputs=[audio_muxing_output], name='Sample Muxing AUDIO') audio_muxing = bitmovin.encodings.Muxing.FMP4.create( object_=audio_muxing, encoding_id=encoding.id).resource bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) manifest_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) hls_manifest = HlsManifest(manifest_name='example_manifest_hls.m3u8', outputs=[manifest_output], name='Sample HLS Manifest') hls_manifest = bitmovin.manifests.HLS.create(object_=hls_manifest).resource audio_media = AudioMedia(name='Sample Audio Media', group_id='audio_group', segment_path=audio_muxing_output.outputPath, encoding_id=encoding.id, stream_id=audio_stream.id, muxing_id=audio_muxing.id, language='en', uri='audiomedia.m3u8') audio_media = bitmovin.manifests.HLS.AudioMedia.create( manifest_id=hls_manifest.id, object_=audio_media).resource variant_stream_1080p = VariantStream( audio=audio_media.groupId, closed_captions='NONE', segment_path=video_muxing_1080p_output.outputPath, uri='video_1080p.m3u8', encoding_id=encoding.id, stream_id=video_stream_1080p.id, muxing_id=video_muxing_1080p.id) variant_stream_1080p = bitmovin.manifests.HLS.VariantStream.create( manifest_id=hls_manifest.id, object_=variant_stream_1080p) variant_stream_720p = VariantStream( audio=audio_media.groupId, closed_captions='NONE', segment_path=video_muxing_720p_output.outputPath, uri='video_720p.m3u8', encoding_id=encoding.id, stream_id=video_stream_720p.id, muxing_id=video_muxing_720p.id) variant_stream_720p = bitmovin.manifests.HLS.VariantStream.create( manifest_id=hls_manifest.id, object_=variant_stream_720p) bitmovin.manifests.HLS.start(manifest_id=hls_manifest.id) try: bitmovin.manifests.HLS.wait_until_finished(manifest_id=hls_manifest.id) except BitmovinError as bitmovin_error: print( "Exception occurred while waiting for HLS manifest creation to finish: {}" .format(bitmovin_error))
def main(): https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='Python Example - Add Timecode to MP4Muxing', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_codec_configuration = AACCodecConfiguration(name='example_audio_codec_configuration_english', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create(audio_codec_configuration).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream], name='Sample Stream Audio') audio_stream = bitmovin.encodings.Stream.create(object_=audio_stream, encoding_id=encoding.id).resource time_code = TimeCode(time_code_start="01:00:00:00") for profile in encoding_profiles: video_codec_configuration = H264CodecConfiguration( name='python_example_mp4muxing_with_timecode_{}p'.format(profile['height']), bitrate=profile['bitrate'], rate=profile['fps'], width=None, height=profile['height'], profile=H264Profile.HIGH) video_codec_configuration = bitmovin.codecConfigurations.H264.create(video_codec_configuration).resource video_stream = Stream(codec_configuration_id=video_codec_configuration.id, input_streams=[video_input_stream], name='Python Example H264 Stream {}p'.format(profile['height'])) video_stream = bitmovin.encodings.Stream.create(object_=video_stream, encoding_id=encoding.id).resource create_muxing(encoding, s3_output, video_stream, audio_stream, 'video_audio_{}p.mp4'.format(profile['height']), time_code) bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished(encoding_id=encoding.id) except BitmovinError as bitmovin_error: print('Exception occurred while waiting for encoding to finish: {}'.format(bitmovin_error))
def main(): # === Prepare the encoding configuration === # Create an S3 Output. This will be used as target bucket for the muxings, sprites and manifests s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding_configs = [] # Iterate over all encoding profiles and create the H264 configuration with the defined height and bitrate. for encoding_profile in encoding_profiles: encoding_config = dict(profile=encoding_profile, type='video') codec = H264CodecConfiguration( name='H264 Codec {}p {}k Configuration'.format( encoding_profile.get('height'), encoding_profile.get('bitrate')), bitrate=encoding_profile.get('bitrate') * 1000, height=encoding_profile.get('height'), rate=encoding_profile.get("fps"), profile=H264Profile.HIGH) encoding_config['codec'] = bitmovin.codecConfigurations.H264.create( codec).resource encoding_configs.append(encoding_config) # Also the AAC configuration has to be created, which will be later on used to create the streams. encoding_config = dict(type='audio') audio_codec = AACCodecConfiguration(name='AAC Codec Configuration', bitrate=128000, rate=48000) encoding_config['codec'] = bitmovin.codecConfigurations.AAC.create( audio_codec).resource encoding_configs.append(encoding_config) # === Encode the main content === # Create an HTTPs input. This resource is then used as base URL for the input file. https_input = HTTPSInput(name='HTTPS input for content', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource # Create an Encoding. This will run in AWS_EU_WEST_1. This is the base entity used to configure the encoding. encoding = Encoding(name="Multiperiod DASH - Content", cloud_region=CloudRegion.AWS_EU_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource # Generate keyframes keyframes = [] for point in midroll_ad_insertion_points: keyframe = Keyframe(time=point, segment_cut=True) keyframe = bitmovin.encodings.Keyframe.create( object_=keyframe, encoding_id=encoding.id).resource keyframes.append(keyframe) content_resources = encode_file_to_fmp4(encoding=encoding, input=https_input, input_path=HTTPS_INPUT_PATH, output=s3_output, output_path=OUTPUT_BASE_PATH, encoding_configs=encoding_configs) # === Encode the ad ==== ad_resources = None ad_encoding = None if INSERT_PRE_ROLL or INSERT_MID_ROLLS or INSERT_POST_ROLL: # Create an HTTPs input. This resource is then used as base URL for the input file. ad_https_input = HTTPSInput(name='HTTPS input for ad', host=AD_HTTPS_INPUT_HOST) ad_https_input = bitmovin.inputs.HTTPS.create(ad_https_input).resource # Create an Encoding. ad_encoding = Encoding(name="Multiperiod Dash - Ad", cloud_region=CloudRegion.AWS_EU_WEST_1) ad_encoding = bitmovin.encodings.Encoding.create(ad_encoding).resource ad_resources = encode_file_to_fmp4(encoding=ad_encoding, input=ad_https_input, input_path=AD_HTTPS_INPUT_PATH, output=s3_output, output_path=OUTPUT_BASE_PATH + "ad/", encoding_configs=encoding_configs) generate_multiperiod_dash_manifest( output=s3_output, output_path=OUTPUT_BASE_PATH, content_encoding_configs=content_resources, keyframes=keyframes, content_encoding=encoding, ad_encoding=ad_encoding, ad_encoding_configs=ad_resources)
def main(): bitmovin = Bitmovin(api_key=API_KEY) https_input = HTTPSInput(host=HTTPS_INPUT_HOST, name='multiple_audio_progressive_mp4 HTTPS input') https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name="bitmovin-python example", cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1) encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration = H264CodecConfiguration( name='example_video_codec_configuration_h264', bitrate=1000000, rate=50.0, width=1280, height=720, profile=H264Profile.HIGH) video_codec_configuration = bitmovin.codecConfigurations.H264.create( video_codec_configuration).resource audio_codec_configuration = AACCodecConfiguration( name='example_audio_codec_configuration_aac', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create( audio_codec_configuration).resource audio_input_stream_1 = StreamInput( input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.POSITION_ABSOLUTE, position=0) audio_input_stream_2 = StreamInput( input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.POSITION_ABSOLUTE, position=1) video_input_stream = StreamInput( input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.POSITION_ABSOLUTE, position=2) video_stream = Stream(codec_configuration_id=video_codec_configuration.id, input_streams=[video_input_stream], name='Sample Video Stream') video_stream = bitmovin.encodings.Stream.create( object_=video_stream, encoding_id=encoding.id).resource audio_stream_1 = Stream( codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream_1], name='Sample Audio Stream 1') audio_stream_1 = bitmovin.encodings.Stream.create( object_=audio_stream_1, encoding_id=encoding.id).resource audio_stream_2 = Stream( codec_configuration_id=audio_codec_configuration.id, input_streams=[audio_input_stream_2], name='Sample Audio Stream 2') audio_stream_2 = bitmovin.encodings.Stream.create( object_=audio_stream_2, encoding_id=encoding.id).resource acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) encoding_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) video_muxing_stream = MuxingStream(video_stream.id) audio_muxing_stream_1 = MuxingStream(audio_stream_1.id) audio_muxing_stream_2 = MuxingStream(audio_stream_2.id) progressive_muxing = MP4Muxing(filename="example_progressive_muxing.mp4", streams=[ video_muxing_stream, audio_muxing_stream_1, audio_muxing_stream_2 ], outputs=[encoding_output], name='Sample Progressive Muxing') progressive_muxing = bitmovin.encodings.Muxing.MP4.create( object_=progressive_muxing, encoding_id=encoding.id) bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error))
def main(): bitmovin = Bitmovin(api_key=API_KEY) bumper_https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=BUMPER_HTTPS_INPUT_HOST) bumper_https_input = bitmovin.inputs.HTTPS.create( bumper_https_input).resource main_https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=MAIN_HTTPS_INPUT_HOST) main_https_input = bitmovin.inputs.HTTPS.create(main_https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='example encoding', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1, encoder_version='2.7.0') encoding = bitmovin.encodings.Encoding.create(encoding).resource video_codec_configuration_1080p = H264CodecConfiguration( name='example_video_codec_configuration_1080p', bitrate=4800000, rate=25.0, width=1920, height=1080, profile=H264Profile.HIGH) video_codec_configuration_1080p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_1080p).resource video_codec_configuration_720p = H264CodecConfiguration( name='example_video_codec_configuration_720p', bitrate=2400000, rate=25.0, width=1280, height=720, profile=H264Profile.HIGH) video_codec_configuration_720p = bitmovin.codecConfigurations.H264.create( video_codec_configuration_720p).resource audio_codec_configuration = AACCodecConfiguration( name='example_audio_codec_configuration_english', bitrate=128000, rate=48000) audio_codec_configuration = bitmovin.codecConfigurations.AAC.create( audio_codec_configuration).resource bumper_ingest_input_stream = IngestInputStream( input_id=bumper_https_input.id, input_path=BUMPER_HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO, position=0) bumper_ingest_input_stream = bitmovin.encodings.IngestInputStream.create( encoding_id=encoding.id, object_=bumper_ingest_input_stream).resource bumper_time_based_trimming_input_stream = TimeBasedTrimmingInputStream( input_stream_id=bumper_ingest_input_stream.id, offset=BUMPER_OFFSET, duration=BUMPER_DURATION) bumper_time_based_trimming_input_stream = bitmovin.encodings.TimeBasedTrimmingInputStream.create( encoding_id=encoding.id, object_=bumper_time_based_trimming_input_stream).resource main_ingest_input_stream = IngestInputStream( input_id=main_https_input.id, input_path=MAIN_HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO, position=0) main_ingest_input_stream = bitmovin.encodings.IngestInputStream.create( encoding_id=encoding.id, object_=main_ingest_input_stream).resource main_time_based_trimming_input_stream = TimeBasedTrimmingInputStream( input_stream_id=main_ingest_input_stream.id, offset=MAIN_OFFSET, duration=BUMPER_DURATION) main_time_based_trimming_input_stream = bitmovin.encodings.TimeBasedTrimmingInputStream.create( encoding_id=encoding.id, object_=main_time_based_trimming_input_stream).resource bumper_concatenation_input_stream_config = ConcatenationInputStreamConfiguration( input_stream_id=bumper_time_based_trimming_input_stream.id, is_main=False, position=0) main_concatenation_input_stream_config = ConcatenationInputStreamConfiguration( input_stream_id=main_time_based_trimming_input_stream.id, is_main=True, position=0) concatenation_input_stream = ConcatenationInputStream(concatenation=[ bumper_concatenation_input_stream_config, main_concatenation_input_stream_config ]) concatenation_input_stream = bitmovin.encodings.ConcatenationInputStream.create( encoding_id=encoding.id, object_=concatenation_input_stream).resource input_stream = StreamInput(input_stream_id=concatenation_input_stream.id) video_stream_1080p = Stream( codec_configuration_id=video_codec_configuration_1080p.id, input_streams=[input_stream], name='Sample Stream 1080p') video_stream_1080p = bitmovin.encodings.Stream.create( object_=video_stream_1080p, encoding_id=encoding.id).resource video_stream_720p = Stream( codec_configuration_id=video_codec_configuration_720p.id, input_streams=[input_stream], name='Sample Stream 720p') video_stream_720p = bitmovin.encodings.Stream.create( object_=video_stream_720p, encoding_id=encoding.id).resource audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id, input_streams=[input_stream], name='Sample Stream AUDIO') audio_stream = bitmovin.encodings.Stream.create( object_=audio_stream, encoding_id=encoding.id).resource acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id) video_muxing_stream_720p = MuxingStream(video_stream_720p.id) audio_muxing_stream = MuxingStream(audio_stream.id) video_muxing_1080p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/1080p/', acl=[acl_entry]) video_muxing_1080p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_1080p], outputs=[video_muxing_1080p_output], name='Sample Muxing 1080p') video_muxing_1080p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_1080p, encoding_id=encoding.id).resource video_muxing_720p_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'video/720p/', acl=[acl_entry]) video_muxing_720p = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[video_muxing_stream_720p], outputs=[video_muxing_720p_output], name='Sample Muxing 720p') video_muxing_720p = bitmovin.encodings.Muxing.FMP4.create( object_=video_muxing_720p, encoding_id=encoding.id).resource audio_muxing_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH + 'audio/', acl=[acl_entry]) audio_muxing = FMP4Muxing(segment_length=4, segment_naming='seg_%number%.m4s', init_segment_name='init.mp4', streams=[audio_muxing_stream], outputs=[audio_muxing_output], name='Sample Muxing AUDIO') audio_muxing = bitmovin.encodings.Muxing.FMP4.create( object_=audio_muxing, encoding_id=encoding.id).resource bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) manifest_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) dash_manifest = DashManifest( manifest_name='example_manifest_sintel_dash.mpd', outputs=[manifest_output], name='Sample DASH Manifest') dash_manifest = bitmovin.manifests.DASH.create(dash_manifest).resource period = Period() period = bitmovin.manifests.DASH.add_period( object_=period, manifest_id=dash_manifest.id).resource video_adaptation_set = VideoAdaptationSet() video_adaptation_set = bitmovin.manifests.DASH.add_video_adaptation_set( object_=video_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource audio_adaptation_set = AudioAdaptationSet(lang='en') audio_adaptation_set = bitmovin.manifests.DASH.add_audio_adaptation_set( object_=audio_adaptation_set, manifest_id=dash_manifest.id, period_id=period.id).resource fmp4_representation_1080p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_1080p.id, segment_path='video/1080p/') fmp4_representation_1080p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_1080p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_720p = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=video_muxing_720p.id, segment_path='video/720p/') fmp4_representation_720p = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_720p, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=video_adaptation_set.id).resource fmp4_representation_audio = FMP4Representation( FMP4RepresentationType.TEMPLATE, encoding_id=encoding.id, muxing_id=audio_muxing.id, segment_path='audio/') fmp4_representation_audio = bitmovin.manifests.DASH.add_fmp4_representation( object_=fmp4_representation_audio, manifest_id=dash_manifest.id, period_id=period.id, adaptationset_id=audio_adaptation_set.id).resource bitmovin.manifests.DASH.start(manifest_id=dash_manifest.id) try: bitmovin.manifests.DASH.wait_until_finished( manifest_id=dash_manifest.id) except BitmovinError as bitmovin_error: print( "Exception occurred while waiting for manifest creation to finish: {}" .format(bitmovin_error))
def main(): https_input = HTTPSInput(name='create_simple_encoding HTTPS input', host=HTTPS_INPUT_HOST) https_input = bitmovin.inputs.HTTPS.create(https_input).resource s3_output = S3Output(access_key=S3_OUTPUT_ACCESSKEY, secret_key=S3_OUTPUT_SECRETKEY, bucket_name=S3_OUTPUT_BUCKETNAME, name='Sample S3 Output') s3_output = bitmovin.outputs.S3.create(s3_output).resource encoding = Encoding(name='example mov encoding', cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1, encoder_version='BETA') encoding = bitmovin.encodings.Encoding.create(encoding).resource video_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) audio_input_stream = StreamInput(input_id=https_input.id, input_path=HTTPS_INPUT_PATH, selection_mode=SelectionMode.AUTO) create_fmp4_muxings(encoding_id=encoding.id, video_input_stream=video_input_stream, audio_input_stream=audio_input_stream, s3_output_id=s3_output.id) mjpeg_codec_config = MJPEGCodecConfiguration( name='mjpeg codec configuration', q_scale=2, rate=1.0) mjpeg_codec_config = bitmovin.codecConfigurations.MJPEG.create( mjpeg_codec_config).resource video_stream = Stream(codec_configuration_id=mjpeg_codec_config.id, input_streams=[video_input_stream], name='Sample Stream 1080p') video_stream = bitmovin.encodings.Stream.create( object_=video_stream, encoding_id=encoding.id).resource video_muxing_stream = MuxingStream(video_stream.id) acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ) mov_muxing_output = EncodingOutput(output_id=s3_output.id, output_path=OUTPUT_BASE_PATH, acl=[acl_entry]) mov_muxing = ProgressiveMOVMuxing( streams=[video_muxing_stream], filename='myKeyframeArchive.mov', outputs=[mov_muxing_output], name='Sample Progressive MOV Muxing', description='This is a Progressive MOV muxing') mov_muxing = bitmovin.encodings.Muxing.ProgressiveMOV.create( object_=mov_muxing, encoding_id=encoding.id).resource bitmovin.encodings.Encoding.start(encoding_id=encoding.id) try: bitmovin.encodings.Encoding.wait_until_finished( encoding_id=encoding.id) except BitmovinError as bitmovin_error: print("Exception occurred while waiting for encoding to finish: {}". format(bitmovin_error)) dash_manifest = create_dash_manifest(encoding_id=encoding.id, s3_output_id=s3_output.id) bitmovin.manifests.DASH.start(manifest_id=dash_manifest.id) try: bitmovin.manifests.DASH.wait_until_finished( manifest_id=dash_manifest.id) except BitmovinError as bitmovin_error: print( "Exception occurred while waiting for manifest creation to finish: {}" .format(bitmovin_error))