### Push Media Processing Task (Node.js) Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E5%A4%9A%E6%B8%85%E6%99%B0%E5%BA%A6%E8%BD%AC%E7%A0%81%E7%A4%BA%E4%BE%8B This Node.js snippet demonstrates how to push a media processing task to DogeCloud. It initializes the API call with basic parameters and the start of the workflows array. Further configuration for transcoding, snapshotting, and HLS packaging would follow. ```javascript dogecloudApi('/mps/task/push.json', { name: 'Transcode_12345678', bucket: 'video', key: 'input.mkv', notifyURL: 'https://api.example.com/doge_mps_callback', workflows: [ { cmds: [ // Transcoding, snapshotting, and HLS operations would be defined here ] } ] }) ``` -------------------------------- ### Push Media Processing Task (Python) Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E5%A4%9A%E6%B8%85%E6%99%B0%E5%BA%A6%E8%BD%AC%E7%A0%81%E7%A4%BA%E4%BE%8B This Python snippet demonstrates how to push a media processing task to DogeCloud. It configures multiple workflows including video transcoding with subtitles and watermarks, snapshot generation, and HLS packaging. The response includes the task ID on success or an error message on failure. ```python api = dogecloud_api('/mps/task/push.json', { 'name': 'Transcode_12345678', 'bucket': 'video', 'key': 'input.mkv', 'notifyURL': 'https://api.example.com/doge_mps_callback', 'workflows': [ { 'cmds': [ { 'op': 'avtranscode', 'video': { 'codec': 'H.264', 'width': 640, 'bitrate': '600k', 'subtitles': [ { 'key': 'subs/input.srt' } ], 'watermarks': [ { 'type': 'text', 'text': '水印内容', 'position': 10, 'duration': 5 } ] }, 'audio': { 'codec': 'aac', 'bitrate': '48k', 'profile': 'aac_he' } }, { 'op': 'saveas', 'key': 'output_360p_600k.mp4' } ] }, { 'cmds': [ { 'op': 'avtranscode', 'video': { 'codec': 'H.264', 'width': 1280, 'bitrate': '2000k' }, 'audio': { 'codec': 'aac', 'bitrate': '64k', 'profile': 'aac_he' } }, { 'op': 'saveas', 'key': 'output_720p_2000k.mp4' }, { 'op': 'vsample', 'format': 'jpg', 'interval': 60, 'width': 1280, 'height': 720, 'pad': True }, { 'op': 'saveas', 'key': 'output_snapshots/' } ] }, { 'cmds': [ { 'op': 'avtranscode', 'video': 'copy', 'audio': 'copy', 'hls': { 'pattern': 'output_origin.$(count).ts', 'segtime': 10 } }, { 'op': 'saveas', 'key': 'output_origin.m3u8' } ] } ] }, True) if api['code'] == 200: print(api['data']['id']) # 成功,输出任务 ID else: print("api failed: " + api['msg']) # 失败,输出错误信息 ``` -------------------------------- ### POST /mps/task/push.json Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E5%A4%9A%E6%B8%85%E6%99%B0%E5%BA%A6%E8%BD%AC%E7%A0%81%E7%A4%BA%E4%BE%8B Submits a new media processing task to the DogeCloud MPS service. The task includes a series of workflows for transcoding, watermarking, and saving output files. ```APIDOC ## POST /mps/task/push.json ### Description Submits a media processing task to the DogeCloud MPS service. This endpoint supports complex workflows including video/audio transcoding, watermarking, subtitle integration, and snapshot generation. ### Method POST ### Endpoint /mps/task/push.json ### Parameters #### Request Body - **name** (string) - Required - A unique name for the task. - **bucket** (string) - Required - The storage bucket name where the source file resides. - **key** (string) - Required - The object key of the source file. - **notifyURL** (string) - Optional - Callback URL for task completion notifications. - **workflows** (array) - Required - A list of workflow objects containing command sequences (cmds). ### Request Example { "name": "Transcode_12345678", "bucket": "video", "key": "input.mkv", "notifyURL": "https://api.example.com/doge_mps_callback", "workflows": [ { "cmds": [ { "op": "avtranscode", "video": { "codec": "H.264", "width": 640, "bitrate": "600k" }, "audio": { "codec": "aac", "bitrate": "48k" } }, { "op": "saveas", "key": "output_360p.mp4" } ] } ] } ### Response #### Success Response (200) - **code** (integer) - Status code (200). - **data** (object) - Contains the task ID. - **id** (string) - The unique identifier for the created task. #### Response Example { "code": 200, "data": { "id": "task_1234567890" } } ``` -------------------------------- ### Go: Construct Video Processing Task Parameters Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E9%9F%B3%E8%A7%86%E9%A2%91%E8%BD%AC%E7%A0%81 This Go code snippet illustrates how to define the parameters for a DogeCloud MPS task using a map. It structures the request to include task name, bucket, input key, notification URL, and a list of workflows. Each workflow contains commands for video transcoding, saving as a new file, and generating snapshots. ```go params := map[string]any{ "name": "Transcode_12345678", "bucket": "video", "key": "input.mkv", "notifyURL": "https://api.example.com/doge_mps_callback", "workflows": []map[string]any{ map[string]any{ "cmds": []map[string]any{ map[string]any{ "op": "avtranscode", "video": map[string]any{ "codec": "H.264", "width": 640, "bitrate": "600k", "subtitles": []map[string]any{ map[string]any{ "key": "subs/input.srt" } }, "watermarks": []map[string]any{ map[string]any{ "type": "text", "text": "水印内容", "position": 10, "duration": 5 } } }, "audio": map[string]any{ "codec": "aac", "bitrate": "48k", "profile": "aac_he" } }, map[string]any{ "op": "saveas", "key": "output_360p_600k.mp4" } } }, map[string]any{ "cmds": []map[string]any{ map[string]any{ "op": "avtranscode", "video": map[string]any{ "codec": "H.264", "width": 1280, "bitrate": "2000k" }, "audio": map[string]any{ "codec": "aac", "bitrate": "64k", "profile": "aac_he" } }, map[string]any{ "op": "saveas", "key": "output_720p_2000k.mp4" }, map[string]any{ "op": "vsample", "format": "jpg", "interval": 60, "width": 1280, "height": 720, "pad": true }, map[string]any{ "op": "saveas", "key": "output_snapshots/" } } }, map[string]any{ "cmds": []map[string]any{ map[string]any{ "op": "avtranscode", "video": "copy", "audio": "copy", "hls": map[string]any{ "pattern": "output_origin.$(count).ts", "segtime": 10 } }, map[string]any{ "op": "saveas", "key": "output_origin.m3u8" } } } } } // Assuming dogeAPIGet is a function that makes the API call // data := dogeAPIGet("/mps/task/push.json", params) // fmt.Println(data) ``` -------------------------------- ### Push Media Processing Task (PHP) Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E5%A4%9A%E6%B8%85%E6%99%B0%E5%BA%A6%E8%BD%AC%E7%A0%81%E7%A4%BA%E4%BE%8B This PHP snippet demonstrates how to push a media processing task to DogeCloud. It configures multiple workflows including video transcoding with subtitles and watermarks, snapshot generation, and HLS packaging. The response includes the task ID on success or an error message on failure. ```php 'Transcode_12345678', 'bucket' => 'video', 'key' => 'input.mkv', 'notifyURL' => 'https://api.example.com/doge_mps_callback', 'workflows' => array( array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => array( 'codec' => 'H.264', 'width' => 640, 'bitrate' => '600k', 'subtitles' => array( array( 'key' => 'subs/input.srt' ) ), 'watermarks' => array( array( 'type' => 'text', 'text' => '水印内容', 'position' => 10, 'duration' => 5 ) ) ), 'audio' => array( 'codec' => 'aac', 'bitrate' => '48k', 'profile' => 'aac_he' ) ), array( 'op' => 'saveas', 'key' => 'output_360p_600k.mp4' ) ) ), array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => array( 'codec' => 'H.264', 'width' => 1280, 'bitrate' => '2000k' ), 'audio' => array( 'codec' => 'aac', 'bitrate' => '64k', 'profile' => 'aac_he' ) ), array( 'op' => 'saveas', 'key' => 'output_720p_2000k.mp4' ), array( 'op' => 'vsample', 'format' => 'jpg', 'interval' => 60, 'width' => 1280, 'height' => 720, 'pad' => true ), array( 'op' => 'saveas', 'key' => 'output_snapshots/' ) ) ), array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => 'copy', 'audio' => 'copy', 'hls' => array( 'pattern' => 'output_origin.$(count).ts', 'segtime' => 10 ) ), array( 'op' => 'saveas', 'key' => 'output_origin.m3u8' ) ) ) ) ), true); if ($api && $api['code'] == 200) { var_dump($api['data']['id']); // 成功,输出任务 ID } else { var_dump($api['msg'] ?? 'Error'); // 失败,输出错误信息 } ?> ``` -------------------------------- ### Push Media Processing Task (Node.js) Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E4%BD%BF%E7%94%A8%E9%99%90%E5%88%B6 This Node.js code snippet demonstrates initiating a media processing task via the DogeCloud API. It outlines the structure for defining task parameters, including name, bucket, input key, notification URL, and a series of workflows. Each workflow contains commands for operations like transcoding and saving, with specific video and audio configurations. ```javascript dogecloudApi('/mps/task/push.json', { name: 'Transcode_12345678', bucket: 'video', key: 'input.mkv', notifyURL: 'https://api.example.com/doge_mps_callback', workflows: [ { cmds: [ { op: 'avtranscode', video: { codec: 'H.264', width: 640, bitrate: '600k', subtitles: [ { key: 'subs/input.srt' } ], watermarks: [ { type: 'text', text: '水印内容', position: 10, duration: 5 } ] }, audio: { codec: 'aac', bitrate: '48k', profile: 'aac_he' } }, { op: 'saveas', key: 'output_360p_600k.mp4' } ] }, { cmds: [ { op: 'avtranscode', video: { codec: 'H.264', width: 1280, bitrate: '2000k' }, audio: { codec: 'aac', bitrate: '64k', profile: 'aac_he' } }, { op: 'saveas', key: 'output_720p_2000k.mp4' }, { op: 'vsample', format: 'jpg', interval: 60, width: 1280, height: 720, pad: true }, { op: 'saveas', key: 'output_snapshots/' } ] }, { cmds: [ { op: 'avtranscode', video: 'copy', audio: 'copy', hls: { pattern: 'output_origin.$(count).ts', segtime: 10 } }, { op: 'saveas', key: 'output_origin.m3u8' } ] } ] }) ``` -------------------------------- ### JavaScript: Transcode Video with Subtitles and Watermarks Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E9%9F%B3%E8%A7%86%E9%A2%91%E8%BD%AC%E7%A0%81 This JavaScript snippet shows how to configure an 'avtranscode' operation to convert a video file. It includes options for setting video codec, resolution, bitrate, adding subtitles from an SRT file, and overlaying text watermarks. The output is then saved using the 'saveas' operation. ```javascript doge.mps.task.push({ name: 'Transcode_12345678', bucket: 'video', key: 'input.mkv', notifyURL: 'https://api.example.com/doge_mps_callback', workflows: [ { cmds: [ { op: 'avtranscode', video: { codec: 'H.264', width: 640, bitrate: '600k', subtitles: [ { key: 'subs/input.srt' } ], watermarks: [ { type: 'text', text: '水印内容', position: 10, duration: 5 } ] }, audio: { codec: 'aac', bitrate: '48k', profile: 'aac_he' } }, { op: 'saveas', key: 'output_360p_600k.mp4' } ] }, { cmds: [ { op: 'avtranscode', video: { codec: 'H.264', width: 1280, bitrate: '2000k' }, audio: { codec: 'aac', bitrate: '64k', profile: 'aac_he' } }, { op: 'saveas', key: 'output_720p_2000k.mp4' }, { op: 'vsample', format: 'jpg', interval: 60, width: 1280, height: 720, pad: true }, { op: 'saveas', key: 'output_snapshots/' } ] }, { cmds: [ { op: 'avtranscode', video: 'copy', audio: 'copy', hls: { pattern: 'output_origin.$(count).ts', segtime: 10 } }, { op: 'saveas', key: 'output_origin.m3u8' } ] } ] }, true, function(err, data) { console.log(err || data.id); // 有 err 则为失败,成功则输出任务 ID }); ``` -------------------------------- ### Java: Configure and Push Video Processing Tasks Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E9%9F%B3%E8%A7%86%E9%A2%91%E8%BD%AC%E7%A0%81 This Java code demonstrates how to construct a JSON payload for the DogeCloud MPS API to perform video transcoding and snapshot generation. It utilizes the `JSONObject` and `JSONArray` classes to build the nested structure representing the processing workflow, including multiple transcoding profiles and a snapshot sampling operation. ```java JSONObject params = new JSONObject(); params.put("name", "Transcode_12345678"); params.put("bucket", "video"); params.put("key", "input.mkv"); params.put("notifyURL", "https://api.example.com/doge_mps_callback"); params.put("workflows", new JSONArray() .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", new JSONObject().put("codec", "H.264").put("width", 640).put("bitrate", "600k").put("subtitles", new JSONArray() .put(new JSONObject().put("key", "subs/input.srt")) ) .put("watermarks", new JSONArray() .put(new JSONObject().put("type", "text").put("text", "水印内容").put("position", 10).put("duration", 5)) )) .put("audio", new JSONObject().put("codec", "aac").put("bitrate", "48k").put("profile", "aac_he")) ) .put(new JSONObject().put("op", "saveas").put("key", "output_360p_600k.mp4")) )) .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", new JSONObject().put("codec", "H.264").put("width", 1280).put("bitrate", "2000k")) .put("audio", new JSONObject().put("codec", "aac").put("bitrate", "64k").put("profile", "aac_he")) ) .put(new JSONObject().put("op", "saveas").put("key", "output_720p_2000k.mp4")) .put(new JSONObject().put("op", "vsample").put("format", "jpg").put("interval", 60).put("width", 1280).put("height", 720).put("pad", true)) .put(new JSONObject().put("op", "saveas").put("key", "output_snapshots/")) )) .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", "copy") .put("audio", "copy") .put("hls", new JSONObject().put("pattern", "output_origin.$(count).ts").put("segtime", 10)) ) .put(new JSONObject().put("op", "saveas").put("key", "output_origin.m3u8")) )) ); JSONObject data = dogeAPIGet("/mps/task/push.json", params); System.out.println(data.toString()); ``` -------------------------------- ### Push Media Processing Task (Python) Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E4%BD%BF%E7%94%A8%E9%99%90%E5%88%B6 This Python code snippet demonstrates how to push a media processing task to DogeCloud MPS. It configures multiple workflows for transcoding, snapshotting, and HLS packaging, specifying codecs, bitrates, resolutions, and output formats. The code includes error handling for API responses. ```python api = dogecloud_api('/mps/task/push.json', { 'name': 'Transcode_12345678', 'bucket': 'video', 'key': 'input.mkv', 'notifyURL': 'https://api.example.com/doge_mps_callback', 'workflows': [ { 'cmds': [ { 'op': 'avtranscode', 'video': { 'codec': 'H.264', 'width': 640, 'bitrate': '600k', 'subtitles': [ { 'key': 'subs/input.srt' } ], 'watermarks': [ { 'type': 'text', 'text': '水印内容', 'position': 10, 'duration': 5 } ] }, 'audio': { 'codec': 'aac', 'bitrate': '48k', 'profile': 'aac_he' } }, { 'op': 'saveas', 'key': 'output_360p_600k.mp4' } ] }, { 'cmds': [ { 'op': 'avtranscode', 'video': { 'codec': 'H.264', 'width': 1280, 'bitrate': '2000k' }, 'audio': { 'codec': 'aac', 'bitrate': '64k', 'profile': 'aac_he' } }, { 'op': 'saveas', 'key': 'output_720p_2000k.mp4' }, { 'op': 'vsample', 'format': 'jpg', 'interval': 60, 'width': 1280, 'height': 720, 'pad': True }, { 'op': 'saveas', 'key': 'output_snapshots/' } ] }, { 'cmds': [ { 'op': 'avtranscode', 'video': 'copy', 'audio': 'copy', 'hls': { 'pattern': 'output_origin.$(count).ts', 'segtime': 10 } }, { 'op': 'saveas', 'key': 'output_origin.m3u8' } ] } ] }, True) if api['code'] == 200: print(api['data']['id']) # 成功,输出任务 ID else: print("api failed: " + api['msg']) # 失败,输出错误信息 ``` -------------------------------- ### Push Media Processing Task (PHP) Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E4%BD%BF%E7%94%A8%E9%99%90%E5%88%B6 This PHP code snippet demonstrates how to push a media processing task to DogeCloud MPS. It configures multiple workflows for transcoding, snapshotting, and HLS packaging, specifying codecs, bitrates, resolutions, and output formats. The code includes error handling for API responses. ```php 'Transcode_12345678', 'bucket' => 'video', 'key' => 'input.mkv', 'notifyURL' => 'https://api.example.com/doge_mps_callback', 'workflows' => array( array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => array( 'codec' => 'H.264', 'width' => 640, 'bitrate' => '600k', 'subtitles' => array( array( 'key' => 'subs/input.srt' ) ), 'watermarks' => array( array( 'type' => 'text', 'text' => '水印内容', 'position' => 10, 'duration' => 5 ) ) ), 'audio' => array( 'codec' => 'aac', 'bitrate' => '48k', 'profile' => 'aac_he' ) ), array( 'op' => 'saveas', 'key' => 'output_360p_600k.mp4' ) ) ), array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => array( 'codec' => 'H.264', 'width' => 1280, 'bitrate' => '2000k' ), 'audio' => array( 'codec' => 'aac', 'bitrate' => '64k', 'profile' => 'aac_he' ) ), array( 'op' => 'saveas', 'key' => 'output_720p_2000k.mp4' ), array( 'op' => 'vsample', 'format' => 'jpg', 'interval' => 60, 'width' => 1280, 'height' => 720, 'pad' => true ), array( 'op' => 'saveas', 'key' => 'output_snapshots/' ) ) ), array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => 'copy', 'audio' => 'copy', 'hls' => array( 'pattern' => 'output_origin.$(count).ts', 'segtime' => 10 ) ), array( 'op' => 'saveas', 'key' => 'output_origin.m3u8' ) ) ) ) ), true); if ($api && $api['code'] == 200) { var_dump($api['data']['id']); // 成功,输出任务 ID } else { var_dump($api['msg'] ?? 'Error'); // 失败,输出错误信息 } ``` -------------------------------- ### Submit Media Processing Tasks via DogeCloud API Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA Demonstrates how to push a media processing task to DogeCloud, including complex workflows like transcoding, snapshot generation, and HLS packaging. The examples show the required JSON structure for workflows and how to verify the API response. ```PHP $api = dogecloud_api('/mps/task/push.json', array( 'name' => 'Transcode_12345678', 'bucket' => 'video', 'key' => 'input.mkv', 'workflows' => array( array( 'cmds' => array( array('op' => 'avtranscode', 'video' => array('codec' => 'H.264', 'width' => 1280, 'bitrate' => '2000k'), 'audio' => array('codec' => 'aac', 'bitrate' => '64k', 'profile' => 'aac_he')), array('op' => 'saveas', 'key' => 'output_720p_2000k.mp4'), array('op' => 'vsample', 'format' => 'jpg', 'interval' => 60, 'width' => 1280, 'height' => 720, 'pad' => true), array('op' => 'saveas', 'key' => 'output_snapshots/') ) ) ) ), true); if ($api && $api['code'] == 200) { var_dump($api['data']['id']); } else { var_dump($api['msg'] ?? 'Error'); } ``` ```Python api = dogecloud_api('/mps/task/push.json', { 'name': 'Transcode_12345678', 'bucket': 'video', 'key': 'input.mkv', 'workflows': [ { 'cmds': [ {'op': 'avtranscode', 'video': {'codec': 'H.264', 'width': 640, 'bitrate': '600k'}, 'audio': {'codec': 'aac', 'bitrate': '48k'}}, {'op': 'saveas', 'key': 'output_360p_600k.mp4'} ] } ] }, True) if api['code'] == 200: print(api['data']['id']) else: print("api failed: " + api['msg']) ``` ```Node.js dogecloudApi('/mps/task/push.json', { name: 'Transcode_12345678', bucket: 'video', key: 'input.mkv', workflows: [ { cmds: [ { op: 'avtranscode', video: { codec: 'H.264', width: 1280 }, audio: { codec: 'aac' } }, { op: 'saveas', key: 'output.mp4' } ] } ] }); ``` -------------------------------- ### Get Temporary Upload Token using DogeCloud API (Python) Source: https://docs.dogecloud.com/oss/sdk-full-python?id=%E5%BC%95%E5%85%A5-aws-s3-sdk This Python snippet shows how to call the DogeCloud API to get a temporary upload token. It specifies the channel as 'OSS_UPLOAD' and defines the scopes for the upload. The code includes error handling for API responses and formats the successful response for client-side use. ```python _key = "*"; # 或者设为 * 表示允许客户端上传到该存储空间内的任意文件(有安全风险,不推荐这样做) res = dogecloud_api('/auth/tmp_token.json', { 'channel': 'OSS_UPLOAD', 'scopes': [ _bucket + ':' + _key ] }, True) if res['code'] != 200: print(json.dumps({ 'error': 'API Error: ' + res['msg'] })) else: ret = { 'credentials': res['data']['Credentials'], 's3Bucket': res['data']['Buckets'][0]['s3Bucket'], 's3Endpoint': res['data']['Buckets'][0]['s3Endpoint'], 'keyPrefix': _key # 顺便告诉客户端本次它允许上传到哪个文件或文件前缀 } print(json.dumps(ret)) # Web 环境可以直接输出给客户端点击复制 ``` -------------------------------- ### Retrieve API Response Structure Source: https://docs.dogecloud.com/oss/api-stat-traffic?id=%E6%8E%A5%E5%8F%A3%E5%9C%B0%E5%9D%80 A sample JSON response from the DogeCloud API showing the standard envelope format containing status codes, messages, and a list of daily data objects. Each object includes a date, start timestamp, and arrays for primary data and secondary (pdata) metrics. ```json { "code": 200, "msg": "OK", "data": { "result": [ { "date": "2018-12-30", "start": 1546099200, "data": [29220178087, 21671796525, ...], "pdata": [1664368875, 1329464887, ...] }, { "date": "2018-12-31", "start": 1546185600, "data": [26855757337, 14871601950, ...], "pdata": [755562037, 826712587, ...] } ] } } ``` -------------------------------- ### Go: Construct MPS Task Parameters Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA This Go snippet shows how to define a map representing the parameters for a DogeCloud MPS task. It includes basic task details like name, bucket, key, and notification URL, along with a 'workflows' array. This structure is the foundation for initiating various media processing operations. ```go params := map[string]any{ "name": "Transcode_12345678", "bucket": "video", "key": "input.mkv", "notifyURL": "https://api.example.com/doge_mps_callback", "workflows": []map[string]any{ map[string]any{ // Workflow definition would go here } } } ``` -------------------------------- ### Java: Configure and Push MPS Transcoding Tasks Source: https://docs.dogecloud.com/mps/dev-op-avtranscode?id=%E8%BE%93%E5%85%A5%E8%BE%93%E5%87%BA This Java code demonstrates how to construct a JSON object representing an MPS task configuration, including multiple workflows for transcoding, snapshot generation, and HLS packaging. It then uses the `dogeAPIGet` method to push this task to the DogeCloud MPS service and prints the response. ```java JSONObject params = new JSONObject(); params.put("name", "Transcode_12345678"); params.put("bucket", "video"); params.put("key", "input.mkv"); params.put("notifyURL", "https://api.example.com/doge_mps_callback"); params.put("workflows", new JSONArray() .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", new JSONObject().put("codec", "H.264").put("width", 640).put("bitrate", "600k").put("subtitles", new JSONArray() .put(new JSONObject().put("key", "subs/input.srt")) ) .put("watermarks", new JSONArray() .put(new JSONObject().put("type", "text").put("text", "水印内容").put("position", 10).put("duration", 5)) )) .put("audio", new JSONObject().put("codec", "aac").put("bitrate", "48k").put("profile", "aac_he")) ) .put(new JSONObject().put("op", "saveas").put("key", "output_360p_600k.mp4")) )) .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", new JSONObject().put("codec", "H.264").put("width", 1280).put("bitrate", "2000k")) .put("audio", new JSONObject().put("codec", "aac").put("bitrate", "64k").put("profile", "aac_he")) ) .put(new JSONObject().put("op", "saveas").put("key", "output_720p_2000k.mp4")) .put(new JSONObject().put("op", "vsample").put("format", "jpg").put("interval", 60).put("width", 1280).put("height", 720).put("pad", true)) .put(new JSONObject().put("op", "saveas").put("key", "output_snapshots/")) )) .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", "copy") .put("audio", "copy") .put("hls", new JSONObject().put("pattern", "output_origin.$(count).ts").put("segtime", 10)) ) .put(new JSONObject().put("op", "saveas").put("key", "output_origin.m3u8")) )) ); JSONObject data = dogeAPIGet("/mps/task/push.json", params); System.out.println(data.toString()); ``` -------------------------------- ### Push Media Processing Task with Java Source: https://docs.dogecloud.com/mps/dev-op-avtranscode This Java code snippet demonstrates how to construct a JSON payload to push a media processing task to DogeCloud's MPS service. It includes video transcoding with subtitles and watermarks, snapshot extraction, and HLS stream generation. The task is then submitted using the `dogeAPIGet` method, and the response is printed. ```java JSONObject params = new JSONObject(); params.put("name", "Transcode_12345678"); params.put("bucket", "video"); params.put("key", "input.mkv"); params.put("notifyURL", "https://api.example.com/doge_mps_callback"); params.put("workflows", new JSONArray() .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", new JSONObject().put("codec", "H.264").put("width", 640).put("bitrate", "600k").put("subtitles", new JSONArray() .put(new JSONObject().put("key", "subs/input.srt")) ) .put("watermarks", new JSONArray() .put(new JSONObject().put("type", "text").put("text", "水印内容").put("position", 10).put("duration", 5)) )) .put("audio", new JSONObject().put("codec", "aac").put("bitrate", "48k").put("profile", "aac_he")) ) .put(new JSONObject().put("op", "saveas").put("key", "output_360p_600k.mp4")) )) .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", new JSONObject().put("codec", "H.264").put("width", 1280).put("bitrate", "2000k")) .put("audio", new JSONObject().put("codec", "aac").put("bitrate", "64k").put("profile", "aac_he")) ) .put(new JSONObject().put("op", "saveas").put("key", "output_720p_2000k.mp4")) .put(new JSONObject().put("op", "vsample").put("format", "jpg").put("interval", 60).put("width", 1280).put("height", 720).put("pad", true)) .put(new JSONObject().put("op", "saveas").put("key", "output_snapshots/")) )) .put(new JSONObject().put("cmds", new JSONArray() .put(new JSONObject() .put("op", "avtranscode") .put("video", "copy") .put("audio", "copy") .put("hls", new JSONObject().put("pattern", "output_origin.$(count).ts").put("segtime", 10)) ) .put(new JSONObject().put("op", "saveas").put("key", "output_origin.m3u8")) )) ); JSONObject data = dogeAPIGet("/mps/task/push.json", params); System.out.println(data.toString()); ``` -------------------------------- ### Push Transcoding and Snapshot Task via DogeCloud API (PHP) Source: https://docs.dogecloud.com/mps/dev-op-avtranscode This PHP code snippet demonstrates how to push a transcoding and snapshot task to the DogeCloud API. It defines a complex workflow with multiple transcoding steps for different resolutions, including adding subtitles and watermarks, generating snapshots, and creating an HLS stream. The code handles the API response to check for success or failure. ```php $api = dogecloud_api('/mps/task/push.json', array( 'name' => 'Transcode_12345678', 'bucket' => 'video', 'key' => 'input.mkv', 'notifyURL' => 'https://api.example.com/doge_mps_callback', 'workflows' => array( array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => array( 'codec' => 'H.264', 'width' => 640, 'bitrate' => '600k', 'subtitles' => array( array( 'key' => 'subs/input.srt' ) ), 'watermarks' => array( array( 'type' => 'text', 'text' => '水印内容', 'position' => 10, 'duration' => 5 ) ) ), 'audio' => array( 'codec' => 'aac', 'bitrate' => '48k', 'profile' => 'aac_he' ) ), array( 'op' => 'saveas', 'key' => 'output_360p_600k.mp4' ) ) ), array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => array( 'codec' => 'H.264', 'width' => 1280, 'bitrate' => '2000k' ), 'audio' => array( 'codec' => 'aac', 'bitrate' => '64k', 'profile' => 'aac_he' ) ), array( 'op' => 'saveas', 'key' => 'output_720p_2000k.mp4' ), array( 'op' => 'vsample', 'format' => 'jpg', 'interval' => 60, 'width' => 1280, 'height' => 720, 'pad' => true ), array( 'op' => 'saveas', 'key' => 'output_snapshots/' ) ) ), array( 'cmds' => array( array( 'op' => 'avtranscode', 'video' => 'copy', 'audio' => 'copy', 'hls' => array( 'pattern' => 'output_origin.$(count).ts', 'segtime' => 10 ) ), array( 'op' => 'saveas', 'key' => 'output_origin.m3u8' ) ) ) ) ), true); if ($api && $api['code'] == 200) { var_dump($api['data']['id']); // 成功,输出任务 ID } else { var_dump($api['msg'] ?? 'Error'); // 失败,输出错误信息 } ``` -------------------------------- ### Submit Media Processing Task via DogeCloud API Source: https://docs.dogecloud.com/mps/dev-op-avtranscode This snippet demonstrates how to use the dogecloudApi function to push a multi-workflow media processing task. It supports video transcoding, subtitle integration, watermarking, snapshot generation, and HLS stream creation. ```javascript dogecloudApi('/mps/task/push.json', { name: 'Transcode_12345678', bucket: 'video', key: 'input.mkv', notifyURL: 'https://api.example.com/doge_mps_callback', workflows: [ { cmds: [ { op: 'avtranscode', video: { codec: 'H.264', width: 640, bitrate: '600k', subtitles: [ { key: 'subs/input.srt' } ], watermarks: [ { type: 'text', text: '水印内容', position: 10, duration: 5 } ] }, audio: { codec: 'aac', bitrate: '48k', profile: 'aac_he' } }, {op: 'saveas', key: 'output_360p_600k.mp4'} ] }, { cmds: [ { op: 'avtranscode', video: {codec: 'H.264', width: 1280, bitrate: '2000k'}, audio: {codec: 'aac', bitrate: '64k', profile: 'aac_he'} }, {op: 'saveas', key: 'output_720p_2000k.mp4'}, {op: 'vsample', format: 'jpg', interval: 60, width: 1280, height: 720, pad: true}, {op: 'saveas', key: 'output_snapshots/'} ] }, { cmds: [ { op: 'avtranscode', video: 'copy', audio: 'copy', hls: {pattern: 'output_origin.$(count).ts', segtime: 10} }, {op: 'saveas', key: 'output_origin.m3u8'} ] } ] }, true, function(err, data) { console.log(err || data.id); }); ```