I am trying to convert .ogv files to .mp4 using an ffmpeg layer on AWS Lambda.
I followed a tutorial from the people at Serverless Framework to convert .mp4's to GIF's and that worked out great. Using the same ffmpeg static build, ( ffmpeg-git-amd64-static.tar.xz ) I set out to convert .ogv files to .mp4 files.
So far I have had success with uploading videos to an S3 Bucket, getting a Lambda to retrieve that video, do something to the video using the ffmpeg binary, and copy a new file to S3.
The Problem:
The videos that are created, will not play.
data point 1: the resultant files from the function are far too small.
The input video file is 1.3MB and the output video is only 256.0KB
data point 2: moov atom not found.
After copying the resultant video from S3 to my local machine, I try to play using ffplay and I receive this error:
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd613093400] moov atom not found
frank.mp4: Invalid data found when processing input
As far as I have been able to tell, the moov atom is suppose to contain important metadata about .mp4 files.
Implementation:
I used the Serverless framework to set up the AWS infrastructure.
Here are a few different ffmpeg commands I have tried:
1st attempt:
// convert to mp4!
spawnSync(
"/opt/ffmpeg/ffmpeg",
[
"-i",
`/tmp/${record.s3.object.key}`,
"-vcodec",
"libx264",
"-acodec",
"aac",
`/tmp/${record.s3.object.key}.mp4`
],
{ stdio: "inherit" }
);
2nd attempt:
// convert to mp4!
spawnSync(
"/opt/ffmpeg/ffmpeg",
[
"-i",
`/tmp/${record.s3.object.key}`,
`/tmp/${record.s3.object.key}.mp4`
],
{ stdio: "inherit" }
);
3rd attempt:
I found this approach in a Stack Overflow question and the poster said that it worked for him.
// convert to mp4!
spawnSync(
"/opt/ffmpeg/ffmpeg",
[
'-i',
`/tmp/${record.s3.object.key}`,
'-codec:v',
'libx264',
'-profile:v',
'main',
'-preset',
'slow',
'-b:v',
'400k',
'-maxrate',
'400k',
'-bufsize',
'800k',
'-threads',
'0',
'-b:a',
'128k',
`/tmp/${record.s3.object.key}.mp4`
],
{ stdio: "inherit" }
);
Each one of these works swell on my local machine.
If the ffmpeg binary that I am using was not a popular one, ( I have seen it on multiple sites dealing in connection with transcoding on Lambda ), my guess would be that it is an issue with the layer... Perhaps.
Any insight would be greatly appreciated. Thank you.
.ogv. To your point I thought that perhaps line 6 from attempt 2 above should read/tmp/${record.s3.object.key}.ogv, but if my understanding is correct, this would result in something like "file_name.ogv.ogv". - incovenant