Hi
I was taking videos from raspicam.
It was working.
But whenever i went to take another video the old video would be overwritten.
I wanted to know how to save videos with different names each time .
For eg. "video1.mp4", "video2.mp4", "video3.mp4"
It would be really helpful if some one shares some Python knowledge .
Thanks.
-
- Raspberry Pi Engineer & Forum Moderator
- Posts: 10312
- Joined: Wed Dec 04, 2013 11:27 am
- Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
Re: saving videos taken with raspicam with names in incremental order
Duplicate of viewtopic.php?f=63&t=205972&p=1276052
You're the one calling "camera.start_recording('my_video.h264')" or similar (NB not an mp4 file, just the raw elementary stream), so you need to do something to form a string that fulfils your criteria.
You're the one calling "camera.start_recording('my_video.h264')" or similar (NB not an mp4 file, just the raw elementary stream), so you need to do something to form a string that fulfils your criteria.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
Re: saving videos taken with raspicam with names in incremental order
Hi,
I removed the duplicate post.
Till now I have achieved to do this.
i used avconv instead of mencoder to encode the h264 raw video into mp4 format.
I wanted something like %04d to increment on the next run of the script and not overwrite the old file.
How to do this. Please help . Thanks.
I removed the duplicate post.
Till now I have achieved to do this.
Code: Select all
#!/usr/bin/python
import time
import os
import sys
import re
import datetime
import subprocess
#from subprocess import call
#your_command = "raspistill -o videostaken/timelapse%04d.jpg -t 100000 -tl 5000 &"
inputimages = "timelapse%04d.jpg"
counter = 1
outputvideo = "myvideo.mp4"
def taketimelapsevideo():
subprocess.call(["raspistill", "-o", "timelapsetaken/"+inputimages, "-t", "10000", "-tl", "2000"])
subprocess.call(["avconv", "-r", "10", "-i", "timelapsetaken/"+inputimages, "-r", "10", "-vcodec", "libx264", "-vf", "scale=1280:720", "timelapsetaken/"+outputvideo])
if __name__ == '__main__':
taketimelapsevideo()
I wanted something like %04d to increment on the next run of the script and not overwrite the old file.
How to do this. Please help . Thanks.
Re: saving videos taken with raspicam with names in incremental order
try this...
Code: Select all
#!/usr/bin/python
import time
import os
import sys
import re
import datetime
import subprocess
#from subprocess import call
#your_command = "raspistill -o videostaken/timelapse%04d.jpg -t 100000 -tl 5000 &"
inputimages = "timelapse%04d.jpg"
counter = 0
#write counter file if first time
if os.path.exists('last.txt') == False:
file = open("last.txt", "w")
file.write(str(counter))
file.close()
#read last counter file stored
file = open("last.txt", "r")
counter = int(file.read())
file.close()
def taketimelapsevideo(counter):
subprocess.call(["raspistill", "-o", "timelapsetaken/"+inputimages, "-t", "10000", "-tl", "2000"])
counter +=1
# write counter file
file = open("last.txt", "w")
file.write(str(counter))
file.close()
outputvideo = "myvideo" + str(counter) + ".mp4"
subprocess.call(["avconv", "-r", "10", "-i", "timelapsetaken/"+inputimages, "-r", "10", "-vcodec", "libx264", "-vf", "scale=1280:720", "timelapsetaken/"+outputvideo])
if __name__ == '__main__':
taketimelapsevideo(counter)
Re: saving videos taken with raspicam with names in incremental order
Hi friend,
I get an error when i try to run the code:
I am using python 2.7.9.
Thanks
I get an error when i try to run the code:
Code: Select all
TypeError at /taketimelapsevideo
taketimelapsevideo() takes exactly 1 argument (0 given)
I am using python 2.7.9.
Thanks
Re: saving videos taken with raspicam with names in incremental order
Hi buddy, I have solved the error.
I had to put counter in taketimelapsevideo() function in my views.py.
And defined it globally.
I had to put counter in taketimelapsevideo() function in my views.py.
And defined it globally.
Last edited by Guneshs on Wed Feb 21, 2018 6:24 pm, edited 1 time in total.
Re: saving videos taken with raspicam with names in incremental order
Hi,
It didnt worked .
i get this warning
Since this is meant to be an automated script , I cant put the "y" to overwrite everytime.
Its not populating the counter on d second run.
It didnt worked .
i get this warning
Code: Select all
File 'timelapsetaken/myvideo1.mp4' already exists. Overwrite ? [y/N] Not overwriting - exiting
Its not populating the counter on d second run.
Re: saving videos taken with raspicam with names in incremental order
I don't understand that. Try deleting last.txt and try this original code again.Guneshs wrote: ↑Wed Feb 21, 2018 6:04 pmHi friend,
I get an error when i try to run the code:
Code: Select all
TypeError at /taketimelapsevideo taketimelapsevideo() takes exactly 1 argument (0 given)
I am using python 2.7.9.
Thanks
Re: saving videos taken with raspicam with names in incremental order
I solved that error
Re: saving videos taken with raspicam with names in incremental order
There wasn't that error when l ran it, so it's confusing. It sounds like it's not reading counter and/or not incrementing it.
Try deleting last.txt and changing the line counter =O to counter =1
Last edited by gordon77 on Wed Feb 21, 2018 7:41 pm, edited 1 time in total.
Re: saving videos taken with raspicam with names in incremental order
ohh.... I had added that code to my another script.
SO it gave me error .
SO it gave me error .