Esempio n. 1
0
def main():
    # Create the input resource to access the input file
    s3_input = S3Input(access_key=S3_INPUT_ACCESS_KEY,
                       secret_key=S3_INPUT_SECRET_KEY,
                       bucket_name=S3_INPUT_BUCKET_NAME,
                       name='Sample S3 Input')
    s3_input = bitmovin.inputs.S3.create(s3_input).resource

    # Create the output resource to write the output files
    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

    # The encoding is created. The cloud region is set to AUTO to use the best cloud region depending on the input
    encoding = Encoding(name='Python Example - Per-Title',
                        cloud_region=CloudRegion.AUTO)
    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    # Select the video and audio input stream that should be encoded
    video_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)
    audio_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)

    audio_stream = create_audio_stream(encoding, audio_input_stream)
    video_stream = create_per_title_video_stream(encoding, video_input_stream)
    create_mp4_muxing(encoding, s3_output, video_stream, audio_stream)
    start_encoding(encoding)
Esempio n. 2
0
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))
Esempio n. 3
0
 def _get_sample_encoding(self):
     encoding = Encoding(
         name='Sample Encoding bitmovin-python',
         description=
         'Sample encoding used in bitmovin-python API client tests',
         cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1)
     self.assertIsNotNone(encoding.name)
     self.assertIsNotNone(encoding.description)
     self.assertIsNotNone(encoding.cloudRegion)
     return encoding
 def _get_sample_encoding(self,
                          cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1,
                          infrastructure=None):
     encoding = Encoding(
         name='Sample Encoding bitmovin-python',
         description=
         'Sample encoding used in bitmovin-python API client tests',
         cloud_region=cloud_region,
         infrastructure=infrastructure,
         labels=['label1', 'label2'])
     self.assertIsNotNone(encoding.name)
     self.assertIsNotNone(encoding.description)
     self.assertIsNotNone(encoding.cloudRegion)
     self.assertIsNotNone(encoding.labels)
     self.assertIsInstance(encoding.labels, list)
     self.assertIs(len(encoding.labels), 2)
     return encoding
def main():
    bitmovin = Bitmovin(api_key=API_KEY)
    resource_response = bitmovin.inputs.RTMP.list()

    if not resource_response or \
       not resource_response.resource or \
       not isinstance(resource_response.resource, list) or \
       len(resource_response.resource) < 1:
        print('Could not find any RTMP inputs. Please contact support.')
        sys.exit(3)

    rtmp_input_id = resource_response.resource[0].id
    print("Found RTMP input with ID '{}'".format(rtmp_input_id))

    rtmp_input = bitmovin.inputs.RTMP.retrieve(id_=rtmp_input_id).resource

    s3_output = S3Output(access_key=S3_OUTPUT_ACCESS_KEY,
                         secret_key=S3_OUTPUT_SECRET_KEY,
                         bucket_name=S3_OUTPUT_BUCKET_NAME,
                         name='Sample S3 Output')
    s3_output = bitmovin.outputs.S3.create(s3_output).resource

    encoding = Encoding(name='example python live stream encoding',
                        encoder_version=ENCODER_VERSION,
                        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_360p = H264CodecConfiguration(
        name='example_video_codec_configuration_720p',
        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

    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=rtmp_input.id,
                                     input_path='live',
                                     position=0,
                                     selection_mode=SelectionMode.AUTO)
    audio_input_stream = StreamInput(input_id=rtmp_input.id,
                                     input_path='live',
                                     position=1,
                                     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

    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

    video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id)
    video_muxing_stream_720p = MuxingStream(video_stream_720p.id)
    video_muxing_stream_360p = MuxingStream(video_stream_360p.id)
    audio_muxing_stream = MuxingStream(audio_stream.id)

    acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ)

    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

    video_muxing_360p_output = EncodingOutput(output_id=s3_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 Muxing 360p')
    video_muxing_360p = bitmovin.encodings.Muxing.FMP4.create(
        object_=video_muxing_360p, encoding_id=encoding.id).resource

    audio_muxing_output = EncodingOutput(output_id=s3_output.id,
                                         output_path=OUTPUT_BASE_PATH +
                                         'audio/128k',
                                         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

    live_stream_configuration = LiveStreamConfiguration(stream_key=STREAM_KEY)
    resource_response = bitmovin.encodings.Encoding.start_live(
        encoding_id=encoding.id,
        live_stream_configuration=live_stream_configuration)

    bitmovin.encodings.Encoding.wait_until_running(
        encoding_id=resource_response.resource.id)

    live_details = None
    retry = 0

    while retry < LIVE_STREAM_INFORMATION_FETCH_MAX_RETRIES:
        try:
            live_details = bitmovin.encodings.Encoding.retrieve_live(
                encoding_id=resource_response.resource.id)
            break
        except BitmovinApiError as bitmovin_api_error:
            if bitmovin_api_error.response.data.code != ERROR_CODE_LIVE_STREAM_NOT_READY:
                sys.exit(2)
            print(
                "Live stream is not ready yet. Retrying to fetch live stream information in {} seconds..."
                .format(LIVE_STREAM_INFORMATION_FETCH_RETRY_INTERVAL))
            retry += 1
            time.sleep(LIVE_STREAM_INFORMATION_FETCH_RETRY_INTERVAL)

    if live_details is not None:
        print_live_stream_details(encoding_id=encoding.id,
                                  live_stream_details=live_details.resource)
    else:
        print("Unable to fetch live stream details!")
        sys.exit(1)
Esempio n. 6
0
def main():
    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME,
                       name='Sample S3 Output')
    s3_input = bitmovin.inputs.S3.create(s3_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='hls fairplay example encoding - {}'.format(date_component))
    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    video_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)

    audio_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)

    video_details = {}
    for profile in VIDEO_PROFILES:
        codec_config = H265CodecConfiguration(
            name="h265 configuration @ {}".format(profile['bitrate']),
            bitrate=profile['bitrate'],
            rate=profile['fps'],
            height=profile['height'],
            profile=H265Profile.main)

        codec_config = bitmovin.codecConfigurations.H265.create(
            codec_config).resource

        stream = Stream(codec_configuration_id=codec_config.id,
                        input_streams=[video_input_stream],
                        name='Sample Stream - {}bps'.format(
                            profile['bitrate']))
        stream = bitmovin.encodings.Stream.create(
            object_=stream, encoding_id=encoding.id).resource

        muxing = create_fmp4_muxing(encoding, stream)

        cenc = create_cenc_drm(encoding=encoding,
                               muxing=muxing,
                               output=s3_output,
                               path='{}fmp4/video_{}p'.format(
                                   OUTPUT_BASE_PATH, profile['height']))

        muxing_key = 'video_{}'.format(profile['bitrate'])

        video_details[muxing_key] = dict(muxing=muxing, drm=cenc)

    audio_codec_config = AACCodecConfiguration(
        name='example_audio_codec_configuration_stereo',
        bitrate=128000,
        rate=48000)

    audio_codec_config = bitmovin.codecConfigurations.AAC.create(
        audio_codec_config).resource

    audio_stream = Stream(codec_configuration_id=audio_codec_config.id,
                          input_streams=[audio_input_stream],
                          name='Sample Audio Stream EN Stereo')

    audio_stream = bitmovin.encodings.Stream.create(
        object_=audio_stream, encoding_id=encoding.id).resource

    acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ)

    audio_muxing = create_fmp4_muxing(encoding=encoding, stream=audio_stream)

    cenc_audio = create_cenc_drm(encoding=encoding,
                                 muxing=audio_muxing,
                                 output=s3_output,
                                 path='{}fmp4/audio_{}'.format(
                                     OUTPUT_BASE_PATH, 128000))

    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 ##

    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 FairPlay Manifest')
    hls_manifest = bitmovin.manifests.HLS.create(hls_manifest).resource

    audio_media = AudioMedia(
        name='Sample Audio Media',
        group_id='audio_group',
        segment_path=cenc_audio.outputs[0].outputPath.replace(
            OUTPUT_BASE_PATH, ''),
        encoding_id=encoding.id,
        stream_id=audio_stream.id,
        muxing_id=audio_muxing.id,
        drm_id=cenc_audio.id,
        language='en',
        uri='audiomedia.m3u8')

    audio_media = bitmovin.manifests.HLS.AudioMedia.create(
        manifest_id=hls_manifest.id, object_=audio_media).resource

    for key, video_detail in video_details.items():
        muxing = video_detail['muxing']
        drm = video_detail['drm']
        variant_stream = VariantStream(
            audio=audio_media.groupId,
            closed_captions='NONE',
            segment_path=drm.outputs[0].outputPath.replace(
                OUTPUT_BASE_PATH, ''),
            uri='{}.m3u8'.format(key),
            encoding_id=encoding.id,
            stream_id=muxing.streams[0].streamId,
            muxing_id=muxing.id,
            drm_id=drm.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.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 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))
