I need to get video/audio file information like duration, width, and height after upload from RestController
.
It will depend on the particular video container (e.g. mp4) and also possibly the framework you are using, but you can use ffprobe, part of ffmpeg, to get the information.
There are several ffmpeg wrappers for Java - at the time of writing this is a popular one: https://github.com/bramp/ffmpeg-cli-wrapper
Getting media file information using this, from the example at the link above, looks like:
FFprobe ffprobe = new FFprobe("/path/to/ffprobe");
FFmpegProbeResult probeResult = ffprobe.probe("input.mp4");
FFmpegFormat format = probeResult.getFormat();
System.out.format("%nFile: '%s' ; Format: '%s' ; Duration: %.3fs",
format.filename,
format.format_long_name,
format.duration
);
FFmpegStream stream = probeResult.getStreams().get(0);
System.out.format("%nCodec: '%s' ; Width: %dpx ; Height: %dpx",
stream.codec_long_name,
stream.width,
stream.height
);