Context
My application enables users to upload an .mp4 file to Google Cloud Storage through Google App Engine using the createUploadUrl() pattern. The upload works fine and I'm able to obtain the corresponding FileInfo object in the handler. I'm using the App Engine SDK 1.8.2 for Java.
The Challenge
I need to grab the "duration" property off of the .mp4 file and store it in my database but the FileInfo object doesn't provide access to this metadata. I have a few ideas on how I might go about doing this (which I've listed below) but none of them are very straightforward given that the project I'm working on has several legacy dependencies.
I'd love to hear any ideas or suggestions you have on how to tackle this (and ideally any success stories if you have!)
Ideas
- I know that there are scripts and utilities like ffmpeg and mdls (for mac) that can read metadata off of the file but my understanding is that these wouldn't be able to run in Google App Engine and I would need to kick off separate processes using something like Google Compute Engine.
- I could create a custom flash upload control that reads the duration logic when the user selects the file for upload and passes it in through standard form submission.
- I'm also aware that there's a Google Cloud Storage JSON API that's been in Beta stage now. I don't see any functionality that would allow me to read the "duration" property off of the .mp4 file but I may be missing something...
Code
HTML Form
<form name="myForm" id="myForm" action="<%=createUploadUrl("/upload, uploadOptions)%>" method="POST" enctype="multipart/form-data">
<input type="file" name="uploadFileControl" id="uploadFileControl" value="Select...">
<input type="submit" value="Submit">
</form>
Server Side Handler
DAO dao = new DAO();
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<FileInfo>> fileInfos = blobstoreService.getFileInfos(req);
List<FileInfo> uploadedFile = fileInfos.get("uploadFileControl");
if(uploadedFile != null) {
FileInfo file = uploadedFile.get(0);
String fileName = file.getFilename();
}