I'm developing a project that it's essentially a video uploader and I want to know if is there any way to get the resolution of the uploaded video using Xuggler libraries in Java.
Asked
Active
Viewed 2,800 times
1 Answers
8
In the class IStreamCoder
there are getHeight
and getWidth
methods.
So you should just use these methods, this sample should show you how to do it.
I extracted you what should be important.
// Create a Xuggler container object
IContainer container = IContainer.make();
// Open up the container
if (container.open("/path/to/video.avi", IContainer.Type.READ, null) < 0)
throw new IllegalArgumentException("could not open file: " + filename);
// query how many streams the call to open found
int numStreams = container.getNumStreams();
// and iterate through the streams to find the first video stream
int videoStreamId = -1;
IStreamCoder videoCoder = null;
for (int i = 0; i < numStreams; i++) {
// Find the stream object
IStream stream = container.getStream(i);
// Get the pre-configured decoder that can decode this stream;
IStreamCoder coder = stream.getStreamCoder();
if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
videoStreamId = i;
videoCoder = coder;
break;
}
}
if (videoStreamId == -1)
throw new RuntimeException("could not find video stream in container: "
+filename);
/*
* Now we have found the video stream in this file.
* Let's open up our decoder so it can do work.
*/
if (videoCoder.open() < 0)
throw new RuntimeException("could not open video decoder for container: "
+ filename);
// here you have what you need
int height = videoCoder.getHeight();
int width = videoCoder.getWidth();

Alex
- 25,147
- 6
- 59
- 55