Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Islander« (13. Juli 2016, 07:02)
Benutzerinformationen überspringen
Wohnort: Netherlands
Beruf: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer
: https://pame.virtualtuur.comHi Islander!In the Pano Video Converter, on clicking convert, a command line window opens but closes immediately and nothing happens. I tried with all the possible settings.
I've freezed a video capture of the error appearing in the blink of a eye.
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
import osimport stat
import shutil
import sys
import boto3
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# clean out /tmp
folder = '/tmp'
for the_file in os.listdir(folder):
file_path = os.path.join(folder, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path): shutil.rmtree(file_path)
except Exception as e:
logger.info("cleanup /tmp exception: " + e)
print(e)
lambda_tmp_dir = '/tmp' # Lambda fuction can use this directory.
# ffmpeg loading
ffmpeg = "{0}/ffmpeg".format(lambda_tmp_dir)
shutil.copyfile('/var/task/ffmpeg', ffmpeg)
os.environ['ffmpeg'] = ffmpeg
os.chmod(ffmpeg, os.stat(ffmpeg).st_mode | stat.S_IRWXU)
os.chmod("/tmp", stat.S_IRWXU)
s3 = boto3.client('s3')
# Make sure the target directory exists
def prepare_path(target):
if os.path.exists(target):
logger.info("{0} exists".format(target))
shutil.rmtree(target)
os.mkdir(target)
# Copy/download the file to local
# standard way of doing things
"""
def copy_object(bucket, source, dest):
name = source.split('/')[-1]
local_file = "{0}/{1}".format(dest, name)
logger.debug("{0} to {1}".format(source, local_file))
s3.download_file(bucket, source, local_file)
if os.path.exists(local_file):
b = open(local_file, "r")
return local_file
"""
# The following function can be used to upload directory to s3 via boto.
def upload_files(path, bucket, mediaId, fileType):
logger.info("upload_files() path-> " + path + " | bucket-> " + bucket + " | mediaId-> " + mediaId + " | fileType-> " + fileType)
for subdir, dirs, files in os.walk(path):
for file in files:
full_path = os.path.join(subdir, file)
with open(full_path, 'rb') as data:
thisKey = 'media/' + fileType + '/' + mediaId + '/' + full_path[len(path) + 1:]
logger.info("upload_files() thisKey-> " + thisKey)
s3.put_object(Bucket=bucket, Key=thisKey, Body=data)
def create_presigned_url(bucket_name, object_name, expiration=3600):
"""Generate a presigned URL to share an S3 object
:param bucket_name: string
:param object_name: string
:param expiration: Time in seconds for the presigned URL to remain valid
:return: Presigned URL as string. If error, returns None.
"""
# Generate a presigned URL for the S3 object
s3_client = boto3.client('s3')
try:
response = s3_client.generate_presigned_url('get_object',
Params={'Bucket': bucket_name,
'Key': object_name},
ExpiresIn=expiration)
except ClientError as e:
logging.error(e)
return None
# The response contains the presigned URL
return response
def ffmpeg_lambda_handler(event, context):
# determine the ID
the_file_path = event['Records'][0]['s3']['object']['key']
the_bucket = event['Records'][0]['s3']['bucket']['name']
the_file_path_array = the_file_path.split('/')
the_file_name = the_file_path_array[-1]
the_file_name_array = the_file_name.split('.')
mediaId = str(the_file_name_array[0])
fileType = the_file_path_array[1]
# create the local_path
local_path = "{0}/{1}".format(lambda_tmp_dir, mediaId)
prepare_path(local_path)
# copy_object to destination path.
# localInputFile = copy_object(the_bucket, the_file_path, local_path)
localInputFile = create_presigned_url(the_bucket, the_file_path, expiration=3600)
# ++++++++++++++++++++++++++++++++++++++++ FFMPEG ++++++++++++++++++++++++++++++++++++++++++
audioPath = "{0}/{1}".format(local_path, 'audio_file.mp3')
if fileType == 'transition':
# GoPro settings
brPairs = [[1080, 16000], [1080, 7000], [720, 3000], [540, 1500], [224, 440]]
else:
# Spherical Video settings
brPairs = [[1920, 16000], [720, 3000], [960, 7000], [1440, 16000], [2048, 40000]]
for p in brPairs:
# size
thisKey = str(p[0])
# get bit-rate
bitrate = p[1]
# buffer rate
bufs = str(bitrate * 0.75)
# convert num to string
bitstring = str(bitrate)
# final file path
final_file = thisKey + '_' + bitstring + '.mp4'
localOutputPath = "{0}/{1}".format(local_path, final_file)
localOutputPath = str(localOutputPath)
s3Path = 's3://xplorit-media/processor/360video/170968.mp4'
httpsPath = 'https://s3-us-west-2.amazonaws.com/xplorit-media/processor/360video/170968.mp4'
buff_temp_name = str('temp_' + mediaId + '_' + thisKey + '_' + bitstring)
localTempPath = "{0}/{1}".format(local_path, buff_temp_name)
localTempPath = str(localTempPath)
myPassLogFile = folder + '/my_passlog_' + mediaId + '_' + thisKey + '_' + bitstring
# Pass Commands
# pass_one_command = ffmpeg + ' -y -i ' + localInputFile + ' -c:v libx264 -strict -2 -b:v ' + bitstring + 'k -maxrate ' + bitstring + 'k -bufsize ' + bufs + 'k -vf scale=-2:' + thisKey + ' -an -pass 1 -passlogfile ' + myPassLogFile + ' -f mp4 ' + localTempPath
# pass_two_command = ffmpeg + ' -y -i ' + localInputFile + ' -c:v libx264 -strict -2 -b:v ' + bitstring + 'k -maxrate ' + bitstring + 'k -bufsize ' + bufs + 'k -vf scale=-2:' + thisKey + ' -c:a aac -b:a 128k -pass 2 -passlogfile ' + myPassLogFile + ' -movflags +faststart -f mp4 ' + localOutputPath
pass_one_command = ffmpeg + ' -y -i "' + localInputFile + '" -c:v libx264 -strict -2 -b:v ' + bitstring + 'k -maxrate ' + bitstring + 'k -bufsize ' + bufs + 'k -vf scale=-2:' + thisKey + ' -an -pass 1 -passlogfile ' + myPassLogFile + ' -f mp4 /dev/null'
pass_two_command = ffmpeg + ' -y -i "' + localInputFile + '" -c:v libx264 -strict -2 -b:v ' + bitstring + 'k -maxrate ' + bitstring + 'k -bufsize ' + bufs + 'k -vf scale=-2:' + thisKey + ' -c:a aac -b:a 128k -pass 2 -passlogfile ' + myPassLogFile + ' -movflags +faststart -f mp4 ' + localOutputPath
# aws s3 cp - s3: // my - amazing - bucket / geoip_v4_data.csv.gz
# ffmpeg - re - i in.ts - f hls - method PUT http: // example.com / live / out.m3u8
# Pass one
logger.info("Pass One " + pass_one_command)
os.system(pass_one_command)
# Pass two
logger.info("Pass two " + pass_two_command)
os.system(pass_two_command)
# delete temp
os.system('rm -f ' + localTempPath)
# delete log
os.system('rm -f ' + myPassLogFile)
# delete mbtree
os.system('rm -f ' + myPassLogFile + '-0.log.mbtree')
logger.info("B -> DONE PROCESSING = " + mediaId + '_' + thisKey + '_' + bitstring)
# upload file localOutputPath
key_create = 'media/' + fileType + '/' + mediaId + '/' + final_file
logger.info("UPLOADING localOutputPath = " + localOutputPath + ' the_bucket = ' + the_bucket + ' key_create = ' + key_create)
s3.upload_file(localOutputPath, the_bucket, key_create)
# remove file
os.system('rm -f ' + localOutputPath)
# encode audio
audioCommand = ffmpeg + ' -y -i "' + localInputFile + '" -f mp3 -ab 192000 -vn ' + audioPath
logger.info("Audio extraction " + audioCommand)
try:
os.system(audioCommand)
key_create = 'media/' + fileType + '/' + mediaId + '/audio_file.mp3'
logger.info("UPLOADING audioPath = " + audioPath + ' the_bucket = ' + the_bucket + ' key_create = ' + key_create)
s3.upload_file(audioPath, the_bucket, key_create)
logger.info("Audio extraction SUCCESS " + audioCommand)
except:
logger.info("Audio extraction ERROR" + audioCommand)
# upload audio file localOutputPath
# ++++++++++++++++++++++++++++++++++++++++ KRPANOTOOLS ++++++++++++++++++++++++++++++++++++++++++
# Upload to s3.
# upload_files(local_path, the_bucket, mediaId, fileType)
# key_create = 'media/' + fileType + '/' + mediaId + '/' + mediaId + '.mp4'
# logger.info("UPLOADING localInputFile = " + localInputFile + ' the_bucket = ' + the_bucket + ' key_create = ' + key_create)
# s3.upload_file(localInputFile, the_bucket, key_create)
logger.info("OK WE'RE DONE!!!")
|