ActiveStorage seems to be mostly focused on images. While it does offer "preview" support to get a thumbnail from a video -- what about "variants"?
With images, maybe it's uploaded as a JPG, but I can use the variants feature to convert to a PNG, and/or resize it, whatever.
But what if I want to do something similar with videos? Let's say the video was uploaded as an mp4, but I want to transform it into webm, or vice versa, or downsample it, or whatever.
How would one do this if one wanted to use ActiveStorage to keep track of the original uploaded file?
I needed something to convert quicktime (mov) files into mp4.
This works locally, but uses way too much memory in production to be useful.
Still, it seems to work, so may help you it you have a lot of RAM to spare.
Example: for a ~4.4mb video, it uses >1GB RAM to transcode it!
# Transcoding quicktime to mp4
if post_params[:files][1].content_type == "video/quicktime"
# Transcode
require 'streamio-ffmpeg'
movie = FFMPEG::Movie.new(post_params[:files][1].tempfile.path)
# Write new movie
require 'tempfile'
tempfile = Tempfile.new(["", ".mp4"])
movie.transcode(tempfile.path)
# Update tempfile path in ActiveStorage
post_params[:files][1].tempfile = tempfile
# Update headers
post_params[:files][1].headers = post_params[:files][1].headers.sub("\nContent-Type: video/quicktime", "\nContent-Type: video/mp4")
end
So what I intend to do is offload these workloads to AWS lambdas, which could be triggered to run when an new file arrives in ActiveStorage.
I will update if I get it working successfully.
Related
If user uploads HEIF file, I would like to convert it to JPEG in Rails 6 application on Active Storage. This would be a system vide function. JPEG image cannot be a variant, because photo needs to be analyzed (I need the EXIF data from it).
Should the conversion be triggered during the analysis of the original file, or is it more appropriate place for this without slowing down the upload itself.
I have a small webapp that runs on a server intended for use in a setting without reliable internet access (i.e., the app can't depend on outside resources during production). The purpose of the app is simply to upload image files, read the metadata, and categorize them in the right location on the disk. Up until recently there was no problem with this process, then I noticed that some of the files did not have all of the metadata attached (specifically the creation date). Upon further inspection, it appears that these are files that were shot on my iPhone as HEIC/HEIF photos and uploaded directly to the webpage from the phone.
Due to the design of the webapp, the filename of the uploaded file is shown on the page. Every time an HEIC photo is uploaded it displays the filename as ending in .jpeg.
I've had a hard time finding good documentation on this, but it sounds like the default for the iPhone at this point is to convert HEIC files to jpeg if it looks like they are transferring to a location that may not be able to read them. I guess a website form falls into this category. It also appears that as part of this conversion some of the EXIF data disappears.
So, does anyone know a way to retain the EXIF data? My primary limitation here is that the upload needs to happen through the webapp and that multiple users will be using this. As a result, I can't simply have everyone change their iPhone settings to only shoot jpegs.
In case it matters, the webapp is running on node.js and expressjs.
I want to have my users be able to upload audio files.
I've done some research on this and found Paperclip. However, I've also read that Paperclip performs poorly if the file is over 4MB, and as you probably know most audio files are over 4MB.
So my question is, how can I have users upload audio files without using Paperclip? I plan on storing everything in Amazon S3.
I plan on users being able to stream this audio and download the files, if that makes any difference.
Is there a way to extract audio from a video file with Ruby? I'm looking to get audio from our sermon videos when posting them online.
There isn't anything built into Ruby, but you can use ffmpeg to strip the audio from the video. Check out the gem https://github.com/streamio/streamio-ffmpeg. This will also require you to have ffmpeg and any dependencies installed on your production machine. You may want to consider moving this into a background process (delayed_job) or putting a progressbar so the user doesn't wonder why it is just churning but not displaying results immediately. You can use something like polling or some type of notification to let the user know once the audio file is ready for streaming/downloading.
I've got videos ( FLV ) set to split once they reach a certain filesize/length due to storage constraints, but I can't find a simple way to concatenate these files on the fly to upload them.
Currently it's looking like I'll have to concatenate the files using something like ffmpeg into an intermediary file and then uploading that, however that is rather intensive on resources and it would be much simpler if I could just tweak data in the stream I'm sending to youtube so the first file never "ends" and the next file can just be read in ( modified as it's read so it doesn't break ), and then youtube would "solidify" it when it processes the video.
So the question remains, is there any way to do this, or is the FLV file format ( wowza / flash video ) a bane to my plans?
No, there's no way to do that. You need to concatenate them first, and you need to specify the length of the entire video at the start of the upload (i.e. you can't just stream video bytes without knowing in advance the total upload size).