Esempio n. 8
0
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))
Esempio n. 9
0
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    sftp_input = SFTPInput(host=SFTP_INPUT_HOST,
                           username=SFTP_INPUT_USER,
                           password=SFTP_INPUT_PASSWORD,
                           name='multiple_audio_dash_mpd SFTP input')
    sftp_input = bitmovin.inputs.SFTP.create(sftp_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

    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

    audio_codec_configuration_stereo = AACCodecConfiguration(
        name='example_audio_codec_configuration_stereo',
        bitrate=128000,
        rate=48000)
    audio_codec_configuration_stereo = bitmovin.codecConfigurations.AAC.create(
        audio_codec_configuration_stereo).resource

    audio_codec_configuration_5_1 = AACCodecConfiguration(
        name='example_audio_codec_configuration_5_1',
        bitrate=384000,
        rate=48000)
    audio_codec_configuration_5_1 = bitmovin.codecConfigurations.AAC.create(
        audio_codec_configuration_5_1).resource

    video_input_stream = StreamInput(
        input_id=sftp_input.id,
        input_path=SFTP_INPUT_PATH,
        selection_mode=SelectionMode.POSITION_ABSOLUTE,
        position=0)

    audio_input_stream_cz_stereo = StreamInput(
        input_id=sftp_input.id,
        input_path=SFTP_INPUT_PATH,
        selection_mode=SelectionMode.POSITION_ABSOLUTE,
        position=1)
    audio_input_stream_en_stereo = StreamInput(
        input_id=sftp_input.id,
        input_path=SFTP_INPUT_PATH,
        selection_mode=SelectionMode.POSITION_ABSOLUTE,
        position=2)
    audio_input_stream_cz_5_1 = StreamInput(
        input_id=sftp_input.id,
        input_path=SFTP_INPUT_PATH,
        selection_mode=SelectionMode.POSITION_ABSOLUTE,
        position=3)
    audio_input_stream_en_5_1 = StreamInput(
        input_id=sftp_input.id,
        input_path=SFTP_INPUT_PATH,
        selection_mode=SelectionMode.POSITION_ABSOLUTE,
        position=4)

    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

    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

    video_stream_240p = Stream(
        codec_configuration_id=video_codec_configuration_240p.id,
        input_streams=[video_input_stream],
        name='Sample Stream 240p')
    video_stream_240p = bitmovin.encodings.Stream.create(
        object_=video_stream_240p, encoding_id=encoding.id).resource

    audio_stream_cz_stereo = Stream(
        codec_configuration_id=audio_codec_configuration_stereo.id,
        input_streams=[audio_input_stream_cz_stereo],
        name='Sample Audio Stream CZ Stereo')
    audio_stream_cz_stereo = bitmovin.encodings.Stream.create(
        object_=audio_stream_cz_stereo, encoding_id=encoding.id).resource

    audio_stream_en_stereo = Stream(
        codec_configuration_id=audio_codec_configuration_stereo.id,
        input_streams=[audio_input_stream_en_stereo],
        name='Sample Audio Stream EN Stereo')
    audio_stream_en_stereo = bitmovin.encodings.Stream.create(
        object_=audio_stream_en_stereo, encoding_id=encoding.id).resource

    audio_stream_cz_5_1 = Stream(
        codec_configuration_id=audio_codec_configuration_5_1.id,
        input_streams=[audio_input_stream_cz_5_1],
        name='Sample Audio Stream CZ 5.1')
    audio_stream_cz_5_1 = bitmovin.encodings.Stream.create(
        object_=audio_stream_cz_5_1, encoding_id=encoding.id).resource

    audio_stream_en_5_1 = Stream(
        codec_configuration_id=audio_codec_configuration_5_1.id,
        input_streams=[audio_input_stream_en_5_1],
        name='Sample Audio Stream EN 5.1')
    audio_stream_en_5_1 = bitmovin.encodings.Stream.create(
        object_=audio_stream_en_5_1, 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)
    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)

    audio_muxing_stream_cz_stereo = MuxingStream(audio_stream_cz_stereo.id)
    audio_muxing_stream_en_stereo = MuxingStream(audio_stream_en_stereo.id)
    audio_muxing_stream_cz_5_1 = MuxingStream(audio_stream_cz_5_1.id)
    audio_muxing_stream_en_5_1 = MuxingStream(audio_stream_en_5_1.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

    video_muxing_480p_output = EncodingOutput(output_id=s3_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 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=s3_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 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=s3_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 Muxing 240p')
    video_muxing_240p = bitmovin.encodings.Muxing.FMP4.create(
        object_=video_muxing_240p, encoding_id=encoding.id).resource

    audio_muxing_output_en_stereo = EncodingOutput(
        output_id=s3_output.id,
        output_path=OUTPUT_BASE_PATH + 'audio/en_2_0/',
        acl=[acl_entry])
    audio_muxing_en_stereo = FMP4Muxing(
        segment_length=4,
        segment_naming='seg_%number%.m4s',
        init_segment_name='init.mp4',
        streams=[audio_muxing_stream_en_stereo],
        outputs=[audio_muxing_output_en_stereo],
        name='Sample Audio Muxing EN Stereo')
    audio_muxing_en_stereo = bitmovin.encodings.Muxing.FMP4.create(
        object_=audio_muxing_en_stereo, encoding_id=encoding.id).resource

    audio_muxing_output_cz_stereo = EncodingOutput(
        output_id=s3_output.id,
        output_path=OUTPUT_BASE_PATH + 'audio/cz_2_0/',
        acl=[acl_entry])
    audio_muxing_cz_stereo = FMP4Muxing(
        segment_length=4,
        segment_naming='seg_%number%.m4s',
        init_segment_name='init.mp4',
        streams=[audio_muxing_stream_cz_stereo],
        outputs=[audio_muxing_output_cz_stereo],
        name='Sample Audio Muxing CZ Stereo')
    audio_muxing_cz_stereo = bitmovin.encodings.Muxing.FMP4.create(
        object_=audio_muxing_cz_stereo, encoding_id=encoding.id).resource

    audio_muxing_output_en_5_1 = EncodingOutput(output_id=s3_output.id,
                                                output_path=OUTPUT_BASE_PATH +
                                                'audio/en_5_1/',
                                                acl=[acl_entry])
    audio_muxing_en_5_1 = FMP4Muxing(segment_length=4,
                                     segment_naming='seg_%number%.m4s',
                                     init_segment_name='init.mp4',
                                     streams=[audio_muxing_stream_en_5_1],
                                     outputs=[audio_muxing_output_en_5_1],
                                     name='Sample Audio Muxing EN 5.1')
    audio_muxing_en_5_1 = bitmovin.encodings.Muxing.FMP4.create(
        object_=audio_muxing_en_5_1, encoding_id=encoding.id).resource

    audio_muxing_output_cz_5_1 = EncodingOutput(output_id=s3_output.id,
                                                output_path=OUTPUT_BASE_PATH +
                                                'audio/cz_5_1/',
                                                acl=[acl_entry])
    audio_muxing_cz_5_1 = FMP4Muxing(segment_length=4,
                                     segment_naming='seg_%number%.m4s',
                                     init_segment_name='init.mp4',
                                     streams=[audio_muxing_stream_cz_5_1],
                                     outputs=[audio_muxing_output_cz_5_1],
                                     name='Sample Audio Muxing CZ 5.1')
    audio_muxing_cz_5_1 = bitmovin.encodings.Muxing.FMP4.create(
        object_=audio_muxing_cz_5_1, 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_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

    audio_adaptation_set_cz_2_0 = AudioAdaptationSet(lang='CZ 2.0')
    audio_adaptation_set_cz_2_0 = bitmovin.manifests.DASH.add_audio_adaptation_set(
        object_=audio_adaptation_set_cz_2_0,
        manifest_id=dash_manifest.id,
        period_id=period.id).resource

    fmp4_representation_audio_cz_2_0 = FMP4Representation(
        FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=audio_muxing_cz_stereo.id,
        segment_path='audio/cz_2_0/')
    fmp4_representation_audio_cz_2_0 = bitmovin.manifests.DASH.add_fmp4_representation(
        object_=fmp4_representation_audio_cz_2_0,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=audio_adaptation_set_cz_2_0.id).resource

    audio_adaptation_set_en_2_0 = AudioAdaptationSet(lang='EN 2.0')
    audio_adaptation_set_en_2_0 = bitmovin.manifests.DASH.add_audio_adaptation_set(
        object_=audio_adaptation_set_en_2_0,
        manifest_id=dash_manifest.id,
        period_id=period.id).resource

    fmp4_representation_audio_en_2_0 = FMP4Representation(
        FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=audio_muxing_en_stereo.id,
        segment_path='audio/en_2_0/')
    fmp4_representation_audio_en_2_0 = bitmovin.manifests.DASH.add_fmp4_representation(
        object_=fmp4_representation_audio_en_2_0,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=audio_adaptation_set_en_2_0.id).resource

    audio_adaptation_set_cz_5_1 = AudioAdaptationSet(lang='CZ 5.1')
    audio_adaptation_set_cz_5_1 = bitmovin.manifests.DASH.add_audio_adaptation_set(
        object_=audio_adaptation_set_cz_5_1,
        manifest_id=dash_manifest.id,
        period_id=period.id).resource

    fmp4_representation_audio_cz_5_1 = FMP4Representation(
        FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=audio_muxing_cz_5_1.id,
        segment_path='audio/cz_5_1/')
    fmp4_representation_audio_cz_5_1 = bitmovin.manifests.DASH.add_fmp4_representation(
        object_=fmp4_representation_audio_cz_5_1,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=audio_adaptation_set_cz_5_1.id).resource

    audio_adaptation_set_en_5_1 = AudioAdaptationSet(lang='EN 5.1')
    audio_adaptation_set_en_5_1 = bitmovin.manifests.DASH.add_audio_adaptation_set(
        object_=audio_adaptation_set_en_5_1,
        manifest_id=dash_manifest.id,
        period_id=period.id).resource

    fmp4_representation_audio_en_5_1 = FMP4Representation(
        FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=audio_muxing_en_5_1.id,
        segment_path='audio/en_5_1/')
    fmp4_representation_audio_en_5_1 = bitmovin.manifests.DASH.add_fmp4_representation(
        object_=fmp4_representation_audio_en_5_1,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=audio_adaptation_set_en_5_1.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():
    resource_response = bitmovin.inputs.RTMP.list()

    if not resource_response or \
       not resource_response.resource or \
       not isinstance(resource_response.resource, list) or \
       len(resource_response.resource) < 1:
        print('Could not find any RTMP inputs. Please contact support.')
        sys.exit(3)

    rtmp_input_id = resource_response.resource[0].id
    print('Found RTMP input with ID \'{}\''.format(rtmp_input_id))

    rtmp_input = bitmovin.inputs.RTMP.retrieve(id_=rtmp_input_id).resource

    video_input_stream = StreamInput(input_id=rtmp_input.id,
                                     input_path='live',
                                     position=0,
                                     selection_mode=SelectionMode.AUTO)
    audio_input_stream = StreamInput(input_id=rtmp_input.id,
                                     input_path='live',
                                     position=1,
                                     selection_mode=SelectionMode.AUTO)

    s3_output = S3Output(
        name='S3 Output',
        access_key=S3_OUTPUT_ACCESS_KEY,
        secret_key=S3_OUTPUT_SECRET_KEY,
        bucket_name=S3_OUTPUT_BUCKET_NAME,
    )
    s3_output = bitmovin.outputs.S3.create(s3_output).resource

    encoding = Encoding(name='Test Live Stream',
                        encoder_version=ENCODER_VERSION,
                        cloud_region=CloudRegion.AWS_EU_WEST_1)
    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ)
    manifest_output = EncodingOutput(output_id=s3_output.id,
                                     output_path=OUTPUT_BASE_PATH,
                                     acl=[acl_entry])

    dash_manifest = DashManifest(
        name='Sample DASH Manifest Live',
        manifest_name='stream.mpd',
        outputs=[manifest_output],
        description='Bitmovin Python Test Live 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

    hls_manifest = HlsManifest(name='Sample HLS Manifest',
                               manifest_name='stream.m3u8',
                               outputs=[manifest_output])
    hls_manifest = bitmovin.manifests.HLS.create(object_=hls_manifest).resource

    createH264Rendition(encoding, dash_manifest, period, video_adaptation_set,
                        hls_manifest, 'audio', video_input_stream, s3_output,
                        'video/1080p', 4800000, VIDEO_FRAME_RATE, 1920, 1080,
                        H264Profile.HIGH)

    createH264Rendition(encoding, dash_manifest, period, video_adaptation_set,
                        hls_manifest, 'audio', video_input_stream, s3_output,
                        'video/720p', 2400000, VIDEO_FRAME_RATE, 1280, 720,
                        H264Profile.HIGH)

    createH264Rendition(encoding, dash_manifest, period, video_adaptation_set,
                        hls_manifest, 'audio', video_input_stream, s3_output,
                        'video/480p', 1200000, VIDEO_FRAME_RATE, 854, 480,
                        H264Profile.HIGH)

    createH264Rendition(encoding, dash_manifest, period, video_adaptation_set,
                        hls_manifest, 'audio', video_input_stream, s3_output,
                        'video/360p', 800000, VIDEO_FRAME_RATE, 640, 360,
                        H264Profile.HIGH)

    createH264Rendition(encoding, dash_manifest, period, video_adaptation_set,
                        hls_manifest, 'audio', video_input_stream, s3_output,
                        'video/240p', 400000, VIDEO_FRAME_RATE, 426, 240,
                        H264Profile.HIGH)

    createAACRendition(encoding, dash_manifest, period, audio_adaptation_set,
                       hls_manifest, 'audio', audio_input_stream, s3_output,
                       'audio/128kbps', 128000, AUDIO_SAMPLE_RATE)

    live_dash_manifest = LiveDashManifest(
        manifest_id=dash_manifest.id,
        time_shift=TIMESHIFT_IN_SECONDS,
        live_edge_offset=DASH_LIVE_EDGE_OFFSET_IN_SECONDS)

    live_hls_manifest = LiveHlsManifest(manifest_id=hls_manifest.id,
                                        time_shift=TIMESHIFT_IN_SECONDS)

    live_stream_configuration = LiveStreamConfiguration(
        stream_key=STREAM_KEY,
        live_dash_manifests=[live_dash_manifest],
        live_hls_manifests=[live_hls_manifest])

    resource_response = bitmovin.encodings.Encoding.start_live(
        encoding_id=encoding.id,
        live_stream_configuration=live_stream_configuration)

    bitmovin.encodings.Encoding.wait_until_running(
        encoding_id=resource_response.resource.id)

    live_details = None
    retry = 0

    while retry < LIVE_STREAM_INFORMATION_FETCH_MAX_RETRIES:
        try:
            live_details = bitmovin.encodings.Encoding.retrieve_live(
                encoding_id=resource_response.resource.id)
            break
        except BitmovinApiError as bitmovin_api_error:
            if bitmovin_api_error.response.data.code != ERROR_CODE_LIVE_STREAM_NOT_READY:
                sys.exit(2)
            print(
                'Live stream is not ready yet. Retrying to fetch live stream information in {} seconds...'
                .format(LIVE_STREAM_INFORMATION_FETCH_RETRY_INTERVAL))
            retry += 1
            time.sleep(LIVE_STREAM_INFORMATION_FETCH_RETRY_INTERVAL)

    if live_details is not None:
        print_live_stream_details(encoding_id=encoding.id,
                                  live_stream_details=live_details.resource)
    else:
        print('Unable to fetch live stream details!')
        sys.exit(1)
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)

    # Create a SFTP input. This resource is then used as base path for the input file.
    input_ = SFTPInput(host=SFTP_INPUT_HOST,
                       username=SFTP_INPUT_USERNAME,
                       password=SFTP_INPUT_PASSWORD,
                       name='SFTP Input')

    input_ = bitmovin.inputs.SFTP.create(object_=input_).resource

    # Create a SFTP output. This will be used as target storage for the muxings, sprites and manifests
    output = SFTPOutput(host=SFTP_OUTPUT_HOST,
                        username=SFTP_OUTPUT_USERNAME,
                        password=SFTP_OUTPUT_PASSWORD,
                        name='SFTP Output')
    output = bitmovin.outputs.SFTP.create(output).resource

    # Create an Encoding. This will run in AWS_AP_SOUTHEAST_1. This is the base entity used to configure the encoding.
    encoding = Encoding(
        name='Encoding with multiple audio and stream condition',
        cloud_region=ENCODING_CLOUD_REGION)
    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    # create video/audio input streams
    video_input_stream = make_stream_input(
        input_=input_, position=0, selection_mode=SelectionMode.VIDEO_RELATIVE)

    audio_input_streams = [
        make_stream_input(input_=input_, position=i)
        for i in range(NUMBER_OF_AUDIO_CHANNELS_TO_CREATE)
    ]

    # create video/audio configurations
    video_encoding_configs = [
        make_video_encoding_config(bitmovin=bitmovin, profile=video_profile)
        for video_profile in VIDEO_ENCODING_PROFILES
    ]

    audio_encoding_configs = [
        make_audio_encoding_config(bitmovin=bitmovin, profile=audio_profile)
        for audio_profile in AUDIO_ENCODING_PROFILES
    ]

    # input stream audio conditions
    audio_stream_condition = Condition(attribute="INPUTSTREAM",
                                       operator="==",
                                       value="TRUE")

    # create video streams
    for video_config in video_encoding_configs:
        video_stream = Stream(codec_configuration_id=video_config['codec'].id,
                              input_streams=[video_input_stream])
        video_stream = bitmovin.encodings.Stream.create(
            object_=video_stream, encoding_id=encoding.id).resource
        video_config['stream'] = video_stream

    # create audio streams
    for audio_config in audio_encoding_configs:
        for audio_stream_input in audio_input_streams:
            audio_stream = Stream(
                codec_configuration_id=audio_config['codec'].id,
                input_streams=[audio_stream_input],
                conditions=audio_stream_condition)
            audio_stream = bitmovin.encodings.Stream.create(
                object_=audio_stream, encoding_id=encoding.id).resource
            audio_config['streams'].append(audio_stream)

    # create muxings for video
    for video_config in video_encoding_configs:
        make_video_muxings(bitmovin=bitmovin,
                           encoding=encoding,
                           video_config=video_config,
                           output=output)

    # create muxings for audio
    for audio_config in audio_encoding_configs:
        for stream_number, stream in enumerate(audio_config['streams']):
            make_audio_muxings(bitmovin=bitmovin,
                               encoding=encoding,
                               audio_config=audio_config,
                               stream=stream,
                               output=output,
                               stream_number=stream_number)

    # start the encoding process and wait until finished
    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:")
        pprint(bitmovin_error)
        exit(-1)

    # retrieve the input stream analysis to get the exact number of audio streams encoded.
    number_of_audio_streams, audio_stream_languages = get_audio_input_stream_analysis(
        bitmovin=bitmovin,
        encoding=encoding,
        stream=audio_encoding_configs[0]['streams'][0])

    # this holds the manifests to be started later.
    manifests_to_start = []

    # create the manifests according to MANIFESTS const.
    for manifest_spec in MANIFESTS:
        manifest_type = manifest_spec['type']

        if manifest_type == DASH:
            manifests_to_start.append(
                dict(type=manifest_type,
                     object_=make_dash_manifest(
                         bitmovin=bitmovin,
                         manifest_spec=manifest_spec,
                         encoding=encoding,
                         output=output,
                         video_encoding_configs=video_encoding_configs,
                         audio_encoding_configs=audio_encoding_configs,
                         number_of_audio_streams=number_of_audio_streams,
                         audio_stream_languages=audio_stream_languages)))
        elif manifest_type == HLS:
            manifests_to_start.append(
                dict(type=manifest_type,
                     object_=make_hls_manifest(
                         bitmovin=bitmovin,
                         manifest_spec=manifest_spec,
                         encoding=encoding,
                         output=output,
                         video_encoding_configs=video_encoding_configs,
                         audio_encoding_configs=audio_encoding_configs,
                         number_of_audio_streams=number_of_audio_streams,
                         audio_stream_languages=audio_stream_languages)))
        else:
            print("Unknown manifest type {}".format(manifest_type))
            exit(-1)

    # trigger all manifest creations
    for manifest_spec in manifests_to_start:
        manifest_type = manifest_spec['type']
        manifest = manifest_spec['object_']

        manifest_manager = bitmovin.manifests.DASH if manifest_type == DASH else bitmovin.manifests.HLS
        manifest_manager.start(manifest_id=manifest.id)

    # wait until all manifest creations finish
    for manifest_spec in manifests_to_start:
        manifest_type = manifest_spec['type']
        manifest = manifest_spec['object_']

        manifest_manager = bitmovin.manifests.DASH if manifest_type == DASH else bitmovin.manifests.HLS

        try:
            manifest_manager.wait_until_finished(manifest_id=manifest.id)
        except BitmovinError as bitmovin_error:
            print(
                "Exception occurred while waiting for HLS manifest creation to finish: {}"
                .format(bitmovin_error))
Esempio n. 13
0
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME,
                       cloud_region=AWSCloudRegion.US_EAST_1,
                       name='Sample S3 Output')
    s3_input = bitmovin.inputs.S3.create(s3_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 encoding',
                        cloud_region=CloudRegion.AWS_US_EAST_1)

    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    video_codec_configuration_460p = H264CodecConfiguration(
        name='example_video_codec_configuration_460p',
        bitrate=2000000,
        rate=23.976,
        width=852,
        height=460,
        profile=H264Profile.HIGH)
    video_codec_configuration_460p = bitmovin.codecConfigurations.H264.create(
        video_codec_configuration_460p).resource

    video_codec_configuration_276p = H264CodecConfiguration(
        name='example_video_codec_configuration_276p',
        bitrate=1000000,
        rate=23.976,
        width=512,
        height=276,
        profile=H264Profile.HIGH)
    video_codec_configuration_276p = bitmovin.codecConfigurations.H264.create(
        video_codec_configuration_276p).resource

    video_codec_configuration_80p = H264CodecConfiguration(
        name='example_video_codec_configuration_80p',
        bitrate=186534,
        rate=23.976,
        width=144,
        height=80,
        profile=H264Profile.HIGH)
    video_codec_configuration_80p = bitmovin.codecConfigurations.H264.create(
        video_codec_configuration_80p).resource

    audio_codec_configuration_stereo = AACCodecConfiguration(
        name='example_audio_codec_configuration_stereo',
        bitrate=128000,
        rate=48000)
    audio_codec_configuration_stereo = \
        bitmovin.codecConfigurations.AAC.create(audio_codec_configuration_stereo).resource

    video_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)

    audio_input_stream_en_stereo = StreamInput(
        input_id=s3_input.id,
        input_path=S3_INPUT_PATH,
        selection_mode=SelectionMode.AUTO)

    video_stream_460p = Stream(
        codec_configuration_id=video_codec_configuration_460p.id,
        input_streams=[video_input_stream],
        name='Sample Stream 460p')
    video_stream_460p = bitmovin.encodings.Stream.create(
        object_=video_stream_460p, encoding_id=encoding.id).resource

    video_stream_276p = Stream(
        codec_configuration_id=video_codec_configuration_276p.id,
        input_streams=[video_input_stream],
        name='Sample Stream 276p')
    video_stream_276p = bitmovin.encodings.Stream.create(
        object_=video_stream_276p, encoding_id=encoding.id).resource

    video_stream_80p = Stream(
        codec_configuration_id=video_codec_configuration_80p.id,
        input_streams=[video_input_stream],
        name='Sample Stream 80p')
    video_stream_80p = bitmovin.encodings.Stream.create(
        object_=video_stream_80p, encoding_id=encoding.id).resource

    audio_stream_en_stereo = Stream(
        codec_configuration_id=audio_codec_configuration_stereo.id,
        input_streams=[audio_input_stream_en_stereo],
        name='Sample Audio Stream EN Stereo')
    audio_stream_en_stereo = bitmovin.encodings.Stream.create(
        object_=audio_stream_en_stereo, encoding_id=encoding.id).resource

    acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ)

    video_muxing_stream_460p = MuxingStream(video_stream_460p.id)
    video_muxing_stream_276p = MuxingStream(video_stream_276p.id)
    video_muxing_stream_80p = MuxingStream(video_stream_80p.id)

    audio_muxing_stream_en_stereo = MuxingStream(audio_stream_en_stereo.id)

    widevine_drm = CENCWidevineEntry(pssh=CENC_WIDEVINE_PSSH)
    play_ready_drm = CENCPlayReadyEntry(la_url=CENC_PLAYREADY_LA_URL)
    marlin_drm = {}

    video_muxing_460p_output = EncodingOutput(output_id=s3_output.id,
                                              output_path=OUTPUT_BASE_PATH +
                                              'video/460p/',
                                              acl=[acl_entry])
    video_muxing_460p = FMP4Muxing(segment_length=4,
                                   segment_naming='seg_%number%.m4s',
                                   init_segment_name='init.mp4',
                                   streams=[video_muxing_stream_460p],
                                   name='Sample Muxing 460p')
    video_muxing_460p = bitmovin.encodings.Muxing.FMP4.create(
        object_=video_muxing_460p, encoding_id=encoding.id).resource
    cenc_460p = CENCDRMResource(key=CENC_KEY,
                                kid=CENC_KID,
                                widevine=widevine_drm,
                                play_ready=play_ready_drm,
                                marlin=marlin_drm,
                                outputs=[video_muxing_460p_output],
                                name='test cenc')
    cenc_460p = bitmovin.encodings.Muxing.FMP4.DRM.CENC.create(
        object_=cenc_460p,
        encoding_id=encoding.id,
        muxing_id=video_muxing_460p.id).resource

    video_muxing_276p_output = EncodingOutput(output_id=s3_output.id,
                                              output_path=OUTPUT_BASE_PATH +
                                              'video/276p/',
                                              acl=[acl_entry])
    video_muxing_276p = FMP4Muxing(segment_length=4,
                                   segment_naming='seg_%number%.m4s',
                                   init_segment_name='init.mp4',
                                   streams=[video_muxing_stream_276p],
                                   name='Sample Muxing 276p')
    video_muxing_276p = bitmovin.encodings.Muxing.FMP4.create(
        object_=video_muxing_276p, encoding_id=encoding.id).resource
    cenc_276p = CENCDRMResource(key=CENC_KEY,
                                kid=CENC_KID,
                                widevine=widevine_drm,
                                play_ready=play_ready_drm,
                                marlin=marlin_drm,
                                outputs=[video_muxing_276p_output],
                                name='test cenc')
    cenc_276p = bitmovin.encodings.Muxing.FMP4.DRM.CENC.create(
        object_=cenc_276p,
        encoding_id=encoding.id,
        muxing_id=video_muxing_276p.id).resource

    video_muxing_80p_output = EncodingOutput(output_id=s3_output.id,
                                             output_path=OUTPUT_BASE_PATH +
                                             'video/80p/',
                                             acl=[acl_entry])
    video_muxing_80p = FMP4Muxing(segment_length=4,
                                  segment_naming='seg_%number%.m4s',
                                  init_segment_name='init.mp4',
                                  streams=[video_muxing_stream_80p],
                                  name='Sample Muxing 80p')
    cenc_80p = CENCDRMResource(key=CENC_KEY,
                               kid=CENC_KID,
                               widevine=widevine_drm,
                               play_ready=play_ready_drm,
                               marlin=marlin_drm,
                               outputs=[video_muxing_80p_output],
                               name='test cenc')
    video_muxing_80p = bitmovin.encodings.Muxing.FMP4.create(
        object_=video_muxing_80p, encoding_id=encoding.id).resource
    cenc_80p = bitmovin.encodings.Muxing.FMP4.DRM.CENC.create(
        object_=cenc_80p,
        encoding_id=encoding.id,
        muxing_id=video_muxing_80p.id).resource

    audio_muxing_output_en_stereo = EncodingOutput(
        output_id=s3_output.id,
        output_path=OUTPUT_BASE_PATH + 'audio/en_2_0/',
        acl=[acl_entry])
    audio_muxing_en_stereo = FMP4Muxing(
        segment_length=4,
        segment_naming='seg_%number%.m4s',
        init_segment_name='init.mp4',
        streams=[audio_muxing_stream_en_stereo],
        name='Sample Audio Muxing EN Stereo')
    audio_muxing_en_stereo = bitmovin.encodings.Muxing.FMP4.create(
        object_=audio_muxing_en_stereo, encoding_id=encoding.id).resource
    cenc_audio = CENCDRMResource(key=CENC_KEY,
                                 kid=CENC_KID,
                                 widevine=widevine_drm,
                                 play_ready=play_ready_drm,
                                 marlin=marlin_drm,
                                 outputs=[audio_muxing_output_en_stereo],
                                 name='test cenc')
    cenc_audio = bitmovin.encodings.Muxing.FMP4.DRM.CENC.create(
        object_=cenc_audio,
        encoding_id=encoding.id,
        muxing_id=audio_muxing_en_stereo.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_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

    video_content_protection = ContentProtection(
        encoding_id=encoding.id,
        muxing_id=video_muxing_460p.id,
        drm_id=cenc_460p.id)
    bitmovin.manifests.DASH.add_content_protection_to_adaptionset(
        object_=video_content_protection,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=video_adaptation_set.id)
    fmp4_representation_460p = DRMFMP4Representation(
        type=FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=video_muxing_460p.id,
        drm_id=cenc_460p.id,
        segment_path='video/460p/')
    fmp4_representation_460p = bitmovin.manifests.DASH.add_drm_fmp4_representation(
        object_=fmp4_representation_460p,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=video_adaptation_set.id).resource

    fmp4_representation_276p = DRMFMP4Representation(
        type=FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=video_muxing_276p.id,
        drm_id=cenc_276p.id,
        segment_path='video/276p/')
    fmp4_representation_276p = bitmovin.manifests.DASH.add_drm_fmp4_representation(
        object_=fmp4_representation_276p,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=video_adaptation_set.id).resource

    fmp4_representation_80p = DRMFMP4Representation(
        type=FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=video_muxing_80p.id,
        drm_id=cenc_80p.id,
        segment_path='video/80p/')
    fmp4_representation_80p = bitmovin.manifests.DASH.add_drm_fmp4_representation(
        object_=fmp4_representation_80p,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=video_adaptation_set.id).resource

    audio_adaptation_set_en_2_0 = AudioAdaptationSet(lang='EN 2.0')
    audio_adaptation_set_en_2_0 = bitmovin.manifests.DASH.add_audio_adaptation_set(
        object_=audio_adaptation_set_en_2_0,
        manifest_id=dash_manifest.id,
        period_id=period.id).resource

    audio_content_protection = ContentProtection(
        encoding_id=encoding.id,
        muxing_id=audio_muxing_en_stereo.id,
        drm_id=cenc_audio.id)
    bitmovin.manifests.DASH.add_content_protection_to_adaptionset(
        object_=audio_content_protection,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=audio_adaptation_set_en_2_0.id)
    drm_cenc_fmp4_representation_audio_en_2_0 = DRMFMP4Representation(
        type=FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=audio_muxing_en_stereo.id,
        drm_id=cenc_audio.id,
        segment_path='audio/en_2_0/')
    drm_cenc_fmp4_representation_audio_en_2_0 = bitmovin.manifests.DASH.add_drm_fmp4_representation(
        object_=drm_cenc_fmp4_representation_audio_en_2_0,
        manifest_id=dash_manifest.id,
        period_id=period.id,
        adaptationset_id=audio_adaptation_set_en_2_0.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 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))
