Converting a ~4.4MB quicktime (.MOV) video to .mp4 locally works fine, but on heroku it consumes over 1GB of memory and crashes the server.
Steps to reproduce
Take this video, place it in the root of a new or existing rails app.
Add
gem 'streamio-ffmpeg', '~> 3.0', '>= 3.0.2'to your gemfile and bundle, push to heroku, bundle on heroku.Run
heroku run rails cto jump into the rails console and try to convert the movie:
require 'streamio-ffmpeg'
# Read video file
movie = FFMPEG::Movie.new("IMG_1459.MOV")
# Transcode video and save as an mp4
movie.transcode("IMG_1459.mp4")
The last line runs for a while then crashes.
Error logs
Converting the ~4.4MB video appears to consume over 1GB of memory (!!)
2022-03-05T13:00:24.678737+00:00 heroku[web.1]: Process running mem=1076M(210.3%)
2022-03-05T13:00:24.689256+00:00 heroku[web.1]: Error R15 (Memory quota vastly exceeded)
2022-03-05T13:00:24.691853+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-03-05T13:00:24.810891+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/posts" host=secure-inlet-07449.herokuapp.com request_id=7cd160ea-b332-4965-ae3f-563696dd054b fwd="1.145.252.113" dyno=web.1 connect=0ms service=29610ms status=503 bytes=0 protocol=https
2022-03-05T13:00:25.025812+00:00 heroku[web.1]: Process exited with status 137
2022-03-05T13:00:25.121873+00:00 heroku[web.1]: State changed from up to crashed
The logs are from similar code in an actual app.
Update
I think I seriously underestimated how much RAM it would consume. (I had assumed I had a memory leak or some unclosed connection somehow triggering a loop or similar). But it may be true that this is simply an incredibly memory-intensive task, and therefore is a bad idea to try to run in the app itself, and should be instead offloaded to an external processes (e.g. EC2's or AWS Lambdas etc).