Example #1
0
def vframe(format,
           offset,
           width,
           height,
           rotate,
           fromBucket,
           fromKey,
           usePipeline="",
           notifyUrl=None,
           saveBucket=None,
           saveKey=None):
    #prepare fop
    params = {"offset": offset, "w": width, "h": height, "rotate": rotate}
    fop = qiniu.build_op("vframe", format, **params)
    if saveBucket != None and saveKey != None:
        fop = qiniu.op_save(fop, saveBucket, saveKey)

    #do pfop
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth, fromBucket, usePipeline, notifyUrl)
    retData, respInfo = pfop.execute(fromKey, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Example #2
0
 def vframe(self, save_bucket_name, saveas, src_bucket_name, src,
            offset=0, width=None, height=None, rotate=None,
            pipeline='vframe', notify_url=None, format='png'):
     pfop = qiniu.PersistentFop(
         auth=self._auth,
         bucket=src_bucket_name,
         pipeline=pipeline,
         notify_url=notify_url
     )
     opargs = {
         'offset': offset
     }
     if width is not None:
         opargs['w'] = width
     if height is not None:
         opargs['h'] = height
     if rotate is not None:
         opargs['rotate'] = rotate
     op = qiniu.build_op('vframe', format,
                         **opargs)
     op = qiniu.op_save(op, save_bucket_name, saveas)
     logging.debug('[op] {}'.format(op))
     ops = [op]
     ret, info = pfop.execute(src, ops, 1)
     return ret, info
Example #3
0
def vsample(bucket, key, picFormat, startSecond, duration, pattern, resolution=None, rotate=None, interval=None):
    #准备命令
    cmd = "vsample"

    #组织参数
    cmdParams = {
        "ss": startSecond,
        "t": duration,
        "pattern": pattern,
    }
    if resolution:
        cmdParams.update({"s": resolution})
    if rotate:
        cmdParams.update({"rotate": rotate})
    if interval:
        cmdParams.update({"interval": interval})

    #执行fop
    fop = qiniu.build_op(cmd, picFormat, **cmdParams)
    #默认为空,表示使用公共队列
    usePipeline = ""
    #fop处理结果通知url
    notifyUrl = None
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth, bucket, usePipeline, notifyUrl)
    retData, respInfo = pfop.execute(key, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Example #4
0
def watermark_with_image(srcBucket,
                         srcKey,
                         destFormat,
                         wmImage,
                         wmGravity="NorthEast",
                         saveBucket=None,
                         saveKey=None,
                         usePipeline=None,
                         notifyUrl=None):
    cmd = "avthumb"
    params = {
        "wmImage": qiniu.urlsafe_base64_encode(wmImage),
        "wmGravity": wmGravity,
    }

    fop = qiniu.build_op(cmd, destFormat, **params)
    #saveas
    if saveBucket != None and saveKey != None:
        fop = qiniu.op_save(fop, saveBucket, saveKey)

    #pfop
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth,
                               srcBucket,
                               pipeline=usePipeline,
                               notify_url=notifyUrl)
    retData, respInfo = pfop.execute(srcKey, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Example #5
0
def avthumb_m3u8(type, dstFormat):
    #准备命令
    cmd = "avthumb/m3u8"

    if type == "wifi":
        segtime = "10"
        videoBitRate = "440k"
    elif type == "3g":
        segtime = "5"
        videoBitRate = "240k"

    resolution = "400x244"
    cmdParams = {
        "segtime": segtime,
        "vb": videoBitRate,
        "s": resolution,
        "vodec": "libx264",
    }

    #结果保存空间名称
    saveBucket = "qiniu-lab"
    if type == "wifi":
        saveKey = u"七牛云存储视频名片_wifi.m3u8".encode("utf-8")
    elif type == "3g":
        saveKey = u"七牛云存储视频名片_3g.m3u8".encode("utf-8")

    #构建fop指令
    fop = qiniu.build_op(cmd, dstFormat, **cmdParams)
    #指定保存的空间和key,否则将以结果的hash值作为文件名保存
    fop = qiniu.op_save(fop, saveBucket, saveKey)

    #执行fop操作
    fromBucket = "qiniu-lab"
    fromKey = u"七牛云存储视频名片.mp4".encode("utf-8")
    #默认为空,表示使用公共队列
    usePipeline = ""
    #私有队列,根据你实际情况设置
    usePipeline = "fff"
    #fop处理结果通知url
    notifyUrl = None
    auth = qiniu.Auth(accessKey, secretKey)
    pfop = qiniu.PersistentFop(auth, fromBucket, usePipeline, notifyUrl)
    retData, respInfo = pfop.execute(fromKey, [fop], force=None)
    if retData != None:
        print("PersistentId:" + retData["persistentId"])
    else:
        print("Error:")
        print("--StatusCode:" + str(respInfo.status_code))
        print("--Reqid:" + respInfo.req_id)
        print("--Message:" + respInfo.error)
Example #6
0
 def avconcat(self, save_bucket_name, saveas, base_bucket_name, base,
              urls, mode='2', format='mp4',
              pipeline='concatevideo', notify_url=None):
     pfop = qiniu.PersistentFop(
         auth=self._auth,
         bucket=base_bucket_name,
         pipeline=pipeline,
         notify_url=notify_url
     )
     op = qiniu.build_op('avconcat', mode, format=format)
     if len(urls) > 5:
         raise ValueError('cannot append more then 5 videos')
     encoded_keys = [qiniu.urlsafe_base64_encode(url) for url in urls]
     encoded_keys.insert(0, op)
     op = '/'.join(encoded_keys)
     op = qiniu.op_save(op, save_bucket_name, saveas)
     logging.debug('[op] {}'.format(op))
     ops = [op]
     ret, info = pfop.execute(base, ops, 1)
     return ret, info
Example #7
0
# coding: utf-8
# zhangtaichao
import config.param as param
from qiniu import Auth, PersistentFop, build_op, op_save

key_src = '赤壁赋第一讲赏读.mp4'

q = Auth(param.AccessKey, param.SecretKey)

pfop = PersistentFop(q, param.bucket, param.pipeline)
#op = op_save('avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240', saved_bucket, saved_key)
#op = op_save('avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240')

ops = {'r': 24, 'vb': '56k'}
op = build_op('avthumb', 'flv', **ops)
ops = []
ops.append(op)
ret, info = pfop.execute(key_src, ops, 1)
print(info)
assert ret['persistentId'] is not None
Example #8
0
# coding: utf-8
# zhangtaichao
import config.param as param
from qiniu import Auth, PersistentFop, build_op, op_save

key_src= '赤壁赋第一讲赏读.mp4'

q = Auth(param.AccessKey,param.SecretKey)

pfop = PersistentFop(q,param.bucket,param.pipeline)
#op = op_save('avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240', saved_bucket, saved_key)
#op = op_save('avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240')

ops = {
    'r':24,
    'vb':'56k'
}
op = build_op('avthumb','flv',**ops)
ops = []
ops.append(op)
ret, info = pfop.execute(key_src, ops, 1)
print(info)
assert ret['persistentId'] is not None