Esempio n. 15
0
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    generic_s3_input = GenericS3Input(access_key=GENERIC_S3_INPUT_ACCESSKEY,
                                      secret_key=GENERIC_S3_INPUT_SECRETKEY,
                                      bucket_name=GENERIC_S3_INPUT_BUCKETNAME,
                                      name='Sample GENERIC_S3 Input',
                                      host=GENERIC_S3_INPUT_HOST,
                                      port=GENERIC_S3_INPUT_PORT)

    generic_s3_output = GenericS3Output(access_key=GENERIC_S3_OUTPUT_ACCESSKEY,
                                        secret_key=GENERIC_S3_OUTPUT_SECRETKEY,
                                        bucket_name=GENERIC_S3_OUTPUT_BUCKETNAME,
                                        name='Sample GENERIC_S3 Output',
                                        host=GENERIC_S3_OUTPUT_HOST,
                                        port=GENERIC_S3_OUTPUT_PORT)

    generic_s3_output = bitmovin.outputs.GenericS3.create(generic_s3_output).resource
    generic_s3_input = bitmovin.inputs.GenericS3.create(generic_s3_input).resource

    encoding = Encoding(name='example encoding',
                        cloud_region=CLOUD_REGION,
                        infrastructure_id=INFRASTRUCTURE_ID)

    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=generic_s3_input.id,
                                     input_path=GENERIC_S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)
    audio_input_stream = StreamInput(input_id=generic_s3_input.id,
                                     input_path=GENERIC_S3_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=generic_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=generic_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=generic_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=generic_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))
