Hi,
I’ve done this with AWS lambda and API Gateway, it was for me easier than a plug-in, especially in terms of reliability.
If you’re interested you can reach out to me at: louis@hellooo.io
import subprocess
import os
def lambda_handler(event, context):
try:
# Get the input file path and format from the event
input_file = event['input_file']
output_format = event['output_format']
# Ensure that the input file exists
if not os.path.exists(input_file):
raise ValueError(f"Input file {input_file} does not exist.")
# Define the output file path and format based on the input format
if output_format == 'mp3':
output_file = os.path.splitext(input_file)[0] + '.mp3'
elif output_format == 'amr':
output_file = os.path.splitext(input_file)[0] + '.amr'
else:
raise ValueError("Output format must be 'mp3' or 'amr'.")
# Run ffmpeg command to perform the conversion
subprocess.run(['ffmpeg', '-i', input_file, output_file])
# Check if the output file was created successfully
if os.path.exists(output_file):
return {'converted_file': output_file}
else:
return {'converted_file': None}
except Exception as e:
# If any error occurs during the conversion process, return an empty value for the converted file
print(f"Error occurred: {str(e)}")
return {'converted_file': None}
This is something interesting in the replies that we can do it multiple ways, which one is better, using a LAMBDA function with AWS or using a 3rd party platform like CloudConvert APIs?
If CloudConvert supports the conversion you need (in @aj11 's case only 1 of the 2) then that is the quickest way to get conversions working without code.
Thanks, but i am more concerns about the cost, as most of the time its the cost. i want suggest my client lesser cost path, if i ever going to advise one.
And bro, we can use lambda in many way, what is the over all cost of calling a single lambda function.
CloudConvert has worked well. We are only converting 50 or so files a month, so the cost is negligible. If we were doing higher volumes, a lambda would make sense.