最近更新时间:2026-11-18 16:33:48
以下代码用于获取视频对象的元信息:
from ks3.connection import Connection
conn = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
b = conn.get_bucket('<YOUR_BUCKET_NAME>')
ret = b.get_object_process('<YOUR_VIDEO_KEY>', 'video/info')
print('request_id:', ret.request_id)
print(ret.data.decode('utf-8'))以下代码用于截取视频指定时间点的画面:
from ks3.connection import Connection
conn = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
b = conn.get_bucket('<YOUR_BUCKET_NAME>')
ret = b.get_object_process('<YOUR_VIDEO_KEY>', 'video/snapshot,t_7000,w_800')
open('snapshot.jpg', 'wb').write(ret.data)以下代码用于截图并另存为指定对象:
import base64
from ks3.connection import Connection
conn = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
b = conn.get_bucket('<YOUR_BUCKET_NAME>')
saveas_object = base64.b64encode(b'<YOUR_SAVEAS_OBJECT>').decode('utf-8')
saveas_bucket = base64.b64encode(b'<YOUR_SAVEAS_BUCKET>').decode('utf-8')
body = 'x-kss-process=video/snapshot,t_10000,f_png,w_800,h_600|sys/saveas,o_%s,b_%s' % (
saveas_object, saveas_bucket)
ret = b.post_process_task('<YOUR_VIDEO_KEY>', body)
print('request_id:', ret.request_id)以下代码用于提交异步视频转码任务:
import base64
from ks3.connection import Connection
conn = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
b = conn.get_bucket('<YOUR_BUCKET_NAME>')
saveas_object = base64.b64encode(b'<YOUR_SAVEAS_OBJECT>').decode('utf-8')
saveas_bucket = base64.b64encode(b'<YOUR_SAVEAS_BUCKET>').decode('utf-8')
body = 'x-kss-async-process=video/convert,f_mp4,vc_h264,s_1920x1080|sys/saveas,o_%s,b_%s' % (
saveas_object, saveas_bucket)
ret = b.post_async_process_task('<YOUR_VIDEO_KEY>', body)
print('request_id:', ret.request_id)
print(ret.data.decode('utf-8'))以下代码用于按 processId 查询异步任务:
from ks3.connection import Connection
conn = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
b = conn.get_bucket('<YOUR_BUCKET_NAME>')
ret = b.get_async_process_task('<YOUR_PROCESS_ID>')
print('request_id:', ret.request_id)
print(ret.data.decode('utf-8'))以下代码用于分页列举异步任务:
from ks3.connection import Connection
conn = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
b = conn.get_bucket('<YOUR_BUCKET_NAME>')
ret = b.list_async_process_task(process_type='video', max_results=10)
print('request_id:', ret.request_id)
print(ret.data.decode('utf-8'))以下代码用于自动翻页拉取全部异步任务:
from ks3.connection import Connection
conn = Connection('<YOUR_ACCESS_KEY>', '<YOUR_SECRET_KEY>', host='<YOUR_REGION_ENDPOINT>')
b = conn.get_bucket('<YOUR_BUCKET_NAME>')
for page in b.list_all_async_process_task(process_type='video', max_results=10):
print(page.data.decode('utf-8'))
纯净模式