Esempio n. 16
0
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 S3 input. This resource is then used as base bucket for the input file.
    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME,
                       name='S3 Input')
    s3_input = bitmovin.inputs.S3.create(s3_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

    video_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)
    audio_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)

    acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ)

    encoding_analysis = Encoding(name='Per title encoding analysis',
                                 cloud_region=CloudRegion.AWS_EU_WEST_1)
    encoding_analysis = bitmovin.encodings.Encoding.create(
        encoding_analysis).resource

    # Do analysis encoding to get the complexity factor
    encoding_analysis = bitmovin.encodings.Encoding.create(
        encoding_analysis).resource
    encoding_analysis_config = H264CodecConfiguration(
        name='H264 Per Title Analysis Configuration',
        bitrate=None,
        crf=23.0,
        height=360,
        rate=None,
        profile=H264Profile.MAIN)
    encoding_analysis_config = bitmovin.codecConfigurations.H264.create(
        encoding_analysis_config).resource

    encoding_analysis_stream = Stream(
        codec_configuration_id=encoding_analysis_config.id,
        input_streams=[video_input_stream],
        name='Per Title Analysis Stream')
    encoding_analysis_stream = bitmovin.encodings.Stream.create(
        object_=encoding_analysis_stream,
        encoding_id=encoding_analysis.id).resource

    encoding_analysis_output = EncodingOutput(output_id=s3_output.id,
                                              output_path=OUTPUT_BASE_PATH +
                                              'video/quality_analysis/',
                                              acl=[acl_entry])

    encoding_analysis_muxing_stream = MuxingStream(encoding_analysis_stream.id)
    encoding_analysis_muxing = FMP4Muxing(
        segment_length=4,
        segment_naming='seg_%number%.m4s',
        init_segment_name='init.mp4',
        streams=[encoding_analysis_muxing_stream],
        outputs=[encoding_analysis_output],
        name='Per Title Analysis Muxing')
    encoding_analysis_muxing = bitmovin.encodings.Muxing.FMP4.create(
        object_=encoding_analysis_muxing,
        encoding_id=encoding_analysis.id).resource

    bitmovin.encodings.Encoding.start(encoding_id=encoding_analysis.id)

    try:
        bitmovin.encodings.Encoding.wait_until_finished(
            encoding_id=encoding_analysis.id, check_interval=5)
    except BitmovinError as bitmovin_error:
        print('Exception occurred while waiting for encoding to finish: {}'.
              format(bitmovin_error))
        exit(-1)

    encoding_analysis_muxing = bitmovin.encodings.Muxing.FMP4.retrieve(
        encoding_id=encoding_analysis.id,
        muxing_id=encoding_analysis_muxing.id).resource

    # Calculate and saturate the complexity factor
    complexity_factor = encoding_analysis_muxing.avgBitrate / MEDIAN_BITRATE

    if complexity_factor > MAX_COMPLEXITY_FACTOR:
        complexity_factor = MAX_COMPLEXITY_FACTOR
    elif complexity_factor < MIN_COMPLEXITY_FACTOR:
        complexity_factor = MIN_COMPLEXITY_FACTOR

    print('Got complexity factor of: {:0.2f}'.format(complexity_factor))

    print('Updating encoding profile from:')
    pprint(encoding_profiles)
    print('To')
    # Multiply every bitrate with the complexity factor
    for profile in encoding_profiles:
        profile['bitrate'] = int(profile['bitrate'] * complexity_factor)
    pprint(encoding_profiles)

    # Create an Encoding. This will run in AWS_AP_SOUTHEAST_1. This is the base entity used to configure the encoding.
    encoding = Encoding(name='Per title encoding',
                        cloud_region=CloudRegion.AWS_EU_WEST_1)

    encoding = bitmovin.encodings.Encoding.create(encoding).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)
        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.
    audio_codec_configuration = AACCodecConfiguration(
        name='AAC Codec Configuration', bitrate=128000, rate=48000)
    audio_codec_configuration = bitmovin.codecConfigurations.AAC.create(
        audio_codec_configuration).resource

    # 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

    # 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/dash/{}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_dash/',
                                         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

    # Create TS 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/hls/{}p_{}k/'.format(encoding_profile.get('height'),
                                        encoding_profile.get('bitrate')),
            acl=[acl_entry])
        video_muxing = TSMuxing(segment_length=4,
                                segment_naming='seg_%number%.ts',
                                streams=[video_muxing_stream],
                                outputs=[video_muxing_output],
                                name='TS Muxing {}p_{}k'.format(
                                    encoding_profile.get('height'),
                                    encoding_profile.get('bitrate')))
        encoding_config['ts_muxing'] = bitmovin.encodings.Muxing.TS.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_hls/',
                                         acl=[acl_entry])
    audio_ts_muxing = TSMuxing(segment_length=4,
                               segment_naming='seg_%number%.ts',
                               streams=[audio_muxing_stream],
                               outputs=[audio_muxing_output],
                               name='Audio TS Muxing')
    audio_ts_muxing = bitmovin.encodings.Muxing.TS.create(
        object_=audio_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, check_interval=5)
    except BitmovinError as bitmovin_error:
        print('Exception occurred while waiting for encoding to finish: {}'.
              format(bitmovin_error))
        exit(-1)

    # 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/dash/{}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_dash/')
    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_hls/',
                             encoding_id=encoding.id,
                             stream_id=audio_stream.id,
                             muxing_id=audio_ts_muxing.id,
                             language='en',
                             uri='audio.m3u8')
    audio_media = bitmovin.manifests.HLS.AudioMedia.create(
        manifest_id=hls_manifest.id, object_=audio_media).resource

    # 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('ts_muxing')
        variant_stream = VariantStream(
            audio='audio',
            closed_captions='NONE',
            segment_path='video/hls/{}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)
        variant_stream = bitmovin.manifests.HLS.VariantStream.create(
            manifest_id=hls_manifest.id, object_=variant_stream).resource

    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))
        exit(-1)

    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))
        exit(-1)
Esempio n. 18
0
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, tenant_org_id=ORG_ID)

    # Create an HTTP Input
    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME)

    s3_input = bitmovin.inputs.S3.create(s3_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

    acl_entry = ACLEntry(permission=ACLPermission.PRIVATE)

    # Create an Encoding. This is the base entity used to configure the encoding.
    encoding = Encoding(name='Python sample for Broadcast TS encoding',
                        cloud_region=CloudRegion.AUTO)

    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    # Create an H264 configuration for HD video
    hd_video_config = H264CodecConfiguration(
        name='HD_video_config',
        width=1920,
        height=1080,
        bitrate=6_000_000,
        bufsize=7_000_000,
        max_bitrate=7_000_000,
        profile=H264Profile.HIGH,
        cabac=True,
        bframes=3,
        b_adapt=BAdapt.FULL,
        sub_me=H264SubMe.RD_REF_IP,
        motion_estimation_method=H264MotionEstimationMethod.UMH,
        qp_max=51,
        qp_min=1,
        ref_frames=2,
        level=H264Level.L4_1,
        min_gop=1,
        max_gop=25,
        open_gop=True,
        interlaceMode=H264InterlaceMode.TOP_FIELD_FIRST,
        slices=1,
        rc_lookahead=60,
        partitions=[
            H264Partition.I4X4, H264Partition.I8X8, H264Partition.P8X8,
            H264Partition.B8X8
        ],
        rate=25.0,
        b_pyramid=H264BPyramid.NONE,
        nal_hrd=H264NalHrd.VBR,
        trellis=H264Trellis.ENABLED_ALL,
        sample_aspect_ratio_numerator=1,
        sample_aspect_ratio_denominator=1,
        color_config=ColorConfig(input_color_range=InputColorRange.MPEG,
                                 color_space=ColorSpace.BT709,
                                 color_primaries=ColorPrimaries.BT709,
                                 color_transfer=ColorTransfer.BT709,
                                 color_range=ColorRange.MPEG,
                                 chroma_location=ChromaLocation.LEFT))
    hd_video_config = bitmovin.codecConfigurations.H264.create(
        hd_video_config).resource

    # Create an MP2 configuration for audio
    audio_codec_configuration = MP2CodecConfiguration(
        name='MP2 Codec Configuration',
        bitrate=192_000,
        rate=48_000,
        channel_layout=MP2ChannelLayout.CL_STEREO)

    audio_codec_configuration = bitmovin.codecConfigurations.MP2.create(
        audio_codec_configuration).resource

    # Define input streams for audio and video
    video_input_stream = StreamInput(
        input_id=s3_input.id,
        input_path=S3_INPUT_PATH,
        selection_mode=SelectionMode.VIDEO_RELATIVE,
        position=0)

    audio_input_stream_1 = StreamInput(
        input_id=s3_input.id,
        input_path=S3_INPUT_PATH,
        selection_mode=SelectionMode.AUDIO_RELATIVE,
        position=0)

    # Create output stream configuration
    video_stream = Stream(codec_configuration_id=hd_video_config.id,
                          input_streams=[video_input_stream],
                          name='Video Stream')

    video_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_1],
                          name='Audio Stream')

    audio_stream = bitmovin.encodings.Stream.create(
        object_=audio_stream, encoding_id=encoding.id).resource

    # Create broadcast TS muxing
    video_muxing_stream_broadcast_ts = MuxingStream(video_stream.id)
    audio_muxing_stream_broadcast_ts = MuxingStream(audio_stream.id)

    broadcast_ts_muxing_output = EncodingOutput(output_id=s3_output.id,
                                                output_path=OUTPUT_BASE_PATH,
                                                acl=[acl_entry])

    broadcast_ts_transport_configuration = BroadcastTsTransportConfiguration(
        muxrate=8_000_000,
        stop_on_error=False,
        pat_repetition_rate_per_sec=8.0,
        pmt_repetition_rate_per_sec=8.0,
        prevent_empty_adaptation_fields_in_video=True)

    broadcast_ts_program_configuration = BroadcastTsProgramConfiguration(
        program_number=10,
        pid_for_pmt=101,
        insert_program_clock_ref_on_pes=True)

    broadcast_ts_video_stream_configuration = BroadcastTsVideoStreamConfiguration(
        stream_id=video_stream.id,
        max_decode_delay=90_000,
        packet_identifier=481,
        start_with_discontinuity_indicator=True,
        align_pes=True,
        set_rai_on_au=SetRaiOnAu.ALL_PES_PACKETS,
        insert_access_unit_delimiter_in_avc=True,
    )

    broadcast_ts_audio_stream_configuration = BroadcastTsAudioStreamConfiguration(
        stream_id=audio_stream.id,
        packet_identifier=2005,
        start_with_discontinuity_indicator=True,
        align_pes=True,
        language='eng')

    broadcast_ts_muxing_configuration = BroadcastTsMuxingConfiguration(
        transport=broadcast_ts_transport_configuration,
        program=broadcast_ts_program_configuration,
        video_streams=[broadcast_ts_video_stream_configuration],
        audio_streams=[broadcast_ts_audio_stream_configuration])

    broadcast_ts_muxing = BroadcastTsMuxing(
        filename=OUTPUT_FILE_NAME,
        segment_length=30,
        streams=[
            video_muxing_stream_broadcast_ts, audio_muxing_stream_broadcast_ts
        ],
        outputs=[broadcast_ts_muxing_output],
        name='Broadcast TS Muxing',
        configuration=broadcast_ts_muxing_configuration)

    bitmovin.encodings.Muxing.BroadcastTS.create(object_=broadcast_ts_muxing,
                                                 encoding_id=encoding.id)

    # Start the encoding
    start_encoding_request = StartEncodingRequest(
        encoding_mode=EncodingMode.STANDARD,
        trimming=StartEncodingTrimming(start_pic_timing='', end_pic_timing=''))
    bitmovin.encodings.Encoding.start(
        encoding_id=encoding.id, start_encoding_request=start_encoding_request)

    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('OUTPUT FILE: https://{}.s3.amazonaws.com/{}{}'.format(
        S3_OUTPUT_BUCKETNAME, OUTPUT_BASE_PATH, OUTPUT_FILE_NAME))
