Auto convert HEIF to JPEG on direct upload with Active Storage - ruby-on-rails

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.

Related

Can you make Video variants, transformations of video, with ActiveStorage?

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.

HEIC/HEIF changed to jpeg without metadata at upload

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.

How to validate images on iOS have not been tampered/shopped after capturing them

I am trying to create an app for iPhone that will let users capture video/pics and captures their geo info and uploads them to a database online.
I am primarily trying to certify the images weren't manipulated/shopped and are same copy as initial shot.
Is there any unique image data on iOS that I can use to validate images?
Hard requirement: Your app needs to capture, because any other app could apply changes before saving to iOS image library.
Save image to the local storage of your app, not to the iOS image library.
Or, if you do want to use the iOS image library, you need to keep track of all images that were captured in your app. Create some hash (MD5, SHA, ... whatever) of each image after it's been freshly captured. Store the list of hashes on disk (in NSUserDefault, in a file, or in a CoreData database, whatever you wish). When a user selects an image, generate its has and check if you can find it in the list. In case you allow upload only once, delete the hash from the list after upload.
You could also look at comparing creation date and modification date of an image file that comes from the iOS image library. Both timestamps must be the same.

Audio format to choose for Big audio files

Which audio file format is best to use for large audio files? I have many large audio files to be used in my app but their current mp3 size is of hundred of MB's
If you want to save more storage on audio files, file format may not change too much on the file size, reducing the bit rate(for example 320Kbps to 128Kbps) can reduce the file size significantly.
:how to do it using microsofts audio compression manager?(practically its not well documented in m.s.d.n.
Windows provide codecs that compress specifically audio files. The audio files tipically are PCM format (WAVE_FORMAT_PCM) and get played by using the simplest directsound method (check msdn it`s at hand and it works)
To play a file using directsound, thus PCM format you first create a directsound object, create a directsoundbuffer, and then pump the PCM data directly to the buffer using a keep-fill-buffer algorithm.
If you wish to use codecs, u try and write a procedure that opens a stream file and passes it through a acm driver object, thus (de)compressing it.
The driver for ACM (audio compression manager) finds a codecs that suits the input source and decompresses it yet again to WAVE_FORMAT_PCM for your app be able to play it.

UYVY format to be converted

I' m framing video images from video stream and I took one frame of the video streaming from a video Port (as a first step of my application) so I could transmit the raw UYVY video data. After running, these data are stored into a .dat file
Meanwhile, before transmitting the raw data, I am looking for a way to display the decoded information stored in the .dat file. In other words, Is there a software that would convert the UYVY raw data into a picture?
Thank you for your assistance
Each of your .dat file is an UYVY 422 image that can be display.
Without any details about your platform and your running context, I would recommend the use of the FFMPEG suite.
Using ffplay you could display your image with
ffplay -video_size WIDTHxHEIGHT -pixel_format uyvy422 filename.dat
As you saw the only things you need to know is the image size!

Resources