全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

媒体处理(Python)

最近更新时间:2026-11-18 16:33:48

媒体处理(Python)

获取视频信息

以下代码用于获取视频对象的元信息:

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'))

文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