Esempio n. 20
0
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    zixi_input = ZixiInput(host=ZIXI_HOST,
                           port=ZIXI_PORT,
                           stream=ZIXI_STREAM,
                           password=ZIXI_PASSWORD)

    zixi_input = bitmovin.inputs.Zixi.create(zixi_input).resource

    s3_output = S3Output(access_key=S3_OUTPUT_ACCESS_KEY,
                         secret_key=S3_OUTPUT_SECRET_KEY,
                         bucket_name=S3_OUTPUT_BUCKET_NAME,
                         name='Sample S3 Output')
    s3_output = bitmovin.outputs.S3.create(s3_output).resource

    encoding = Encoding(name='example python live stream encoding',
                        encoder_version=ENCODER_VERSION,
                        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_360p = H264CodecConfiguration(
        name='example_video_codec_configuration_720p',
        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

    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=zixi_input.id,
                                     input_path='live',
                                     position=0,
                                     selection_mode=SelectionMode.AUTO)
    audio_input_stream = StreamInput(input_id=zixi_input.id,
                                     input_path='live',
                                     position=1,
                                     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

    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

    video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id)
    video_muxing_stream_720p = MuxingStream(video_stream_720p.id)
    video_muxing_stream_360p = MuxingStream(video_stream_360p.id)
    audio_muxing_stream = MuxingStream(audio_stream.id)

    acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ)

    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

    video_muxing_360p_output = EncodingOutput(output_id=s3_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 Muxing 360p')
    video_muxing_360p = bitmovin.encodings.Muxing.FMP4.create(
        object_=video_muxing_360p, encoding_id=encoding.id).resource

    audio_muxing_output = EncodingOutput(output_id=s3_output.id,
                                         output_path=OUTPUT_BASE_PATH +
                                         'audio/128k',
                                         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

    live_stream_configuration = LiveStreamConfiguration(stream_key=STREAM_KEY)
    resource_response = bitmovin.encodings.Encoding.start_live(
        encoding_id=encoding.id,
        live_stream_configuration=live_stream_configuration)

    bitmovin.encodings.Encoding.wait_until_running(
        encoding_id=resource_response.resource.id)

    print(
        'Your live encoding is running and pulling from your zixi receiver/broadcaster'
    )
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME,
                       name='Sample S3 Output')
    s3_input = bitmovin.inputs.S3.create(s3_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='hls fairplay example encoding - {}'.format(date_component))
    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    video_codec_configuration_480p = H264CodecConfiguration(name='example_video_codec_configuration_480p',
                                                            bitrate=1200000,
                                                            rate=None,
                                                            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=None,
                                                            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=None,
                                                            height=240,
                                                            profile=H264Profile.HIGH)
    video_codec_configuration_240p = bitmovin.codecConfigurations.H264.create(video_codec_configuration_240p).resource

    audio_codec_configuration_stereo = AACCodecConfiguration(name='example_audio_codec_configuration_stereo',
                                                             bitrate=128000,
                                                             rate=48000)
    audio_codec_configuration_stereo = bitmovin.codecConfigurations.AAC.create(
        audio_codec_configuration_stereo).resource

    video_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)

    audio_input_stream_en_stereo = StreamInput(input_id=s3_input.id,
                                               input_path=S3_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

    video_stream_240p = Stream(codec_configuration_id=video_codec_configuration_240p.id,
                               input_streams=[video_input_stream],
                               name='Sample Stream 240p')
    video_stream_240p = bitmovin.encodings.Stream.create(object_=video_stream_240p,
                                                         encoding_id=encoding.id).resource

    audio_stream_en_stereo = Stream(codec_configuration_id=audio_codec_configuration_stereo.id,
                                    input_streams=[audio_input_stream_en_stereo],
                                    name='Sample Audio Stream EN Stereo')
    audio_stream_en_stereo = bitmovin.encodings.Stream.create(object_=audio_stream_en_stereo,
                                                              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)
    video_muxing_stream_240p = MuxingStream(video_stream_240p.id)

    audio_muxing_stream_en_stereo = MuxingStream(audio_stream_en_stereo.id)

    video_muxing_480p_output = EncodingOutput(output_id=s3_output.id,
                                              output_path=OUTPUT_BASE_PATH + 'video/hls/480p',
                                              acl=[acl_entry])
    video_muxing_480p = TSMuxing(segment_length=4,
                                 segment_naming='seg_%number%.ts',
                                 streams=[video_muxing_stream_480p],
                                 name='Sample Muxing 480p')
    video_muxing_480p = bitmovin.encodings.Muxing.TS.create(object_=video_muxing_480p,
                                                            encoding_id=encoding.id).resource

    fair_play_480p = FairPlayDRM(key=FAIRPLAY_KEY,
                                 iv=FAIRPLAY_IV,
                                 uri=FAIRPLAY_URI,
                                 outputs=[video_muxing_480p_output],
                                 name='FairPlay 480p')
    fair_play_480p = bitmovin.encodings.Muxing.TS.DRM.FairPlay.create(object_=fair_play_480p,
                                                                      encoding_id=encoding.id,
                                                                      muxing_id=video_muxing_480p.id).resource

    video_muxing_360p_output = EncodingOutput(output_id=s3_output.id,
                                              output_path=OUTPUT_BASE_PATH + 'video/hls/360p',
                                              acl=[acl_entry])
    video_muxing_360p = TSMuxing(segment_length=4,
                                 segment_naming='seg_%number%.ts',
                                 streams=[video_muxing_stream_360p],
                                 name='Sample Muxing 360p')
    video_muxing_360p = bitmovin.encodings.Muxing.TS.create(object_=video_muxing_360p,
                                                            encoding_id=encoding.id).resource
    fair_play_360p = FairPlayDRM(key=FAIRPLAY_KEY,
                                 iv=FAIRPLAY_IV,
                                 uri=FAIRPLAY_URI,
                                 outputs=[video_muxing_360p_output],
                                 name='FairPlay 360p')
    fair_play_360p = bitmovin.encodings.Muxing.TS.DRM.FairPlay.create(object_=fair_play_360p,
                                                                      encoding_id=encoding.id,
                                                                      muxing_id=video_muxing_360p.id).resource

    video_muxing_240p_output = EncodingOutput(output_id=s3_output.id,
                                              output_path=OUTPUT_BASE_PATH + 'video/hls/240p',
                                              acl=[acl_entry])
    video_muxing_240p = TSMuxing(segment_length=4,
                                 segment_naming='seg_%number%.ts',
                                 streams=[video_muxing_stream_240p],
                                 name='Sample Muxing 240p')
    video_muxing_240p = bitmovin.encodings.Muxing.TS.create(object_=video_muxing_240p,
                                                            encoding_id=encoding.id).resource

    fair_play_240p = FairPlayDRM(key=FAIRPLAY_KEY,
                                 iv=FAIRPLAY_IV,
                                 uri=FAIRPLAY_URI,
                                 outputs=[video_muxing_240p_output],
                                 name='FairPlay 240p')
    fair_play_240p = bitmovin.encodings.Muxing.TS.DRM.FairPlay.create(object_=fair_play_240p,
                                                                      encoding_id=encoding.id,
                                                                      muxing_id=video_muxing_240p.id).resource

    audio_muxing_output_en_stereo = EncodingOutput(output_id=s3_output.id,
                                                   output_path=OUTPUT_BASE_PATH + 'audio/hls/en_2_0',
                                                   acl=[acl_entry])
    audio_muxing_en_stereo = TSMuxing(segment_length=4,
                                      segment_naming='seg_%number%.ts',
                                      streams=[audio_muxing_stream_en_stereo],
                                      name='Sample Audio Muxing EN Stereo')
    audio_muxing_en_stereo = bitmovin.encodings.Muxing.TS.create(object_=audio_muxing_en_stereo,
                                                                 encoding_id=encoding.id).resource
    fair_play_audio = FairPlayDRM(key=FAIRPLAY_KEY,
                                  iv=FAIRPLAY_IV,
                                  uri=FAIRPLAY_URI,
                                  outputs=[audio_muxing_output_en_stereo],
                                  name='FairPlay Audio')

    fair_play_audio = bitmovin.encodings.Muxing.TS.DRM.FairPlay.create(object_=fair_play_audio,
                                                                       encoding_id=encoding.id,
                                                                       muxing_id=audio_muxing_en_stereo.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 ##

    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 FairPlay Manifest')
    hls_manifest = bitmovin.manifests.HLS.create(hls_manifest).resource

    audio_media = AudioMedia(name='Sample Audio Media',
                             group_id='audio_group',
                             segment_path=audio_muxing_output_en_stereo.outputPath,
                             encoding_id=encoding.id,
                             stream_id=audio_stream_en_stereo.id,
                             muxing_id=audio_muxing_en_stereo.id,
                             drm_id=fair_play_audio.id,
                             language='en',
                             uri='audiomedia.m3u8')

    audio_media = bitmovin.manifests.HLS.AudioMedia.create(manifest_id=hls_manifest.id, object_=audio_media).resource

    variant_stream_480p = VariantStream(audio=audio_media.groupId,
                                        closed_captions='NONE',
                                        segment_path=video_muxing_480p_output.outputPath,
                                        uri='video_480p.m3u8',
                                        encoding_id=encoding.id,
                                        stream_id=video_stream_480p.id,
                                        muxing_id=video_muxing_480p.id,
                                        drm_id=fair_play_480p.id)

    bitmovin.manifests.HLS.VariantStream.create(manifest_id=hls_manifest.id,
                                                object_=variant_stream_480p)

    variant_stream_360p = VariantStream(audio=audio_media.groupId,
                                        closed_captions='NONE',
                                        segment_path=video_muxing_360p_output.outputPath,
                                        uri='video_360p.m3u8',
                                        encoding_id=encoding.id,
                                        stream_id=video_stream_360p.id,
                                        muxing_id=video_muxing_360p.id,
                                        drm_id=fair_play_360p.id)

    bitmovin.manifests.HLS.VariantStream.create(manifest_id=hls_manifest.id,
                                                object_=variant_stream_360p)

    variant_stream_240p = VariantStream(audio=audio_media.groupId,
                                        closed_captions='NONE',
                                        segment_path=video_muxing_240p_output.outputPath,
                                        uri='video_240p.m3u8',
                                        encoding_id=encoding.id,
                                        stream_id=video_stream_240p.id,
                                        muxing_id=video_muxing_240p.id,
                                        drm_id=fair_play_240p.id)

    bitmovin.manifests.HLS.VariantStream.create(manifest_id=hls_manifest.id,
                                                object_=variant_stream_240p)

    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))
Esempio n. 22
0
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    local_input = LocalInput(name='My Local Input', path=INPUT_BASE_PATH)
    local_output = LocalOutput(name='My Local Output', path=OUTPUT_BASE_PATH)

    created_input = bitmovin.inputs.Local.create(local_input).resource
    created_output = bitmovin.outputs.Local.create(local_output).resource

    encoding = Encoding(name='Local Input Output Example',
                        cloud_region=CLOUD_REGION,
                        infrastructure_id=INFRASTRUCTURE_ID)

    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    ##########################
    # qualities
    video_qualities = [
        {'width': 1280, 'height': 720, 'bitrate': 2400000, 'bframes': None, 'profile': H264Profile.HIGH, 'level': None},
        {'width': 854, 'height': 480, 'bitrate': 1200000, 'bframes': None, 'profile': H264Profile.HIGH, 'level': None},
        {'width': 640, 'height': 360, 'bitrate': 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['bitrate']),
                                        rate=None,
                                        width=video_quality['width'],
                                        height=video_quality['height'],
                                        bitrate=video_quality['bitrate'],
                                        bframes=video_quality['bframes'],
                                        profile=video_quality['profile'],
                                        level=video_quality['level']
                                        )
        config = bitmovin.codecConfigurations.H264.create(config).resource
        video_configs.append(config)

    for audio_quality in audio_qualities:
        config = AACCodecConfiguration(name='aac_{}_{}'.format(audio_quality['bitrate'], audio_quality['rate']),
                                       bitrate=audio_quality['bitrate'],
                                       rate=audio_quality['rate'])
        config = bitmovin.codecConfigurations.AAC.create(config).resource
        audio_configs.append(config)

    video_input_stream = StreamInput(input_id=created_input.id,
                                     input_path=RELATIVE_INPUT_FILE_PATH,
                                     selection_mode=SelectionMode.AUTO)

    audio_input_stream = StreamInput(input_id=created_input.id,
                                     input_path=RELATIVE_INPUT_FILE_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 audio_config in audio_configs:
        stream = Stream(codec_configuration_id=audio_config.id,
                        input_streams=[audio_input_stream],
                        name='{}_stream'.format(audio_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']
        encoding_output = EncodingOutput(output_id=created_output.id,
                                         output_path=RELATIVE_OUTPUT_PATH + 'video_dash/{}/'.format(stream.name),
                                         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})

    for audio_muxing_stream in audio_muxing_streams:
        stream = audio_muxing_stream['stream']
        muxing = audio_muxing_stream['mux']
        encoding_output = EncodingOutput(output_id=created_output.id,
                                         output_path=RELATIVE_OUTPUT_PATH + 'audio_dash/{}/'.format(stream.name),
                                         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})

    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=created_output.id,
                                     output_path='{}manifests/'.format(RELATIVE_OUTPUT_PATH),
                                     acl=[acl_entry])

    ##########################
    # dash manifest

    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
    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_fmp4_representation = FMP4Representation(FMP4RepresentationType.TEMPLATE,
                                 encoding_id=encoding.id,
                                 muxing_id=muxing.id,
                                 segment_path='/{}'.format(encoding_output.outputPath))
        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_fmp4_representation = FMP4Representation(FMP4RepresentationType.TEMPLATE,
                                 encoding_id=encoding.id,
                                 muxing_id=muxing.id,
                                 segment_path='/{}'.format(encoding_output.outputPath))
        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))
