使用谷歌云功能python在视频中添加水印



我正在通过http谷歌云功能在上传的视频中添加水印,但我的代码是在ffmpeg非零上返回的。我的python代码

import os
from google.cloud import storage
from subprocess import check_output
from videoprops import get_video_properties

def hello_world(request):
client = storage.Client()
bucket = client.get_bucket('bucket_name')
request_json = request.get_json()
req_data = request.get_json()
name = req_data['file']
videofile_name = req_data['file_name']
os.makedirs('/tmp/'+os.path.dirname(name), exist_ok=True)
file_name = '/tmp/' + name
output_file_name = '/tmp/' + name.split('.')[0] + '_.'+name.split('.')[1]
print(output_file_name)
logo_path = '/temp/watermark.png'
logo_name = 'watermark.png'
print('logo found')
print(file_name)
try:
os.remove(file_name)
except OSError:
pass
try:
os.remove(logo_path)
except OSError:
pass
print("File has been removed")
# Downloading the video to the cloud functions
blob = bucket.get_blob(name)
blob.download_to_filename(file_name)
blob_logo = bucket.get_blob(logo_name)
blob_logo.download_to_filename(logo_path)
print("Video Downloaded")
props = get_video_properties(file_name)
if os.path.exists(file_name):
print("NEW MP4 EXISTS")
#   check_output('ffmpeg  -itsoffset -4  -i '+file_name+' -vcodec mjpeg -vframes 1 -an -f rawvideo -s '+str(props['width'])+'x'+str(props['height'])+' '+thumbnail_file_name, shell=True)
#   thumbnail_blob = bucket.blob(os.path.dirname(name)+'/thumbnail.jpg')
#   thumbnail_blob.upload_from_filename(thumbnail_file_name)
# 19-7-2020
check_output('ffmpeg  -i '+file_name+' -i '+logo_path +
' -filter_complex overlay=10:10 -codec:a copy -preset ultrafast -async 1 '+output_file_name, shell=True)
thumbnail_blob = bucket.blob(
os.path.dirname(name) + '/'+videofile_name)
thumbnail_blob.upload_from_filename(output_file_name)
# -------------------------------------
else:
print("MP4 not created")
print("uploaded")

在这个代码访问视频添加水印也从桶访问和应用ffmpeg和上传。

错误为:-

引发CalledProcessError(retcode,process.args,子流程。CalledProcessError:命令"ffmpeg-i/tmp/Upload/Video/1060/ad69ec74-49db-4fdb-b118-d23b9468a7b8.mp4-i/temp/watermark.png-filter_complex overlay=10:10-编解码器:一个副本-预设超快-异步1/tmp/Upload/Video/1060/ad69ec74-469db-4fdb-b118-D23b9468 a7b8_.mp4"返回非零退出状态1。

我已经解决并使用了谷歌云函数中的http请求基触发器。可能对未来中的某个人有所帮助

import os
import os.path
from google.cloud import storage
from subprocess import check_output
from videoprops import get_video_properties

def hello_world(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values that can be turned into a
Response object using
# flask.Flask.make_response>`.
`make_response <http://flask.pocoo.org/docs/1.0/api/
"""
client = storage.Client()
bucket = client.get_bucket('showtalentbucket')
request_json = request.get_json()
req_data = request.get_json()
name = req_data['file']
videofile_name = req_data['file_name']
os.makedirs('/tmp/'+os.path.dirname(name), exist_ok=True)
file_name = '/tmp/' + name
output_file_name = '/tmp/' + name.split('.')[0] + '_.'+name.split('.')[1]
mp4_output_file_name = '/tmp/' + 
name.split('.')[0] + '__.'+name.split('.')[1]
print(output_file_name)
logo_path = '/tmp/watermark.png'
logo_name = 'watermark.png'
print('logo found')
print(file_name)
try:
os.remove(file_name)
except OSError:
pass
try:
os.remove(logo_path)
except OSError:
pass
print("File has been removed")
# Downloading the video to the cloud functions
blob = bucket.get_blob(name)
blob.download_to_filename(file_name)
blob_logo = bucket.get_blob(logo_name)
blob_logo.download_to_filename(logo_path)
print("Video Downloaded")
props = get_video_properties(file_name)
if os.path.exists(file_name):
print("NEW MP4 EXISTS")

check_output('ffmpeg  -i '+file_name+' -i '+logo_path +
' -filter_complex overlay=10:10 -codec:a copy -preset ultrafast -async 1 '+output_file_name, shell=True)
if os.path.splitext(name)[1].lower().startswith('.mov'):
check_output('ffmpeg  -itsoffset -4  -i '+output_file_name +
' -acodec copy -vcodec copy -f mov '+mp4_output_file_name, shell=True)
thumbnail_blob = bucket.blob(
os.path.dirname(name) + '/'+videofile_name)
thumbnail_blob.upload_from_filename(mp4_output_file_name)
else:
thumbnail_blob = bucket.blob(
os.path.dirname(name) + '/'+videofile_name)
thumbnail_blob.upload_from_filename(output_file_name)
# -------------------------------------
else:
print("MP4 not created")
print("uploaded")

相关内容

  • 没有找到相关文章

最新更新