I have a Java servlet method that evaluates an uploaded file to determine its type and then that file is passed on to ffmpeg for processing. Tika is used to detect the type of file. Right now it seems that either Tika, or my implementation of it is only able to determine container rather than the stream within the container and that leads to a detection issue where the container might be an MP4 but the stream within is an AAC audio. In my Java code I have the following:
String fileType = tika.detect(uploadedFile);
String[] mediaAndType = fileType.split("/");
media = mediaAndType[0];
mediatype = mediaAndType[1];
I have an file with the extension of .m4a that Tika detects as "video/3gpp" and MediaInfo detects as:
Format : MPEG-4
Format profile : 3GPP Media Release 4
Codec ID : 3gp4 (isom/3gp4)
There is only one stream in the file:
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : LC
Codec ID : mp4a-40-2
If I can detect that the file has only an audio format stream in the container, then I can hand it off to ffmpeg for audio processing vs video processing (which throws an error when processing the file above).
I chose Tika originally because it is simple and fast and easy to implement so if there is a way to use Tika to get what I want, that would be best but I am open to other tools to determine the number and types of streams within the container. I tried using the MP4Parser in Tika but it didn't return anything useful.
So is there a better way/tool to detect the format of the stream within the container that is fairly lightweight?