Esempio n. 23
0
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME,
                       name='Sample S3 Output')
    s3_input = bitmovin.inputs.S3.create(s3_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

    acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ)

    encoding = Encoding(name='example mp4 encoding for smooth',
                        cloud_region=CloudRegion.GOOGLE_EUROPE_WEST_1)

    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    encoding_configs = []

    # Iterate over all encoding profiles and create the H264 configuration with the defined height and bitrate.
    for idx, _ in enumerate(encoding_profiles_h264):
        profile_h264 = encoding_profiles_h264[idx]
        encoding_config = dict(profile_h264=profile_h264)
        h264_codec = H264CodecConfiguration(
            name='H264 Codec {}p {}k Configuration'.format(
                profile_h264.get('height'), profile_h264.get('bitrate')),
            bitrate=profile_h264.get('bitrate') * 1000,
            height=profile_h264.get('height'),
            profile=profile_h264.get('profile'),
            rate=profile_h264.get("fps"))
        encoding_config[
            'h264_codec'] = bitmovin.codecConfigurations.H264.create(
                h264_codec).resource
        encoding_configs.append(encoding_config)

    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=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)

    audio_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_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_h264")
        video_stream_condition = Condition(attribute="HEIGHT",
                                           operator=">=",
                                           value=str(
                                               encoding_profile.get('height')))
        video_stream_h264 = Stream(
            codec_configuration_id=encoding_config.get("h264_codec").id,
            input_streams=[video_input_stream],
            conditions=video_stream_condition,
            name='Stream H264 {}p_{}k'.format(encoding_profile.get('height'),
                                              encoding_profile.get('bitrate')))

        encoding_config['h264_stream'] = bitmovin.encodings.Stream.create(
            object_=video_stream_h264, encoding_id=encoding.id).resource

    audio_stream_condition = Condition(attribute="INPUTSTREAM",
                                       operator="==",
                                       value="TRUE")
    audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id,
                          input_streams=[audio_input_stream],
                          conditions=audio_stream_condition,
                          name='Sample Stream AUDIO')

    audio_stream = bitmovin.encodings.Stream.create(
        object_=audio_stream, encoding_id=encoding.id).resource

    for encoding_config in encoding_configs:
        encoding_profile = encoding_config.get("profile_h264")
        video_muxing_stream_h264 = MuxingStream(
            encoding_config.get("h264_stream").id)
        video_muxing_output_h264 = EncodingOutput(output_id=s3_output.id,
                                                  output_path=OUTPUT_BASE_PATH,
                                                  acl=[acl_entry])
        video_muxing_h264 = MP4Muxing(
            filename='video_{}p.ismv'.format(encoding_profile.get('height')),
            fragment_duration=4000,
            streams=[video_muxing_stream_h264],
            outputs=[video_muxing_output_h264],
            name='Sample Muxing {}p'.format(encoding_profile.get('height')))

        encoding_config['h264_muxing'] = bitmovin.encodings.Muxing.MP4.create(
            object_=video_muxing_h264, 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,
                                         acl=[acl_entry])

    audio_muxing = MP4Muxing(filename='audio.isma',
                             fragment_duration=4000,
                             streams=[audio_muxing_stream],
                             outputs=[audio_muxing_output],
                             name='Sample Muxing AUDIO')

    audio_muxing = bitmovin.encodings.Muxing.MP4.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])

    smooth_manifest = SmoothManifest(
        server_manifest_name='example_manifest_smooth.ism',
        client_manifest_name='example_manifest_smooth.ismc',
        outputs=[manifest_output],
        name='Sample SmoothStreaming Manifest')

    smooth_manifest = bitmovin.manifests.Smooth.create(
        object_=smooth_manifest).resource

    mp4_representation_audio = MP4Representation(encoding_id=encoding.id,
                                                 muxing_id=audio_muxing.id,
                                                 media_file='audio.isma')

    mp4_representation_audio = bitmovin.manifests.Smooth.MP4Representation.create(
        manifest_id=smooth_manifest.id, object_=mp4_representation_audio)

    for encoding_config in encoding_configs:
        encoding_profile = encoding_config.get("profile_h264")
        muxing = encoding_config.get('h264_muxing')
        mp4_representation = MP4Representation(
            encoding_id=encoding.id,
            muxing_id=muxing.id,
            media_file='video_{}p.ismv'.format(encoding_profile.get('height')))

        encoding_config[
            'h264_smooth'] = bitmovin.manifests.Smooth.MP4Representation.create(
                manifest_id=smooth_manifest.id, object_=mp4_representation)

    bitmovin.manifests.Smooth.start(manifest_id=smooth_manifest.id)

    try:
        bitmovin.manifests.Smooth.wait_until_finished(
            manifest_id=smooth_manifest.id)
    except BitmovinError as bitmovin_error:
        print(
            "Exception occurred while waiting for Smooth manifest creation to finish: {}"
            .format(bitmovin_error))
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    # Create an S3 input. This resource is then used as base bucket for the input file.
    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME,
                       name='S3 Input')
    s3_input = bitmovin.inputs.S3.create(s3_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='Encoding with text filter',
                        cloud_region=CloudRegion.AWS_EU_WEST_1)

    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    encoding_configs = []

    # Iterate over all encoding profiles and create the H264 configuration with the defined height and bitrate.
    for idx, _ in enumerate(encoding_profiles_h264):
        profile_h264 = encoding_profiles_h264[idx]
        encoding_config = dict(profile_h264=profile_h264)
        h264_codec = H264CodecConfiguration(
            name='H264 Codec {}p {}k Configuration'.format(
                profile_h264.get('height'), profile_h264.get('bitrate')),
            bitrate=profile_h264.get('bitrate') * 1000,
            height=profile_h264.get('height'),
            profile=profile_h264.get('profile'),
            rate=profile_h264.get('fps'))
        encoding_config[
            'h264_codec'] = bitmovin.codecConfigurations.H264.create(
                h264_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=s3_input.id,
        input_path=S3_INPUT_PATH,
        selection_mode=SelectionMode.VIDEO_RELATIVE,
        position=0)

    audio_input_stream = StreamInput(
        input_id=s3_input.id,
        input_path=S3_INPUT_PATH,
        selection_mode=SelectionMode.AUDIO_RELATIVE,
        position=0)

    # Configure text filter here
    text_filter = TextFilter(name='Text Filter',
                             text='Bitmovin is great!',
                             x='main_w/2-text_w/2',
                             y='10',
                             font_color='#FFFFFF',
                             font_size=48,
                             box=True,
                             box_color='#32A9E1',
                             shadow_color='#218ECD',
                             shadow_x=5,
                             shadow_y=5,
                             font=Font.DEJAVUSANS)

    text_filter = bitmovin.filters.Text.create(object_=text_filter).resource

    stream_filter = [StreamFilter(id=text_filter.id, position=0)]

    # 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_h264')

        video_stream_h264 = Stream(
            codec_configuration_id=encoding_config.get('h264_codec').id,
            input_streams=[video_input_stream],
            name='Stream H264 {}p_{}k'.format(encoding_profile.get('height'),
                                              encoding_profile.get('bitrate')))

        encoding_config['h264_stream'] = bitmovin.encodings.Stream.create(
            object_=video_stream_h264, encoding_id=encoding.id).resource

        bitmovin.encodings.Stream.Filter.create(
            encoding_id=encoding.id,
            stream_id=encoding_config['h264_stream'].id,
            stream_filter=stream_filter)

    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 TS and FMP4 muxings which are later used for the HLS and 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_h264')
        video_muxing_stream_h264 = MuxingStream(
            encoding_config.get('h264_stream').id)
        video_muxing_output_h264 = EncodingOutput(
            output_id=s3_output.id,
            output_path=OUTPUT_BASE_PATH +
            'video/h264/dash/{}p_{}k/'.format(encoding_profile.get('height'),
                                              encoding_profile.get('bitrate')),
            acl=[acl_entry])
        video_muxing_h264 = FMP4Muxing(segment_length=4,
                                       segment_naming='seg_%number%.m4s',
                                       init_segment_name='init.mp4',
                                       streams=[video_muxing_stream_h264],
                                       outputs=[video_muxing_output_h264],
                                       name='FMP4 H264 Muxing {}p_{}k'.format(
                                           encoding_profile.get('height'),
                                           encoding_profile.get('bitrate')))
        encoding_config['h264_muxing'] = bitmovin.encodings.Muxing.FMP4.create(
            object_=video_muxing_h264, encoding_id=encoding.id).resource

        video_ts_muxing_output_h264 = EncodingOutput(
            output_id=s3_output.id,
            output_path=OUTPUT_BASE_PATH +
            'video/h264/hls/{}p_{}k/'.format(encoding_profile.get('height'),
                                             encoding_profile.get('bitrate')),
            acl=[acl_entry])
        video_ts_muxing_h264 = TSMuxing(segment_length=4,
                                        segment_naming='seg_%number%.ts',
                                        streams=[video_muxing_stream_h264],
                                        outputs=[video_ts_muxing_output_h264],
                                        name='FMP4 H264 Muxing {}p_{}k'.format(
                                            encoding_profile.get('height'),
                                            encoding_profile.get('bitrate')))
        encoding_config[
            'h264_ts_muxing'] = bitmovin.encodings.Muxing.TS.create(
                object_=video_ts_muxing_h264, encoding_id=encoding.id).resource

    audio_muxing_stream = MuxingStream(audio_stream.id)

    # mp4 audio muxing
    audio_muxing_output = EncodingOutput(output_id=s3_output.id,
                                         output_path=OUTPUT_BASE_PATH +
                                         'audio/dash/',
                                         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='Audio Dash Muxing')
    audio_muxing = bitmovin.encodings.Muxing.FMP4.create(
        object_=audio_muxing, encoding_id=encoding.id).resource

    # TS audio muxing
    hls_audio_muxing_output = EncodingOutput(output_id=s3_output.id,
                                             output_path=OUTPUT_BASE_PATH +
                                             'audio/hls/',
                                             acl=[acl_entry])
    hls_audio_muxing = TSMuxing(segment_length=4,
                                segment_naming='seg_%number%.ts',
                                streams=[audio_muxing_stream],
                                outputs=[hls_audio_muxing_output],
                                name='Audio TS Muxing')
    hls_audio_muxing = bitmovin.encodings.Muxing.TS.create(
        object_=hls_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:')
        pprint(bitmovin_error)
        exit(-1)

    # 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 H264 manifest and add one period with an adaptation set for audio and video
    dash_manifest_h264 = DashManifest(manifest_name='stream.mpd',
                                      outputs=[manifest_output],
                                      name='DASH H264 Manifest')
    dash_manifest_h264 = bitmovin.manifests.DASH.create(
        dash_manifest_h264).resource
    period_h264 = Period()
    period_h264 = bitmovin.manifests.DASH.add_period(
        object_=period_h264, manifest_id=dash_manifest_h264.id).resource
    video_adaptation_set_h264 = VideoAdaptationSet()
    video_adaptation_set_h264 = bitmovin.manifests.DASH.add_video_adaptation_set(
        object_=video_adaptation_set_h264,
        manifest_id=dash_manifest_h264.id,
        period_id=period_h264.id).resource

    audio_adaptation_set_h264 = AudioAdaptationSet(lang='en')
    audio_adaptation_set_h264 = bitmovin.manifests.DASH.add_audio_adaptation_set(
        object_=audio_adaptation_set_h264,
        manifest_id=dash_manifest_h264.id,
        period_id=period_h264.id).resource

    fmp4_representation_audio = FMP4Representation(
        FMP4RepresentationType.TEMPLATE,
        encoding_id=encoding.id,
        muxing_id=audio_muxing.id,
        segment_path='audio/dash/')

    bitmovin.manifests.DASH.add_fmp4_representation(
        object_=fmp4_representation_audio,
        manifest_id=dash_manifest_h264.id,
        period_id=period_h264.id,
        adaptationset_id=audio_adaptation_set_h264.id)

    # Add all representation to the video adaption set
    for encoding_config in encoding_configs:
        encoding_profile = encoding_config.get('profile_h264')
        muxing = encoding_config.get('h264_muxing')
        fmp4_representation = FMP4Representation(
            FMP4RepresentationType.TEMPLATE,
            encoding_id=encoding.id,
            muxing_id=muxing.id,
            segment_path='video/h264/dash/{}p_{}k/'.format(
                encoding_profile.get('height'),
                encoding_profile.get('bitrate')))
        encoding_config[
            'h264_dash'] = bitmovin.manifests.DASH.add_fmp4_representation(
                object_=fmp4_representation,
                manifest_id=dash_manifest_h264.id,
                period_id=period_h264.id,
                adaptationset_id=video_adaptation_set_h264.id).resource

    bitmovin.manifests.DASH.start(manifest_id=dash_manifest_h264.id)

    # Create a HLS H264 manifest and add one period with an adaptation set for audio and video
    hls_manifest = HlsManifest(manifest_name='stream.m3u8',
                               outputs=[manifest_output],
                               name='HLS H264 Manifest')
    hls_manifest = bitmovin.manifests.HLS.create(object_=hls_manifest).resource

    hls_audio_media = AudioMedia(name='en',
                                 group_id='audio_group',
                                 segment_path='audio/hls/',
                                 encoding_id=encoding.id,
                                 stream_id=audio_stream.id,
                                 muxing_id=hls_audio_muxing.id,
                                 language='en',
                                 uri='audio.m3u8')

    bitmovin.manifests.HLS.AudioMedia.create(manifest_id=hls_manifest.id,
                                             object_=hls_audio_media)

    # Add all representation to the video adaption set
    for encoding_config in encoding_configs:
        encoding_profile = encoding_config.get('profile_h264')
        video_muxing_stream_h264 = encoding_config.get('h264_stream')
        ts_muxing = encoding_config.get('h264_ts_muxing')

        # append another variant stream for this video quality to our hls renditions.
        hls_variant_stream = VariantStream(
            audio='audio_group',
            segment_path='video/h264/hls/{}p_{}k/'.format(
                encoding_profile.get('height'),
                encoding_profile.get('bitrate')),
            uri='video_{}p_{}.m3u8'.format(encoding_profile.get('height'),
                                           encoding_profile.get('bitrate')),
            encoding_id=encoding.id,
            stream_id=video_muxing_stream_h264.id,
            muxing_id=ts_muxing.id)

        bitmovin.manifests.HLS.VariantStream.create(
            manifest_id=hls_manifest.id, object_=hls_variant_stream)

    bitmovin.manifests.HLS.start(manifest_id=hls_manifest.id)

    try:
        bitmovin.manifests.DASH.wait_until_finished(
            manifest_id=dash_manifest_h264.id)
    except BitmovinError as bitmovin_error:
        print(
            'Exception occurred while waiting for manifest creation to finish: {}'
            .format(bitmovin_error))
        exit(-1)

    try:
        bitmovin.manifests.HLS.wait_until_finished(manifest_id=hls_manifest.id)
    except BitmovinError as bitmovin_error:
        print(
            'Exception occurred while waiting for manifest creation to finish: {}'
            .format(bitmovin_error))
        exit(-1)
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)
Esempio n. 26
0
def main():
    bitmovin = Bitmovin(api_key=API_KEY)
    resource_response = bitmovin.inputs.RTMP.list()

    if not resource_response or \
       not resource_response.resource or \
       not isinstance(resource_response.resource, list) or \
       len(resource_response.resource) < 1:
        print('Could not find any RTMP inputs. Please contact support.')
        sys.exit(3)

    rtmp_input_id = resource_response.resource[0].id
    print("Found RTMP input with ID '{}'".format(rtmp_input_id))

    rtmp_input = bitmovin.inputs.RTMP.retrieve(id_=rtmp_input_id).resource

    output = GenericS3Output(access_key=GENERIC_S3_OUTPUT_ACCESSKEY,
                             secret_key=GENERIC_S3_OUTPUT_SECRETKEY,
                             bucket_name=GENERIC_S3_OUTPUT_BUCKETNAME,
                             host=GENERIC_S3_OUTPUT_HOST,
                             port=GENERIC_S3_OUTPUT_PORT,
                             name='Sample Generic S3 Output')
    output = bitmovin.outputs.GenericS3.create(output).resource

    encoding = Encoding(name='example python hls live stream encoding',
                        encoder_version=ENCODER_VERSION,
                        cloud_region=CLOUD_REGION,
                        infrastructure_id=INFRASTRUCTURE_ID)
    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_360p = H264CodecConfiguration(
        name='example_video_codec_configuration_720p',
        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

    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=rtmp_input.id,
                                     input_path='live',
                                     position=0,
                                     selection_mode=SelectionMode.AUTO)
    audio_input_stream = StreamInput(input_id=rtmp_input.id,
                                     input_path='live',
                                     position=1,
                                     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

    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

    video_muxing_stream_1080p = MuxingStream(video_stream_1080p.id)
    video_muxing_stream_720p = MuxingStream(video_stream_720p.id)
    video_muxing_stream_360p = MuxingStream(video_stream_360p.id)
    audio_muxing_stream = MuxingStream(audio_stream.id)

    acl_entry = ACLEntry(permission=ACLPermission.PUBLIC_READ)

    video_muxing_1080p_output = EncodingOutput(output_id=output.id,
                                               output_path=OUTPUT_BASE_PATH +
                                               'video/1080p',
                                               acl=[acl_entry])
    video_muxing_1080p = TSMuxing(segment_length=4,
                                  segment_naming='seg_%number%.ts',
                                  streams=[video_muxing_stream_1080p],
                                  outputs=[video_muxing_1080p_output],
                                  name='Sample Muxing 1080p')
    video_muxing_1080p = bitmovin.encodings.Muxing.TS.create(
        object_=video_muxing_1080p, encoding_id=encoding.id).resource
    video_muxing_720p_output = EncodingOutput(output_id=output.id,
                                              output_path=OUTPUT_BASE_PATH +
                                              'video/720p',
                                              acl=[acl_entry])
    video_muxing_720p = TSMuxing(segment_length=4,
                                 segment_naming='seg_%number%.m4s',
                                 streams=[video_muxing_stream_720p],
                                 outputs=[video_muxing_720p_output],
                                 name='Sample Muxing 720p')
    video_muxing_720p = bitmovin.encodings.Muxing.TS.create(
        object_=video_muxing_720p, encoding_id=encoding.id).resource

    video_muxing_360p_output = EncodingOutput(output_id=output.id,
                                              output_path=OUTPUT_BASE_PATH +
                                              'video/360p',
                                              acl=[acl_entry])
    video_muxing_360p = TSMuxing(segment_length=4,
                                 segment_naming='seg_%number%.m4s',
                                 streams=[video_muxing_stream_360p],
                                 outputs=[video_muxing_360p_output],
                                 name='Sample Muxing 360p')
    video_muxing_360p = bitmovin.encodings.Muxing.TS.create(
        object_=video_muxing_360p, encoding_id=encoding.id).resource

    audio_muxing_output = EncodingOutput(output_id=output.id,
                                         output_path=OUTPUT_BASE_PATH +
                                         'audio/128k',
                                         acl=[acl_entry])
    audio_muxing = TSMuxing(segment_length=4,
                            segment_naming='seg_%number%.m4s',
                            streams=[audio_muxing_stream],
                            outputs=[audio_muxing_output],
                            name='Sample Muxing AUDIO')
    audio_muxing = bitmovin.encodings.Muxing.TS.create(
        object_=audio_muxing, encoding_id=encoding.id).resource

    #### Manifest #####################################################################################################

    manifest_output = EncodingOutput(output_id=output.id,
                                     output_path=OUTPUT_BASE_PATH,
                                     acl=[acl_entry])
    hls_manifest = HlsManifest(
        manifest_name='example_live_manifest.m3u8',
        outputs=[manifest_output],
        name='Sample HLS Manifest Live',
        description='Bitmovin Python Test Live HLS Manifest')
    hls_manifest = bitmovin.manifests.HLS.create(hls_manifest).resource

    audio_media = AudioMedia(name='Sample Audio Media',
                             group_id='audio_group',
                             segment_path="audio/128k/",
                             encoding_id=encoding.id,
                             stream_id=audio_stream.id,
                             muxing_id=audio_muxing.id,
                             language='en',
                             uri='audiomedia.m3u8',
                             autoselect=False)

    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/1080p/",
                                         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/720p/",
                                        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)

    variant_stream_360p = VariantStream(audio=audio_media.groupId,
                                        closed_captions='NONE',
                                        segment_path="video/360p/",
                                        uri='video_360p.m3u8',
                                        encoding_id=encoding.id,
                                        stream_id=video_stream_360p.id,
                                        muxing_id=video_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)

    ###################################################################################################################

    live_hls_manifest = LiveHlsManifest(manifest_id=hls_manifest.id,
                                        time_shift=60)

    live_stream_configuration = LiveStreamConfiguration(
        stream_key=STREAM_KEY,
        live_hls_manifests=[live_hls_manifest],
    )

    resource_response = bitmovin.encodings.Encoding.start_live(
        encoding_id=encoding.id,
        live_stream_configuration=live_stream_configuration)

    bitmovin.encodings.Encoding.wait_until_running(
        encoding_id=resource_response.resource.id)

    live_details = None
    retry = 0

    while retry < LIVE_STREAM_INFORMATION_FETCH_MAX_RETRIES:
        try:
            live_details = bitmovin.encodings.Encoding.retrieve_live(
                encoding_id=resource_response.resource.id)
            break
        except BitmovinApiError as bitmovin_api_error:
            if bitmovin_api_error.response.data.code != ERROR_CODE_LIVE_STREAM_NOT_READY:
                sys.exit(2)
            print(
                "Live stream is not ready yet. Retrying to fetch live stream information in {} seconds..."
                .format(LIVE_STREAM_INFORMATION_FETCH_RETRY_INTERVAL))
            retry += 1
            time.sleep(LIVE_STREAM_INFORMATION_FETCH_RETRY_INTERVAL)

    if live_details is not None:
        print_live_stream_details(encoding_id=encoding.id,
                                  live_stream_details=live_details.resource)
    else:
        print("Unable to fetch live stream details!")
        sys.exit(1)
