-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from tencentyun/master
同步master修改到fork的分支
- Loading branch information
Showing
8 changed files
with
520 additions
and
188 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,174 @@ | ||
# -*- coding=utf-8 | ||
from qcloud_cos import CosConfig | ||
from qcloud_cos import CosS3Client | ||
from qcloud_cos.cos_comm import CiDetectType | ||
|
||
import sys | ||
import logging | ||
import os | ||
import time | ||
|
||
# 腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7以及Python3.x | ||
|
||
# https://cloud.tencent.com/document/product/436/48987 | ||
|
||
logging.basicConfig(level=logging.INFO, stream=sys.stdout) | ||
|
||
# 设置用户属性, 包括secret_id, secret_key, region | ||
# appid已在配置中移除,请在参数Bucket中带上appid。Bucket由bucketname-appid组成 | ||
# 这里秘钥是从环境变量取得,如自己测试可改成自己对应的秘钥 | ||
secret_id = os.environ["SECRETID"] # 替换为用户的 SecretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi | ||
secret_key = os.environ["SECRETKEY"] # 替换为用户的 SecretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi | ||
region = 'ap-chongqing' # 替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket | ||
# COS支持的所有region列表参见https://www.qcloud.com/document/product/436/6224 | ||
token = None # 如果使用永久密钥不需要填入token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见https://cloud.tencent.com/document/product/436/14048 | ||
|
||
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme='https') # 获取配置对象 | ||
client = CosS3Client(config) | ||
|
||
|
||
bucket_name = 'demo-1253960454' | ||
|
||
|
||
def ci_get_media_queue(): | ||
# 查询媒体队列信息 | ||
response = client.ci_get_media_queue( | ||
Bucket=bucket_name | ||
) | ||
print(response) | ||
return response | ||
|
||
def ci_create_media_transcode_watermark_jobs(): | ||
# 创建转码任务 | ||
body = { | ||
'Input':{ | ||
'Object':'117374C.mp4' | ||
}, | ||
'QueueId': 'pe943803693bd42d1a3105804ddaee525', | ||
'Tag': 'Transcode', | ||
'Operation': { | ||
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'}, | ||
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5', | ||
# "WatermarkTemplateId": ["", ""], | ||
'Watermark': [ | ||
{ | ||
'Type':'Text', | ||
'Pos':'TopRight', | ||
'LocMode':'Absolute', | ||
'Dx':'64', | ||
'Dy': '64', | ||
'StartTime':'0', | ||
'EndTime':'1000.5', | ||
'Text': { | ||
'Text': '水印内容', | ||
'FontSize': '90', | ||
'FontType': 'simfang.ttf', | ||
'FontColor': '0xFFEEFF', | ||
'Transparency': '100', | ||
}, | ||
}, | ||
{ | ||
'Type':'Image', | ||
'Pos':'TopLeft', | ||
'LocMode':'Absolute', | ||
'Dx':'100', | ||
'Dy': '100', | ||
'StartTime':'0', | ||
'EndTime':'1000.5', | ||
'Image': { | ||
'Url': 'http://'+bucket_name+".cos."+region+".myqcloud.com/1215shuiyin.jpg", | ||
'Mode': 'Fixed', | ||
'Width': '128', | ||
'Height': '128', | ||
'Transparency': '100', | ||
}, | ||
} | ||
] | ||
} | ||
} | ||
# dict中数组类型的标签,都需要特殊处理 | ||
lst = [ | ||
'<Watermark>', | ||
'<WatermarkTemplateId>', | ||
'</WatermarkTemplateId>', | ||
'</Watermark>' | ||
] | ||
response = client.ci_create_media_jobs( | ||
Bucket=bucket_name, | ||
Jobs=body, | ||
Lst=lst, | ||
ContentType='application/xml' | ||
) | ||
print(response) | ||
return response | ||
|
||
def ci_create_media_transcode_jobs(): | ||
# 创建转码任务 | ||
body = { | ||
'Input':{ | ||
'Object':'117374C.mp4' | ||
}, | ||
'QueueId': 'pe943803693bd42d1a3105804ddaee525', | ||
'Tag': 'Transcode', | ||
'Operation': { | ||
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'}, | ||
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5' | ||
} | ||
} | ||
response = client.ci_create_media_jobs( | ||
Bucket=bucket_name, | ||
Jobs=body, | ||
Lst={}, | ||
ContentType='application/xml' | ||
) | ||
print(response) | ||
return response | ||
|
||
def ci_list_media_transcode_jobs(): | ||
# 转码任务 | ||
response = client.ci_list_media_jobs( | ||
Bucket=bucket_name, | ||
QueueId='pe943803693bd42d1a3105804ddaee525', | ||
Tag='Transcode', | ||
ContentType='application/xml' | ||
) | ||
print(response) | ||
return response | ||
|
||
def ci_get_media_transcode_jobs(): | ||
# 转码任务 | ||
response = client.ci_get_media_jobs( | ||
Bucket=bucket_name, | ||
JobIDs='j3feb7ccc28fc11eca50b6f68c211dc6c,jb83bcc5a28fb11ecae48a1f29371c5f8', | ||
ContentType='application/xml' | ||
) | ||
print(response) | ||
return response | ||
|
||
if __name__ == "__main__": | ||
#ci_get_media_queue() | ||
ci_get_media_transcode_jobs() | ||
#ci_create_media_transcode_jobs() | ||
# -*- coding=utf-8 | ||
from qcloud_cos import CosConfig | ||
from qcloud_cos import CosS3Client | ||
from qcloud_cos.cos_comm import CiDetectType | ||
|
||
import sys | ||
import logging | ||
import os | ||
import time | ||
|
||
# 腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7以及Python3.x | ||
|
||
# https://cloud.tencent.com/document/product/436/48987 | ||
|
||
logging.basicConfig(level=logging.INFO, stream=sys.stdout) | ||
|
||
# 设置用户属性, 包括secret_id, secret_key, region | ||
# appid已在配置中移除,请在参数Bucket中带上appid。Bucket由bucketname-appid组成 | ||
# 这里秘钥是从环境变量取得,如自己测试可改成自己对应的秘钥 | ||
secret_id = os.environ["SECRETID"] # 替换为用户的 SecretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi | ||
secret_key = os.environ["SECRETKEY"] # 替换为用户的 SecretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi | ||
region = 'ap-chongqing' # 替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket | ||
# COS支持的所有region列表参见https://www.qcloud.com/document/product/436/6224 | ||
token = None # 如果使用永久密钥不需要填入token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见https://cloud.tencent.com/document/product/436/14048 | ||
|
||
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme='https') # 获取配置对象 | ||
client = CosS3Client(config) | ||
|
||
|
||
bucket_name = 'demo-1253960454' | ||
|
||
|
||
def ci_get_media_queue(): | ||
# 查询媒体队列信息 | ||
response = client.ci_get_media_queue( | ||
Bucket=bucket_name | ||
) | ||
print(response) | ||
return response | ||
|
||
def ci_create_media_transcode_watermark_jobs(): | ||
# 创建转码任务 | ||
body = { | ||
'Input':{ | ||
'Object':'117374C.mp4' | ||
}, | ||
'QueueId': 'pe943803693bd42d1a3105804ddaee525', | ||
'Tag': 'Transcode', | ||
'Operation': { | ||
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'}, | ||
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5', | ||
# "WatermarkTemplateId": ["", ""], | ||
'Watermark': [ | ||
{ | ||
'Type':'Text', | ||
'Pos':'TopRight', | ||
'LocMode':'Absolute', | ||
'Dx':'64', | ||
'Dy': '64', | ||
'StartTime':'0', | ||
'EndTime':'1000.5', | ||
'Text': { | ||
'Text': '水印内容', | ||
'FontSize': '90', | ||
'FontType': 'simfang.ttf', | ||
'FontColor': '0xFFEEFF', | ||
'Transparency': '100', | ||
}, | ||
}, | ||
{ | ||
'Type':'Image', | ||
'Pos':'TopLeft', | ||
'LocMode':'Absolute', | ||
'Dx':'100', | ||
'Dy': '100', | ||
'StartTime':'0', | ||
'EndTime':'1000.5', | ||
'Image': { | ||
'Url': 'http://'+bucket_name+".cos."+region+".myqcloud.com/1215shuiyin.jpg", | ||
'Mode': 'Fixed', | ||
'Width': '128', | ||
'Height': '128', | ||
'Transparency': '100', | ||
}, | ||
} | ||
] | ||
} | ||
} | ||
# dict中数组类型的标签,都需要特殊处理 | ||
lst = [ | ||
'<Watermark>', | ||
'<WatermarkTemplateId>', | ||
'</WatermarkTemplateId>', | ||
'</Watermark>' | ||
] | ||
response = client.ci_create_media_jobs( | ||
Bucket=bucket_name, | ||
Jobs=body, | ||
Lst=lst, | ||
ContentType='application/xml' | ||
) | ||
print(response) | ||
return response | ||
|
||
def ci_create_media_transcode_jobs(): | ||
# 创建转码任务 | ||
body = { | ||
'Input':{ | ||
'Object':'117374C.mp4' | ||
}, | ||
'QueueId': 'pe943803693bd42d1a3105804ddaee525', | ||
'Tag': 'Transcode', | ||
'Operation': { | ||
'Output':{'Bucket':bucket_name, 'Region':region, 'Object':'117374C_output.mp4'}, | ||
'TemplateId': 't02db40900dc1c43ad9bdbd8acec6075c5' | ||
} | ||
} | ||
response = client.ci_create_media_jobs( | ||
Bucket=bucket_name, | ||
Jobs=body, | ||
Lst={}, | ||
ContentType='application/xml' | ||
) | ||
print(response) | ||
return response | ||
|
||
def ci_list_media_transcode_jobs(): | ||
# 转码任务 | ||
response = client.ci_list_media_jobs( | ||
Bucket=bucket_name, | ||
QueueId='pe943803693bd42d1a3105804ddaee525', | ||
Tag='Transcode', | ||
ContentType='application/xml' | ||
) | ||
print(response) | ||
return response | ||
|
||
def ci_get_media_transcode_jobs(): | ||
# 转码任务 | ||
response = client.ci_get_media_jobs( | ||
Bucket=bucket_name, | ||
JobIDs='j3feb7ccc28fc11eca50b6f68c211dc6c,jb83bcc5a28fb11ecae48a1f29371c5f8', | ||
ContentType='application/xml' | ||
) | ||
print(response) | ||
return response | ||
|
||
def get_media_info(): | ||
# 获取媒体信息 | ||
response = client.get_media_info( | ||
Bucket=bucket_name, | ||
Key='demo.mp4' | ||
) | ||
print(response) | ||
|
||
def get_snapshot(): | ||
# 产生同步截图 | ||
response = client.get_snapshot( | ||
Bucket=bucket_name, | ||
Key='demo.mp4', | ||
Time='1.5', | ||
Width='480', | ||
Format='png' | ||
) | ||
print(response) | ||
response['Body'].get_stream_to_file('snapshot.jpg') | ||
|
||
|
||
if __name__ == "__main__": | ||
ci_get_media_queue() | ||
#ci_get_media_transcode_jobs() | ||
#ci_create_media_transcode_jobs() | ||
#get_media_info() | ||
#get_snapshot() |
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
Oops, something went wrong.