0

I'm using Unity's new (as of ~5.6.x) Video Player component to programmatically load a video file and play it. But I'd like to be able to detect the dimensions of the source video so that I can resize the render texture target as well as a GameObject containing a control bar for the video.

Is there any way to access these properties?

Currently, I can see it's possible to get the number of frames, etc, which makes me thing I should be able to get the video's dimensions as well, but nothing I can see seems to work.

Programmer
  • 121,791
  • 22
  • 236
  • 328
Vanguard3000
  • 223
  • 1
  • 6
  • 15
  • maybe you can use ffmpeg library https://stackoverflow.com/questions/6758042/how-to-get-video-dimensions-using-ffmpeg – Serdar Jul 24 '17 at 21:50

1 Answers1

2

You can get the video dimension such as the width and height from the VideoPlayer. This can be done by retrieving the VideoClip from the VideoPlayer. Those values can then be accessed from the VideoClip.

Get VideoPlayer

VideoPlayer vplayer = GetComponent<VideoPlayer>();

Get VideoPlayer clip from the VideoPlayer

VideoClip clip = vplayer.clip;

Get VideoPlayer dimension width/height

float videoWidth = clip.width;
float videoHeight = clip.height;

Other important variables you may be interested in:

double videoLength = clip.length;
float frameCount = clip.frameCount;
double frameRate = clip.frameRate;

If you need help playing video, you can check this post.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • My apologies; I typed my question at the end of the day and is woefully unclear. I've used that method before with no problem, but as I am downloading the video at runtime I have to use a URL as its source rather than a clip object. As such, "vplayer.clip" per your notation would be null. Your answer is correct per my original question. You're clearly an SO vet so I'll put this to you: Should I mark your question as correct and create a new question that's more clear; or should I edit my question, rendering your answer inaccurate given the updated data? – Vanguard3000 Jul 25 '17 at 15:18
  • 1
    I really like this answer and think it should dedicated to the offline video playing since it will be useful to many people. You can create a new answer dedicated to url video playing and I will answer it. I plan to be away within 30 minutes and will return in hours. If you can put the question within 30 minutes I will attempt to answer it. – Programmer Jul 25 '17 at 15:24