def main():
    bitmovin = Bitmovin(api_key=API_KEY)

    # Create an S3 input. This resource is then used as base bucket for the input file.
    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME,
                       name='S3 Input')
    s3_input = bitmovin.inputs.S3.create(s3_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='Encoding with video/audio and stream condition',
                        cloud_region=CloudRegion.AWS_EU_WEST_1)

    encoding = bitmovin.encodings.Encoding.create(encoding).resource

    encoding_configs = []

    # Iterate over all encoding profiles and create the H264 configuration with the defined height and bitrate.
    for idx, _ in enumerate(encoding_profiles_h264):
        profile_h264 = encoding_profiles_h264[idx]
        encoding_config = dict(profile_h264=profile_h264)
        h264_codec_height = H264CodecConfiguration(
            name='H264 Codec {}p {}k Configuration'.format(profile_h264.get('height'),
                                                           profile_h264.get('bitrate')),
            bitrate=profile_h264.get('bitrate') * 1000,
            height=profile_h264.get('height'),
            profile=profile_h264.get('profile'),
            rate=profile_h264.get("fps"))
        encoding_config['h264_codec_ar_gt_1'] = bitmovin.codecConfigurations.H264.create(h264_codec_height).resource
        h264_codec_height_landscape = H264CodecConfiguration(
            name='H264 Codec {}p {}k Configuration'.format(profile_h264.get('height'),
                                                           profile_h264.get('bitrate')),
            bitrate=profile_h264.get('bitrate') * 1000,
            height=profile_h264.get('height_landscape'),
            profile=profile_h264.get('profile'),
            rate=profile_h264.get("fps"))
        encoding_config['h264_codec_ar_lt_1'] = bitmovin.codecConfigurations.H264.create(h264_codec_height_landscape).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=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.VIDEO_RELATIVE,
                                     position=0)

    audio_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUDIO_RELATIVE,
                                     position=0)

    # 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_h264")
        video_stream_condition_ar_gt_1 = Condition(attribute="ASPECTRATIO", operator=">=", value="1")
        video_stream_h264 = Stream(codec_configuration_id=encoding_config.get("h264_codec_ar_gt_1").id,
                                   input_streams=[video_input_stream],
                                   conditions=video_stream_condition_ar_gt_1,
                                   name='Stream H264 {}p_{}k'.format(encoding_profile.get('height'),
                                                                     encoding_profile.get('bitrate')))
        encoding_config['h264_stream_ar_gt_1'] = bitmovin.encodings.Stream.create(object_=video_stream_h264,
                                                                                  encoding_id=encoding.id).resource
        video_stream_condition_ar_lt_1 = Condition(attribute="ASPECTRATIO", operator="<", value="1")
        video_stream_h264 = Stream(codec_configuration_id=encoding_config.get("h264_codec_ar_lt_1").id,
                                   input_streams=[video_input_stream],
                                   conditions=video_stream_condition_ar_lt_1,
                                   name='Stream H264 {}p_{}k'.format(encoding_profile.get('height'),
                                                                     encoding_profile.get('bitrate')))
        encoding_config['h264_stream_ar_lt_1'] = bitmovin.encodings.Stream.create(object_=video_stream_h264,
                                                                                  encoding_id=encoding.id).resource

    audio_stream_condition = Condition(attribute="INPUTSTREAM", operator="==", value="TRUE")
    audio_stream = Stream(codec_configuration_id=audio_codec_configuration.id,
                          input_streams=[audio_input_stream],
                          conditions=audio_stream_condition,
                          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_h264")
        video_muxing_stream_h264_ar_gt_1 = MuxingStream(encoding_config.get("h264_stream_ar_gt_1").id)
        video_muxing_output_h264 = EncodingOutput(output_id=s3_output.id,
                                                  output_path=OUTPUT_BASE_PATH + 'video/h264/dash/{}p_{}k/'.format(
                                                      encoding_profile.get('height'),
                                                      encoding_profile.get('bitrate')),
                                                  acl=[acl_entry])
        video_muxing_h264_ar_gt_1 = FMP4Muxing(segment_length=4,
                                               segment_naming='seg_%number%.m4s',
                                               init_segment_name='init.mp4',
                                               streams=[video_muxing_stream_h264_ar_gt_1],
                                               outputs=[video_muxing_output_h264],
                                               name='FMP4 H264 Muxing {}p_{}k'.format(encoding_profile.get('height'),
                                                                                      encoding_profile.get('bitrate')))
        encoding_config['h264_muxing_ar_gt_1'] = bitmovin.encodings.Muxing.FMP4.create(
            object_=video_muxing_h264_ar_gt_1,
            encoding_id=encoding.id).resource

        video_ts_muxing_output_h264 = EncodingOutput(output_id=s3_output.id,
                                                     output_path=OUTPUT_BASE_PATH + 'video/h264/hls/{}p_{}k/'.format(
                                                         encoding_profile.get('height'),
                                                         encoding_profile.get('bitrate')),
                                                     acl=[acl_entry])
        video_ts_muxing_h264_ar_gt_1 = TSMuxing(segment_length=4,
                                                segment_naming='seg_%number%.ts',
                                                streams=[video_muxing_stream_h264_ar_gt_1],
                                                outputs=[video_ts_muxing_output_h264],
                                                name='FMP4 H264 Muxing {}p_{}k'.format(encoding_profile.get('height'),
                                                                                       encoding_profile.get('bitrate')))
        encoding_config['h264_ts_muxing_ar_gt_1'] = bitmovin.encodings.Muxing.TS.create(
            object_=video_ts_muxing_h264_ar_gt_1,
            encoding_id=encoding.id).resource

        video_muxing_stream_h264_ar_lt_1 = MuxingStream(encoding_config.get("h264_stream_ar_lt_1").id)
        video_muxing_output_h264 = EncodingOutput(output_id=s3_output.id,
                                                  output_path=OUTPUT_BASE_PATH + 'video/h264/dash/{}p_{}k/'.format(
                                                      encoding_profile.get('height'),
                                                      encoding_profile.get('bitrate')),
                                                  acl=[acl_entry])
        video_muxing_h264_ar_lt_1 = FMP4Muxing(segment_length=4,
                                               segment_naming='seg_%number%.m4s',
                                               init_segment_name='init.mp4',
                                               streams=[video_muxing_stream_h264_ar_lt_1],
                                               outputs=[video_muxing_output_h264],
                                               name='FMP4 H264 Muxing {}p_{}k'.format(encoding_profile.get('height'),
                                                                                      encoding_profile.get('bitrate')))
        encoding_config['h264_muxing_ar_lt_1'] = bitmovin.encodings.Muxing.FMP4.create(
            object_=video_muxing_h264_ar_lt_1,
            encoding_id=encoding.id).resource

        video_ts_muxing_output_h264 = EncodingOutput(output_id=s3_output.id,
                                                     output_path=OUTPUT_BASE_PATH + 'video/h264/hls/{}p_{}k/'.format(
                                                         encoding_profile.get('height'),
                                                         encoding_profile.get('bitrate')),
                                                     acl=[acl_entry])
        video_ts_muxing_h264_ar_lt_1 = TSMuxing(segment_length=4,
                                                segment_naming='seg_%number%.ts',
                                                streams=[video_muxing_stream_h264_ar_lt_1],
                                                outputs=[video_ts_muxing_output_h264],
                                                name='FMP4 H264 Muxing {}p_{}k'.format(encoding_profile.get('height'),
                                                                                       encoding_profile.get('bitrate')))
        encoding_config['h264_ts_muxing_ar_lt_1'] = bitmovin.encodings.Muxing.TS.create(
            object_=video_ts_muxing_h264_ar_lt_1,
            encoding_id=encoding.id).resource

    audio_muxing_stream = MuxingStream(audio_stream.id)

    # mp4 audio muxing
    audio_muxing_output = EncodingOutput(output_id=s3_output.id,
                                         output_path=OUTPUT_BASE_PATH + "audio/dash/",
                                         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='Audio Dash Muxing')
    audio_muxing = bitmovin.encodings.Muxing.FMP4.create(object_=audio_muxing,
                                                         encoding_id=encoding.id).resource

    # TS audio muxing
    hls_audio_muxing_output = EncodingOutput(output_id=s3_output.id,
                                             output_path=OUTPUT_BASE_PATH + "audio/hls/",
                                             acl=[acl_entry])
    hls_audio_muxing = TSMuxing(segment_length=4,
                                segment_naming='seg_%number%.ts',
                                streams=[audio_muxing_stream],
                                outputs=[hls_audio_muxing_output],
                                name='Audio TS Muxing')
    hls_audio_muxing = bitmovin.encodings.Muxing.TS.create(object_=hls_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:")
        pprint(bitmovin_error)
        exit(-1)

    # 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 H264 manifest and add one period with an adaptation set for audio and video
    dash_manifest_h264 = DashManifest(manifest_name='stream.mpd',
                                      outputs=[manifest_output],
                                      name='DASH H264 Manifest')
    dash_manifest_h264 = bitmovin.manifests.DASH.create(dash_manifest_h264).resource
    period_h264 = Period()
    period_h264 = bitmovin.manifests.DASH.add_period(object_=period_h264, manifest_id=dash_manifest_h264.id).resource
    video_adaptation_set_h264 = VideoAdaptationSet()
    video_adaptation_set_h264 = bitmovin.manifests.DASH.add_video_adaptation_set(object_=video_adaptation_set_h264,
                                                                                 manifest_id=dash_manifest_h264.id,
                                                                                 period_id=period_h264.id).resource

    audio_adaptation_set_h264 = AudioAdaptationSet(lang='en')
    audio_adaptation_set_h264 = bitmovin.manifests.DASH.add_audio_adaptation_set(object_=audio_adaptation_set_h264,
                                                                                 manifest_id=dash_manifest_h264.id,
                                                                                 period_id=period_h264.id).resource

    fmp4_representation_audio = FMP4Representation(FMP4RepresentationType.TEMPLATE,
                                                   encoding_id=encoding.id,
                                                   muxing_id=audio_muxing.id,
                                                   segment_path="audio/dash/")

    bitmovin.manifests.DASH.add_fmp4_representation(object_=fmp4_representation_audio,
                                                    manifest_id=dash_manifest_h264.id,
                                                    period_id=period_h264.id,
                                                    adaptationset_id=audio_adaptation_set_h264.id)

    # Add all representation to the video adaption set
    for encoding_config in encoding_configs:
        encoding_profile = encoding_config.get("profile_h264")
        h264_muxing_ar_gt_1 = encoding_config.get('h264_muxing_ar_gt_1')
        fmp4_representation = FMP4Representation(FMP4RepresentationType.TEMPLATE,
                                                 encoding_id=encoding.id,
                                                 muxing_id=h264_muxing_ar_gt_1.id,
                                                 segment_path='video/h264/dash/{}p_{}k/'.format(
                                                     encoding_profile.get('height'),
                                                     encoding_profile.get('bitrate')))
        encoding_config['h264_dash'] = bitmovin.manifests.DASH.add_fmp4_representation(
            object_=fmp4_representation,
            manifest_id=dash_manifest_h264.id,
            period_id=period_h264.id,
            adaptationset_id=video_adaptation_set_h264.id
        ).resource
        h264_muxing_ar_lt_1 = encoding_config.get('h264_muxing_ar_lt_1')
        fmp4_representation = FMP4Representation(FMP4RepresentationType.TEMPLATE,
                                                 encoding_id=encoding.id,
                                                 muxing_id=h264_muxing_ar_lt_1.id,
                                                 segment_path='video/h264/dash/{}p_{}k/'.format(
                                                     encoding_profile.get('height'),
                                                     encoding_profile.get('bitrate')))
        encoding_config['h264_dash'] = bitmovin.manifests.DASH.add_fmp4_representation(
            object_=fmp4_representation,
            manifest_id=dash_manifest_h264.id,
            period_id=period_h264.id,
            adaptationset_id=video_adaptation_set_h264.id
        ).resource

    bitmovin.manifests.DASH.start(manifest_id=dash_manifest_h264.id)

    # Create a HLS H264 manifest and add one period with an adaptation set for audio and video
    hls_manifest = HlsManifest(manifest_name='stream.m3u8',
                               outputs=[manifest_output],
                               name='HLS H264 Manifest')
    hls_manifest = bitmovin.manifests.HLS.create(object_=hls_manifest).resource

    hls_audio_media = AudioMedia(name='en', group_id='audio_group',
                                 segment_path="audio/hls/",
                                 encoding_id=encoding.id,
                                 stream_id=audio_stream.id,
                                 muxing_id=hls_audio_muxing.id,
                                 language='en',
                                 uri="audio.m3u8")

    bitmovin.manifests.HLS.AudioMedia.create(manifest_id=hls_manifest.id,
                                             object_=hls_audio_media)

    # Add all representation to the video adaption set
    for encoding_config in encoding_configs:
        encoding_profile = encoding_config.get("profile_h264")
        video_muxing_stream_h264_ar_gt_1 = encoding_config.get("h264_stream_ar_gt_1")
        ts_muxing_ar_gt_1 = encoding_config.get('h264_ts_muxing_ar_gt_1')

        # append another variant stream for this video quality to our hls renditions.
        hls_variant_stream = VariantStream(audio="audio_group",
                                           segment_path='video/h264/hls/{}p_{}k/'.format(
                                               encoding_profile.get('height'),
                                               encoding_profile.get('bitrate')),
                                           uri='video_{}p_{}.m3u8'.format(
                                               encoding_profile.get('height'),
                                               encoding_profile.get('bitrate')),
                                           encoding_id=encoding.id,
                                           stream_id=video_muxing_stream_h264_ar_gt_1.id,
                                           muxing_id=ts_muxing_ar_gt_1.id)

        bitmovin.manifests.HLS.VariantStream.create(manifest_id=hls_manifest.id,
                                                    object_=hls_variant_stream)
        
        video_muxing_stream_h264_ar_lt_1 = encoding_config.get("h264_stream_ar_lt_1")
        ts_muxing_ar_lt_1 = encoding_config.get('h264_ts_muxing_ar_lt_1')

        # append another variant stream for this video quality to our hls renditions.
        hls_variant_stream = VariantStream(audio="audio_group",
                                           segment_path='video/h264/hls/{}p_{}k/'.format(
                                               encoding_profile.get('height'),
                                               encoding_profile.get('bitrate')),
                                           uri='video_{}p_{}.m3u8'.format(
                                               encoding_profile.get('height'),
                                               encoding_profile.get('bitrate')),
                                           encoding_id=encoding.id,
                                           stream_id=video_muxing_stream_h264_ar_lt_1.id,
                                           muxing_id=ts_muxing_ar_lt_1.id)

        bitmovin.manifests.HLS.VariantStream.create(manifest_id=hls_manifest.id,
                                                    object_=hls_variant_stream)

    bitmovin.manifests.HLS.start(manifest_id=hls_manifest.id)

    try:
        bitmovin.manifests.DASH.wait_until_finished(manifest_id=dash_manifest_h264.id)
    except BitmovinError as bitmovin_error:
        print("Exception occurred while waiting for manifest creation to finish: {}".format(bitmovin_error))
        exit(-1)

    try:
        bitmovin.manifests.HLS.wait_until_finished(manifest_id=hls_manifest.id)
    except BitmovinError as bitmovin_error:
        print("Exception occurred while waiting for manifest creation to finish: {}".format(bitmovin_error))
        exit(-1)
Esempio n. 28
0
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)

    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():
    bitmovin = Bitmovin(api_key=API_KEY)

    s3_input = S3Input(access_key=S3_INPUT_ACCESSKEY,
                       secret_key=S3_INPUT_SECRETKEY,
                       bucket_name=S3_INPUT_BUCKETNAME,
                       name='Sample S3 Output')
    s3_input = bitmovin.inputs.S3.create(s3_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

    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

    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=s3_input.id,
                                     input_path=S3_INPUT_PATH,
                                     selection_mode=SelectionMode.AUTO)
    audio_input_stream = StreamInput(input_id=s3_input.id,
                                     input_path=S3_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

    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

    video_stream_240p = Stream(
        codec_configuration_id=video_codec_configuration_240p.id,
        input_streams=[video_input_stream],
        name='Sample Stream 240p')
    video_stream_240p = bitmovin.encodings.Stream.create(
        object_=video_stream_240p, 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)
    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)
    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

    video_muxing_480p_output = EncodingOutput(output_id=s3_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 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=s3_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 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=s3_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 Muxing 240p')
    video_muxing_240p = bitmovin.encodings.Muxing.FMP4.create(
        object_=video_muxing_240p, 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/',
                             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/1080p/',
                                         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/720p/',
                                        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)

    variant_stream_480p = VariantStream(audio=audio_media.groupId,
                                        closed_captions='NONE',
                                        segment_path='video/480p/',
                                        uri='video_480p.m3u8',
                                        encoding_id=encoding.id,
                                        stream_id=video_stream_480p.id,
                                        muxing_id=video_muxing_480p.id)
    variant_stream_480p = bitmovin.manifests.HLS.VariantStream.create(
        manifest_id=hls_manifest.id, object_=variant_stream_480p)

    variant_stream_360p = VariantStream(audio=audio_media.groupId,
                                        closed_captions='NONE',
                                        segment_path='video/360p/',
                                        uri='video_360p.m3u8',
                                        encoding_id=encoding.id,
                                        stream_id=video_stream_360p.id,
                                        muxing_id=video_muxing_360p.id)
    variant_stream_360p = bitmovin.manifests.HLS.VariantStream.create(
        manifest_id=hls_manifest.id, object_=variant_stream_360p)

    variant_stream_240p = VariantStream(audio=audio_media.groupId,
                                        closed_captions='NONE',
                                        segment_path='video/240p/',
                                        uri='video_240p.m3u8',
                                        encoding_id=encoding.id,
                                        stream_id=video_stream_240p.id,
                                        muxing_id=video_muxing_240p.id)
    variant_stream_240p = bitmovin.manifests.HLS.VariantStream.create(
        manifest_id=hls_manifest.id, object_=variant_stream_240p)

    bitmovin.manifests.HLS.start(manifest_id=hls_manifest.id)

    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
    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_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

    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.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))

    try:
        bitmovin.manifests.DASH.wait_until_finished(
            manifest_id=dash_manifest.id)
    except BitmovinError as bitmovin_error:
        print(
            "Exception occurred while waiting for DASH manifest creation to finish: {}"
            .format(bitmovin_error))