• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Rob 4 · Dec 18, 2010 at 05:16 PM · video

Incorporating videos / image sequences into free Unity games

Hi. Is there a way to bring videos or image sequences into games with the free version of Unity 3.1? Say someone enters a region or opens a certain door and I want to play a twenty second video clip and then return to the game.

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Brian-Kehrer · Dec 18, 2010 at 05:29 PM

20 Seconds might be a bit long for this technique, but you can scroll the UVs on a material and or switch up the texture at regular intervals

sample code

float lastFrame; float timePerFrame = 0.03333f;//30 frames / second float spacePerSquare = 0.125f;//an 8 by 8 grid of images float rowVal; float colVal;

void Update() { float timer = Time.time; if(timer > lastFrame + timePerFrame){ lastFrame = timer; rowVal += spacePerSquare;

     if(rowVal > 1-spacePerSquare){
         rowVal = 0;
         colVal += spacePerSquare;

         if(colVal > 1-spacePerSquare){
             colVal = 0;
             ///renderer.material.mainTexture = next texture i want to assign in order;

         }
     }
     renderer.material.mainTextureOffset = Vector2 (rowVal, colVal);

 }//end of frame

}

I didn't test this, but you get the general idea. You create an image sequence laid out as a grid, and scroll through it. You obviously won't be able to do large videos that way, for that you need unity pro.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rob 4 · Dec 18, 2010 at 06:32 PM 0
Share

Hmmm . . . may not be able to do what I was hoping in the free version since what I really want to be able to do is have certain triggers in the game allow me to play a video clip ranging from seconds up to a $$anonymous$$ute or two that I'd create in other programs and bring in as long image sequences / swfs/ or flvs or quicktime movies. Am I correct in assu$$anonymous$$g I can bring in lengthy (1 $$anonymous$$ute) audio files that get triggered by certain game events like opening a door?

avatar image Brian-Kehrer · Dec 18, 2010 at 06:38 PM 0
Share

Yes, audio files are no problem.

In pro, all video is compressed into OGG video - so you need to import videos in compressible formats. I'm not sure about flvs or flash files, but its generally a bad idea to double compress the video anyway

avatar image Rob 4 · Dec 18, 2010 at 06:49 PM 0
Share

Thanks $$anonymous$$. As a workaround for my video problem, if I create an animated, lip synched character in my 3d program (talking for 1 $$anonymous$$ute, moving hands and body as explains stuff), could I bring this in as a GameObject via FBX export and then simply add the audio file?

avatar image uhahaha · Dec 19, 2010 at 01:10 AM 0
Share

FBX+Audio could do it. You need to check syncing audio & anim in 3d modeling proggie before exporting to fbx. In Unity you need a triggering script to play the animation & audio.

avatar image yoyo · Jan 01, 2011 at 05:55 PM 0
Share

The image sequence technique does work. I've used ffmpeg to rip videos into jpegs + audio stream, then the WWW interface to read frames from the hard drive using a file:// URL (this was about twice as fast as using the resource loader). The biggest video I've done this way was about 2-1/2 $$anonymous$$utes, at 624x352, playing back at 15 fps. I get 30 fps with smaller videos. If you're interested let me know and I could clean up my stuff and post to the wiki.

avatar image
0

Answer by poppysoc · May 08, 2012 at 02:40 AM

yoyo.. count me as one who would like to see your stuff posted to the wiki.. im still not sure if i want to invest into pro yet. been a torque user for over 6 years and just now considering they are going nowhere slowly. Time for a change!! However, one of my primary ventures with torque included the video launches upon triggers.. thanks

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by varunpalekar · Nov 30, 2012 at 09:59 PM

Use any c# library which can give access to the webcam like 'opencv sharp'. This will help you and then get the image data in Color32 format and render for each as given above.

for e.g;

  1. Read the camera capture by Opencv sharp by CvCapture

  2. then Read frame by frame Image and Save it in IplImage.

  3. then Convert IplImage.imageData as it was in IntPtr by marshal function by MarshaCopy(IntPtr , 0 , 3*Imagewidth*imageheight) to byte array.

  4. now convert the byte array into color32 array, the first 3 byte is responsible for single pixel so copy like this

byte[] data contains the data of IplImage converted from Intptr

byte[] data = new byte[3*imagewidth**imageheight]; IntPtr p = img.ImageData ; //img is the perframe IplImage Marshal.Copy(p , data , 0 , 3* imagewidth**imageheight);

Color32[] color = new Color32[Imagewidth***Imageheight]; int temp = 0; for(int i=0; i < imagewidth*imageheight ;i++) { color[i] = new Color(data[temp] , data[temp+1] , data[temp+2] , 0) //last zero for alpha factor of color32 temp+=3;

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How do I play a full screen video? 4 Answers

Animated GIF and Audio Instead of Video? 3 Answers

Import Video Codec H.264 MP4 from Premiere 6 Answers

Fraps is not recording Unity builds at certain resolutions 1 Answer

Ustream Support 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges