Created
September 20, 2023 05:14
-
-
Save aasumitro/502a3786f7de8d929c5a283653d755d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id := "7035ad47-82b4-4ef4-ae5d-220c40540232" | |
fileToUploadPath := "./assets/video.mp4" | |
fileToUpload, err := os.Open(fileToUploadPath) | |
if err != nil { | |
c.JSON(http.StatusBadRequest, gin.H{ | |
"message": err.Error(), | |
}) | |
return | |
} | |
defer func() { _ = fileToUpload.Close() }() | |
if _, err = azureBlobClient.UploadFile( | |
c, cfgInstance.AzureBlobContainer, | |
fmt.Sprintf("%s.mp4", id), fileToUpload, &azblob.UploadFileOptions{ | |
HTTPHeaders: &blob.HTTPHeaders{ | |
BlobContentType: to.Ptr("video/mp4"), | |
}, | |
}, | |
); err != nil { | |
c.JSON(http.StatusBadRequest, gin.H{ | |
"message": err.Error(), | |
}) | |
return | |
} | |
fileURL := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s.mp4", | |
cfgInstance.AzureBlobName, cfgInstance.AzureBlobContainer, id) | |
// create input and output for azure | |
createAzureInput, _ := bitmovinAPI.Encoding.Inputs.Https.Create(model.HttpsInput{ | |
Name: to.Ptr(fmt.Sprintf("%s.mp4", id)), | |
Host: to.Ptr(fileURL), | |
}) | |
createAzureOutput, _ := bitmovinAPI.Encoding.Outputs.Azure.Create(model.AzureOutput{ | |
AccountName: &cfgInstance.AzureBlobName, | |
AccountKey: &cfgInstance.AzureBlobKey, | |
Container: &cfgInstance.AzureBlobContainer, | |
}) | |
// create video & audio encoding | |
createVideoEncoding, _ := bitmovinAPI.Encoding.Configurations.Video.H264.Create(model.H264VideoConfiguration{ | |
Name: to.Ptr("Getting Started H264 Codec Config 1"), | |
PresetConfiguration: model.PresetConfiguration_VOD_STANDARD, | |
Width: to.Ptr(int32(1024)), | |
Bitrate: to.Ptr(int64(1500000)), | |
Description: to.Ptr(fmt.Sprintf("%s_%d", | |
"Getting Started H264 Codec Config 1", 1500000)), | |
}) | |
// create encoding | |
createEncoding, _ := bitmovinAPI.Encoding.Encodings.Create(model.Encoding{ | |
Name: to.Ptr("Getting Started Encoding"), | |
CloudRegion: model.CloudRegion_AZURE_AUSTRALIA_SOUTHEAST, | |
}) | |
// create stream | |
createVideoStream, _ := bitmovinAPI.Encoding.Encodings.Streams.Create(*createEncoding.Id, model.Stream{ | |
InputStreams: []model.StreamInput{{ | |
InputId: createAzureInput.Id, | |
InputPath: to.Ptr(id), | |
SelectionMode: model.StreamSelectionMode_AUTO, | |
}}, | |
CodecConfigId: createVideoEncoding.Id, | |
}) | |
// create muxing createVideoMuxing createAudioMuxing | |
videoOutputPath := fmt.Sprintf("%s/video/1024_1500000/fmp4", id) | |
_, _ = bitmovinAPI.Encoding.Encodings.Muxings.Fmp4.Create(*createEncoding.Id, model.Fmp4Muxing{ | |
Outputs: []model.EncodingOutput{{ | |
Acl: []model.AclEntry{ | |
{Permission: model.AclPermission_PUBLIC_READ}, | |
}, | |
OutputId: createAzureOutput.Id, | |
OutputPath: &videoOutputPath, | |
}}, | |
Streams: []model.MuxingStream{{StreamId: createVideoStream.Id}}, | |
SegmentLength: to.Ptr(float64(4)), | |
InitSegmentName: to.Ptr("init.mp4"), | |
SegmentNaming: to.Ptr("seg_%number%.m4s"), | |
}) | |
// Create a DASH & HLS Manifest | |
createDashManifest, _ := bitmovinAPI.Encoding.Manifests.Dash.Default.Create(model.DashManifestDefault{ | |
EncodingId: createEncoding.Id, | |
ManifestName: to.Ptr("stream.mpd"), | |
Version: model.DashManifestDefaultVersion_V1, | |
Outputs: []model.EncodingOutput{{ | |
Acl: []model.AclEntry{ | |
{Permission: model.AclPermission_PUBLIC_READ}, | |
}, | |
OutputId: createAzureOutput.Id, | |
OutputPath: &id, | |
}}, | |
}) | |
createHLSManifest, _ := bitmovinAPI.Encoding.Manifests.Hls.Default.Create(model.HlsManifestDefault{ | |
EncodingId: createEncoding.Id, | |
ManifestName: to.Ptr("master.m3u8"), | |
Version: model.HlsManifestDefaultVersion_V1, | |
Outputs: []model.EncodingOutput{{ | |
Acl: []model.AclEntry{ | |
{Permission: model.AclPermission_PUBLIC_READ}, | |
}, | |
OutputId: createAzureOutput.Id, | |
OutputPath: &id, | |
}}, | |
}) | |
// Start an Encoding | |
encode, err := bitmovinAPI.Encoding.Encodings.StartWithRequestBody(*createEncoding.Id, model.StartEncodingRequest{ | |
ManifestGenerator: model.ManifestGenerator_V2, | |
VodDashManifests: []model.ManifestResource{{ManifestId: createDashManifest.Id}}, | |
VodHlsManifests: []model.ManifestResource{{ManifestId: createHLSManifest.Id}}, | |
}) |
Author
aasumitro
commented
Sep 20, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment