A template in AuroraCloud VOD is a predefined configuration that specifies how a video should be processed during transcoding. It includes parameters such as the output format (for example, MP4 or HLS), video and audio codecs, resolution, bitrate, watermark placement, and optional encryption settings. By creating a template, you can standardize and reuse transcoding settings across multiple videos. This not only ensures consistency in output quality and format but also simplifies future transcoding tasks by eliminating the need to manually configure each parameter every time
This guide will walk you through the process of creating a new template on the Visionular platform. Here are the detailed steps to create a template:
Log in to your Visionular account.
Click on "Templates" in the left navigation bar.
On the "Templates" page, click the "Create a template" button.
Template Name: Enter a unique name for your template. The name must be unique and can contain letters, numbers, underscores, spaces, and other characters, up to 100 characters.
Template Description: Enter a description for your template, up to 100 characters.
Container Format: Select the container format from the dropdown menu, the default option is MP4.
Video Codec: Select the video codec format from the dropdown menu, the default option is H.264.
Quality: Select the encoding quality from the dropdown menu, ranging from [1, 10], the default value is 5. The higher the number, the better the video quality.
Frame Rate: Enter the frame rate, the default value is 0 fps, which means the original frame rate will be preserved.
Resolution Type: Select the resolution type from the dropdown menu, the default option is "Same as input".
Audio Codec: The audio codec format is set to AAC, no other options are selectable.
Audio Sampling Rate: Select the audio sampling rate from the dropdown menu, the default option is 44.1kHz.
Audio Channels: Select the audio channels from the dropdown menu, the default option is Stereo (stereo).
Audio Bitrate: Enter the audio bitrate, the default value is 64kbps.
Enable Text Watermark Switch: Turn on this option to add a text watermark to the video.
Enter Text Content (Content): Enter the text you want to display on the video here.
Select Font Color (Font Color): Choose the color of the text from the dropdown menu to ensure it is clearly visible in the video.
Select Font Size (Font Size): Choose the size of the text from the dropdown menu, the default value is 16, which can be adjusted to fit the video content.
Select Font Type (Font Type): Choose the font style of the text from the dropdown menu to match the style or branding requirements of the video.
Select Position (Position): Choose the position of the text watermark on the video from the dropdown menu. Available positions typically include:
Enter Time Interval (Time Interval): Set the duration for which the text watermark will be displayed in the video, ranging from [1, 60] seconds.
Enable Image Watermark Switch: Turn on this option to add an image watermark to the video.
Enter Image URL (Image URL): Enter the URL of the image file here, ensuring the image file is accessible.
Select Position (Position): Choose the position of the image watermark on the video from the dropdown menu. Available positions are the same as for text watermarks, including:
Enter Image Size (Size): Set the size of the image watermark, in the format "width px ~ height px". If not set, the image will maintain its original size.
Enter Time Interval (Time Interval): Set the duration for which the image watermark will be displayed in the video, ranging from [1, 60] seconds.
After confirming all settings are correct, click the "Create" button to create the template.
import requestsfrom typing import Optional, Dict, Any, Listdef create_hls_template(api_key: str,api_secret: str,template_name: str,adaptive_streams: List[Dict[str, Any]],format: str = "hls",acodec: str = "aac",seg_time: int = 10,seg_type: str = "fmp4",description: Optional[str] = None,**kwargs) -> bool:"""Create an HLS template with customizable parametersArgs:api_key: Access Key ID for API authenticationapi_secret: Access Key Secret for API authenticationtemplate_name: Name of the templateadaptive_streams: List of dictionaries containing stream configurationsformat: Output format (default: hls)acodec: Audio codec (default: aac)seg_time: HLS segment duration in seconds (default: 10)seg_type: Segment type (default: fmp4)description: Optional description for the template**kwargs: Additional optional parameters for the templateReturns:bool: True if creation successful, False otherwise"""url = "https://api.visionular.com/vodencoding/v1/add_template"headers = {"Content-Type": "application/json","auth-type": "use-basic"}payload = {"template_name": template_name,"format": format,"acodec": acodec,"seg_time": seg_time,"seg_type": seg_type,"adaptive_streams": adaptive_streams,**kwargs}# Add description if providedif description:payload["description"] = descriptiontry:print("Sending request:", payload)response = requests.post(url,headers=headers,auth=(api_key, api_secret),json=payload,verify=True)# Print full response for debuggingprint("Response status:", response.status_code)print("Response headers:", response.headers)print("Response content:", response.text)response.raise_for_status()result = response.json()if result["code"] == 0:print(f"Template '{template_name}' created successfully!")return Trueelse:print(f"Template creation failed: {result['msg']}")return Falseexcept requests.exceptions.HTTPError as e:print(f"HTTP Error: {e}")print(f"Response content: {e.response.text if e.response else 'No response'}")return Falseexcept Exception as e:print(f"Unexpected error: {e}")return False# Example usageif __name__ == "__main__":api_key = "your_api_key"api_secret = "your_api_secret"# Define the template configurationfrom datetime import datetimeimport randomimport string# Generate unique template name with timestamp and random suffixrandom_suffix = ''.join(random.choices(string.ascii_letters + string.digits, k=4))template_name = f"HLS_720p_1080p_{random_suffix}"adaptive_streams = [# 1080p stream{"vcodec": "h264","resolution": "1080p", # 1920x1080"quality": 8, # High quality"video_bitrate": 2000000, # 2 Mbps"audio_bitrate": 128000 # 128 kbps audio},# 720p stream{"vcodec": "h264","resolution": "720p", # 1280x720"quality": 7, # Medium-high quality"video_bitrate": 1500000, # 1.5 Mbps"audio_bitrate": 96000 # 96 kbps audio}]description = "HLS template with 720p and 1080p streams, max bitrate 2Mbps"# Create the HLS templateif create_hls_template(api_key=api_key,api_secret=api_secret,template_name=template_name,adaptive_streams=adaptive_streams,description=description):print("HLS template created successfully!")else:print("Failed to create HLS template.")