[SOLVED] Saving Captured Video!

Hey Everyone! Felt like I should give back to this community and seeing how there is little to no support on how to actually save a video, here is a successful working sample… Enjoy! :slight_smile: (also attached)

local function copyVideoFile(videoPath,dstName,dstPath) local rfilePath=videoPath local wfilePath=system.pathForFile(dstName,dstPath) local rfh=io.open(rfilePath,"rb") local wfh=io.open(wfilePath,"wb") if not(wfh) then return false else local data=rfh:read("\*a") if not(data) then return false else if not(wfh:write(data)) then return false end end end rfh:close() wfh:close() return true end local function onVideoComplete(event) if (event.completed) then local videoFileExtension=".mov" if (system.getInfo("platformName")=="Android") then videoFileExtension=".mp4" end local videoFilePath=string.sub(event.url,8,-1) local savedVideoFileName="video"..videoFileExtension local savedVideoDirectory=system.TemporaryDirectory if (copyVideoFile(videoFilePath,savedVideoFileName,savedVideoDirectory)) then --your video is now saved under (savedVideoDirectory) directory --and the filename of the video is (savedVideoFileName) --do whatever you need to do :) local function mediaPlayListener(event) print("video ended") end media.playVideo(savedVideoFileName,savedVideoDirectory,true,mediaPlayListener) end end end media.captureVideo({listener=onVideoComplete,preferredQuality="high",preferredMaxDuration=20})

You are a life saver! I haven’t tested it yet but I thought I’d commend you for your work. Can’t wait to test it.

Thank you very much,

Aidan Wolf

Np buddy, I’m glad I can contribute to this community.

You are a life saver! I haven’t tested it yet but I thought I’d commend you for your work. Can’t wait to test it.

Thank you very much,

Aidan Wolf

Np buddy, I’m glad I can contribute to this community.

Which deice does this work for? iPhone? And I see you use enterprise. Will this work on Pro?

Thanks!!

Warren

should work for both and yes it works for Pro.

I just put your code in a test app where I recorded my own video and then called your code to copy it. And it works!! I did this on my Samsung Galaxy S4 and will test tonight on an iPhone 5S. But this is super! I could not believe how big the video file got in just a few seconds though. I even tried setting it to low quality and it still got big. Any suggestions to keep the size down? Or is that just how it is? I am uploading the video to my server when it is done.

Thanks again!

Warren

Which deice does this work for? iPhone? And I see you use enterprise. Will this work on Pro?

Thanks!!

Warren

should work for both and yes it works for Pro.

I just put your code in a test app where I recorded my own video and then called your code to copy it. And it works!! I did this on my Samsung Galaxy S4 and will test tonight on an iPhone 5S. But this is super! I could not believe how big the video file got in just a few seconds though. I even tried setting it to low quality and it still got big. Any suggestions to keep the size down? Or is that just how it is? I am uploading the video to my server when it is done.

Thanks again!

Warren

Eja - this is fantastic!!! From this I was easily able to upload a captured video.  Had been going crazy trying to do it for days. Thanks so much!! Well done.

How big was your file size? If I set the device to the smallest resolution setting I can do this but since I cannot control this with the software and hard to get someone to change it manually then my file size is so big.

Obviously it varies by device but I’m still using the high-res setting. I’m limiting to 20 seconds but even then the file sizes are large. Still, that’s to be expected with video. It seems to work fine using wifi and a dedicated server. I’ll post the results after some more testing.

Eja - this is fantastic!!! From this I was easily able to upload a captured video.  Had been going crazy trying to do it for days. Thanks so much!! Well done.

How big was your file size? If I set the device to the smallest resolution setting I can do this but since I cannot control this with the software and hard to get someone to change it manually then my file size is so big.

Obviously it varies by device but I’m still using the high-res setting. I’m limiting to 20 seconds but even then the file sizes are large. Still, that’s to be expected with video. It seems to work fine using wifi and a dedicated server. I’ll post the results after some more testing.

I’m wondering what use a video capturing app has if you can’t upload them to youtube, or save them to Camera Roll? I’m not trying to be facetious; I’m just wondering…thanks!

Just depends on what someone needs it for. For a client of mine they want video of different construction sites instead of just photos to see the status of the work.

thanks for the answer, Warren…so how is it different using your app than using the built-in camera app?