Unity does not have an API to directly capture a frame image of a video, so it's up to you to write a thumbnail.
Pictures and videos can be used in this way to generate thumbnails, the other, reproduced please indicate the source, thank you.
1 usingSystem.Collections;2 usingSystem.Collections.Generic;3 usingUnityengine;4 usingUnityengine.video;5 usingSystem.IO;6 7 8 Public classNewbehaviourscript:monobehaviour {9 Ten videoplayer VP; One texture2d videoframetexture; A rendertexture rendertexture; - voidStart () - { theVideoframetexture =NewTexture2d (2,2); -VP = getcomponent<videoplayer>(); -Vp.playonawake =false; -Vp.waitforfirstframe =true; + -Vp.sendframereadyevents =true; +Vp.frameready + =Onnewframe; A VP. Play (); at - - } - intFramesvalue=0;//get a picture of the first few frames of video - voidOnnewframe (Videoplayer source,Longframeidx) - { inframesvalue++; - if(framesvalue== -) { toRendertexture = Source.texture asrendertexture; + if(videoframetexture.width! = Rendertexture.width | | Videoframetexture.height! =rendertexture.height) { - videoframetexture.resize (Rendertexture.width, rendertexture.height); the } *Rendertexture.active =rendertexture; $Videoframetexture.readpixels (NewRect (0,0, Rendertexture.width, Rendertexture.height),0,0);Panax Notoginseng videoframetexture.apply (); -Rendertexture.active =NULL; theVp.frameready-=Onnewframe; +Vp.sendframereadyevents =false; A } the } + - voidondisable () $ { $ if(! File.exists (application.persistentdatapath+"/temp.jpg")) { -Scaletexture (Videoframetexture, -, -, (application.persistentdatapath+"/temp.jpg")); - } the } - //generate thumbnail imagesWuyi voidScaletexture (texture2d source,intTargetwidth,intTargetheight,stringSavepath) the { - Wutexture2d result =NewTexture2d (Targetwidth, Targetheight,textureformat.argb32,false); - About for(inti =0; i < result.height; ++i) $ { - for(intj =0; J < Result.width; ++j) - { -Color Newcolor = source. Getpixelbilinear ((float) J/(float) Result.width, (float) I/(float) result.height); A result. SetPixel (J, I, Newcolor); + } the } - result. Apply (); $ file.writeallbytes (Savepath, result. Encodetojpg ()); the } the the}
Unity obtains a frame of the video, generates a thumbnail image