openframeworks-视频-中文

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

openFrameworks•VideoofVideoPlayeropenFrameworksallowsyoutoeasilydisplayvideosfromfileorgrabavideostreamfromawebcam.ForplayingvideosfromfileyouuseofVideoPlayertograbvideofromyourwebcamyouuseofVideoGrabber.TheofVideoPlayerclasslooksfollowsthesameAPIasofSoundPlayerwhichmakesitreallyeasytoworkwithvideoandsound.PlayingavideoclasstestApp:publicofBaseApp{public:ofVideoPlayermy_video;}ToplaybackavideoyoucreateaofVideoPlayermemberandcallloadMovietoloadamoviefromdisk.Callplaytostartplayingthemovie.IntestApp::updateyouneedtoupdatetheplayheadforthevideoplayeraswellbycallingupdateonyourofVideoPlayerobject.voidtestApp::setup(){my_video.loadMovie(fingers.mov);my_video.play();}voidtestApp::draw(){my_video.draw(10,10);}testApp.htestApp.cppPlayingavideoclasstestApp:publicofBaseApp{public:ofVideoPlayermy_video;}ToplaybackavideoyoucreateaofVideoPlayermemberandcallloadMovietoloadamoviefromdisk.Callplaytostartplayingthemovie.IntestApp::updateyouneedtoupdatetheplayheadforthevideoplayeraswellbycallingupdateonyourofVideoPlayerobject.voidtestApp::setup(){my_video.loadMovie(fingers.mov);my_video.play();}voidtestApp::draw(){my_video.draw(10,10);}testApp.htestApp.cppScrubbingthroughvideoclasstestApp:publicofBaseApp{public:ofVideoPlayermy_video;}UsingnextFrameandpreviousFrameyoucanscrubthroughapausedmovie.testApp.htestApp.cppvoidtestApp::setup(){ofBackground(33);my_video.loadMovie(fingers.mov);my_video.play();}voidtestApp::update(){my_video.update();}voidtestApp::draw(){my_video.draw(0,0);}voidtestApp::keyPressed(intkey){if(key=='p'){my_video.setPaused(true);}elseif(key=='a'){my_video.nextFrame();}elseif(key=='b'){my_video.previousFrame();}}GettingpixelsCheckiftheplayerhasanewframeusingisFrameNew,thenusegetPixelstoretrievethenewpixels.testApp.htestApp.cppvoidtestApp::setup(){ofBackground(33);my_video.loadMovie(fingers.mov);my_video.play();//tellourimagehowmany/whatpixelsitwillstore.my_video_frame.allocate(my_video.getWidth(),my_video.getHeight(),OF_IMAGE_COLOR);}voidtestApp::update(){my_video.update();if(my_video.isFrameNew()){//copythepixelsfromthenewvideoframe.my_video_frame.setFromPixels(my_video.getPixels(),my_video.getWidth(),my_video.getHeight(),OF_IMAGE_COLOR);}}classtestApp:publicofBaseApp{public:ofVideoPlayermy_video;ofImagemy_video_frame;}ControllingplaybackYoucanchangetheplayheadpositionusingsetPosition(float).Avalueof0.0meansgotothestart,1.0gototheend.ChangethespeedusingsetSpeed(float).Aspeedof0.0isthesameaspausingthevideo,valuesabove1.0arefasterthenthedefaultplaybackspeed.OfcourseyoucanusefirstFrame()tojumptothefirstframe.WithsetPaused(bool)youcanpauseorcontinueplayback.WhenyouwanttojumptoaspecificframeusesetFrame(int).CheckthetotalnumberofframeswithgetTotalNumFrames()ofVideoPlayerboolloadMovie(stringfileName)voidclose()voidplay()voidupdate()voidstop()boolisFrameNew()unsignedchar*getPixels()ofPixelsRefgetPixelsRef()floatgetPosition()floatgetSpeed()floatgetDuration()boolgetIsMovieDone()ofVideoPlayervoidsetPosition()voidsetVolume(intvolume)voidsetLoopState(ofLoopTypestate)intgetLoopState()voidsetSpeed(floatspeed)voidsetFrame(intframe)voidsetUseTexture(booluse)ofTexture&getTextureReference()voiddraw(floatx,floaty,floatw,floath)voiddraw(floatx,floaty)voiddraw(constofPoint&p)voiddraw(constofRectangle&r)ofVideoPlayervoidsetAnchorPercent(floatxPct,floatyPct)voidsetAnchorPoint(floatx,floaty)voidresetAnchor()voidsetPaused(boolpaused)intgetCurrentFrame()intgetTotalNumFrames()voidfirstFrame()voidnextFrame()voidpreviousFrame()floatgetWidth()floatgetHeight()boolisPaused()boolisPlaying()ofVideoGrabberTheofVideoGrabbergrabsvideofromawebcam.TheclassissimilartoofVideoPlayer.Maindifferenceisthatyouneedtotellwhatwebcam(device)youwanttouseassource.ofVideoGrabbervoidtestApp::setup(){my_grabber.initGrabber(320,240);my_grabber.listDevices();}Getalistofavailabledevices.MakesureyoufirstinitializethegrabberusinginitGrabber.testApp.cpptestApp.hclasstestApp:publicofBaseApp{public:ofVideoGrabbermy_grabber;}ofVideoGrabberDrawvideotoscreen!testApp.cppvoidtestApp::setup(){my_grabber.initGrabber(320,240);my_grabber.setDeviceID(1);}voidtestApp::update(){my_grabber.update();}voidtestApp::draw(){my_grabber.draw(0,0);}ofVideoGrabberWhenyouwanttograbpixelsfromyourwebcamyoucanusethefunctiongetPixels.ThoughyouneedtocheckifwegotanewframeusingisFrameNewbecauseyoudon’twanttogetthesamepixelswealreadyhave.voidtestApp::update(){my_grabber.update();if(my_grabber.isFrameNew()){unsignedchar*pix=my_grabber.getPixels();}}ofVideoGrabbervoidlistDevices()boolisFrameNew()voidupdate()voidclose()voidinitGrabber(intw,inth)boolinitGrabber(intw,inth,booltexture)voidvideoSettings()unsignedchar*getPixels()ofPixelsRef&getPixelsRef()ofTexture&getTextureReference()voidsetVerbose(boolverbose)voidsetDeviceID(intdevice)ofVideoGrabbervoidsetUseTexture(booluse)voiddraw(floatx,floaty,floatw,floath)voiddraw(floatx,floaty)voiddraw(ofPoint&p)voiddraw(ofRectangle&r)voidsetAnchorPercent(floatxPct,floatyPct)voidsetAnchorPoint(floatx,floaty)floatgetWidth()floatgetHeight()ofVideoGrabberofLoopType-used

1 / 17
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功