I am adding watermark in uploaded video by http google cloud function but my code is return on ffmpeg non zero. my python code
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")
In this code accessing video add watermark also accessing from bucket and applying with ffmpeg and uploading.
error is:-
raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command 'ffmpeg -i /tmp/Upload/Video/1060/ad69ec74-49db-4fdb-b118-d23b9468a7b8.mp4 -i /temp/watermark.png -filter_complex overlay=10:10 -codec:a copy -preset ultrafast -async 1 /tmp/Upload/Video/1060/ad69ec74-49db-4fdb-b118-d23b9468a7b8_.mp4' returned non-zero exit status 1.
I have solved and using with http request base trigger in google cloud function. May be help to someone in future
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.