maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Multimedia (https://talk.maemo.org/forumdisplay.php?f=32)
-   -   [Solved] [Maemo 5] Keeping record of last two minute Audio/video recording? (https://talk.maemo.org/showthread.php?t=82561)

nicholes 2012-02-24 13:26

[Solved] [Maemo 5] Keeping record of last two minute Audio/video recording?
 
Hi,
I want to use N900 as a third empire video rec. of a cricket match. to do this somehow N900 should keep video record of last two or three minute only .rest should be delete so thus whatever happens in the match recently (just two minute before) i can see reply of it. i hope i have present what i want in good words.(actually my English is not good)

video rec. SOLVED:- here is how to do this

you need rootsh and leafpad installed

open leafpad and paste the code

Thanks to skykooler and int_ua for their hard work

Code:

#!/usr/bin/env python
import gst
import time
import os

bin = gst.element_factory_make("camerabin")
bin.set_property("videoenc", gst.element_factory_make("dspmp4venc"))
bin.set_property("videomux", gst.element_factory_make("hantromp4mux"))
bin.set_property("audioenc", gst.element_factory_make("nokiaaacenc"))

while True:
    bin.set_state(gst.STATE_PLAYING)
    bin.set_property("filename", "current.mp4")
    bin.set_property("mode",1)
    #starts recording
    bin.emit("user-start")

    time.sleep(60)

    # stops recording
    bin.emit("user-stop")
    bin.set_state(gst.STATE_PAUSED)
    bin.set_state(gst.STATE_NULL)
    try:
        os.remove("twominutesold.mp4")
    except OSError:
        print "No two-minutes-old file exists yet."
    try:
        os.rename("oneminuteold.mp4", "twominutesold.mp4")
    except OSError:
        print "No one-minute-old file exists yet."
    os.rename("current.mp4", "oneminuteold.mp4")

Now save it as record.py

now open your camera shutter and close camera app.

go to xterminal and type sudo gainroot and go to directory where you saved record.py and type

Code:

chmod 755 record.py; ./record.py
the video is saved in home/user

int_ua 2012-02-24 13:58

Re: Keeping record of last two minute video recording?
 
That's an interesting question. As a workaround (but not solution) I can propose to record 1 minute intervals with sh script and drop all except last N of them. But, again, it's just the first thing that comes to my mind. Will look through gst sinks.

int_ua 2012-02-24 14:56

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Maybe leaky queue?..

nicholes 2012-02-24 15:35

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by int_ua (Post 1169213)
Maybe leaky queue?..

is there anything which a noob can understand?

skykooler 2012-02-24 15:45

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by nicholes (Post 1169224)
is there anything which a noob can understand?

The shell script idea seems pretty simple. Unfortunately I don't know enough of gstreamer to completely work it out. Here's my take (two scripts):

update.sh:
Code:

#!/bin/bash
rm twominutesold.avi
mv oneminuteold.avi twominutesold.avi
mv current.avi oneminuteold.avi
(crazy gstreamer stuff to record a minute of video to current.avi)

record.sh:
Code:

#!/bin/bash
watch -n 60 ./update.sh

Record.sh is what you run; every minute it runs update.sh, which deletes the oldest recording and starts a new one. Control-c stops and leaves you with between 2 and 3 minutes of the most recent video.

Anyone want to figure out the gstreamer command?

Spotfist 2012-02-24 15:48

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Would be a good idea for an app, could be used in cars too! keep recordings of any potential accident you may have...

int_ua 2012-02-24 15:53

Re: [Maemo 5] Keeping record of last two minute video recording?
 
The gstreamer command was somewhere on the forums. nicholes, what about pycam that I've seen in your earlier thread? Can it be limited to 1 minute? However, there was pure sh code which is much much simpler.

nicholes 2012-02-24 15:54

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by skykooler (Post 1169227)
The shell script idea seems pretty simple. Unfortunately I don't know enough of gstreamer to completely work it out. Here's my take (two scripts):

update.sh:
Code:

#!/bin/bash
rm twominutesold.avi
mv oneminuteold.avi twominutesold.avi
mv current.avi oneminuteold.avi
(crazy gstreamer stuff to record a minute of video to current.avi)

record.sh:
Code:

#!/bin/bash
watch -n 60 ./update.sh

Record.sh is what you run; every minute it runs update.sh, which deletes the oldest recording and starts a new one. Control-c stops and leaves you with between 2 and 3 minutes of the most recent video.

Anyone want to figure out the gstreamer command?


can this help somehow?

skykooler 2012-02-24 16:07

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by nicholes (Post 1169238)
can this help somehow?

Thanks! Here's a python script which should handle it by itself. To run:
Code:

chmod 755 record.py; ./record.py
record.py:
Code:

import gst
import time
import os

bin = gst.element_factory_make("camerabin")
bin.set_property("videoenc", gst.element_factory_make("dspmp4venc"))
bin.set_property("videomux", gst.element_factory_make("hantromp4mux"))
bin.set_property("audioenc", gst.element_factory_make("nokiaaacenc"))

while True:
    bin.set_state(gst.STATE_PLAYING)
    bin.set_property("filename", "current.mp4")
    bin.set_property("mode",1)
    #starts recording
    bin.emit("user-start")

    time.sleep(60)

    # stops recording
    bin.emit("user-stop")
    bin.set_state(gst.STATE_PAUSED)
    bin.set_state(gst.STATE_NULL)
    try:
        os.remove("twominutesold.mp4")
    except OSError:
        print "No two-minutes-old file exists yet."
    try:
        os.rename("oneminuteold.mp4", "twominutesold.mp4")
    except OSError:
        print "No one-minute-old file exists yet."
    os.rename("current.mp4", "oneminuteold.mp4")


int_ua 2012-02-24 16:23

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Great start :)
Just move STATE_PLAYING into while loop and fix prints, please :)

int_ua 2012-02-24 16:25

Re: [Maemo 5] Keeping record of last two minute video recording?
 
let's start garage project for this, I can't wait to post commits :)
Or some git*

int_ua 2012-02-24 16:33

Re: [Maemo 5] Keeping record of last two minute video recording?
 
But 3 seconds are lost on each video.

int_ua 2012-02-24 16:38

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Maybe let's talk on #maemo@freenode?

skykooler 2012-02-24 16:53

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by int_ua (Post 1169257)
Great start :)
Just move STATE_PLAYING into while loop and fix prints, please :)

I fixed that.

nicholes 2012-02-24 17:34

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by skykooler (Post 1169248)
Thanks! Here's a python script which should handle it by itself. To run:
Code:

chmod 755 record.py; ./record.py
record.py:
Code:

import gst
import time
import os

bin = gst.element_factory_make("camerabin")
bin.set_property("videoenc", gst.element_factory_make("dspmp4venc"))
bin.set_property("videomux", gst.element_factory_make("hantromp4mux"))
bin.set_property("audioenc", gst.element_factory_make("nokiaaacenc"))

while True:
    bin.set_state(gst.STATE_PLAYING)
    bin.set_property("filename", "current.mp4")
    bin.set_property("mode",1)
    #starts recording
    bin.emit("user-start")

    time.sleep(60)

    # stops recording
    bin.emit("user-stop")
    bin.set_state(gst.STATE_PAUSED)
    bin.set_state(gst.STATE_NULL)
    try:
        os.remove("twominutesold.mp4")
    except OSError:
        print "No two-minutes-old file exists yet."
    try:
        os.rename("oneminuteold.mp4", "twominutesold.mp4")
    except OSError:
        print "No one-minute-old file exists yet."
    os.rename("current.mp4", "oneminuteold.mp4")


is there anything which a noob can understand? i dont know what to do i just start xterminal and type

python

(after pressing enter)

should i paste your code (whole code) at once

or i should paste this only.....

Code:

import gst
import time
import os

bin = gst.element_factory_make("camerabin")
bin.set_property("videoenc", gst.element_factory_make("dspmp4venc"))
bin.set_property("videomux", gst.element_factory_make("hantromp4mux"))
bin.set_property("audioenc", gst.element_factory_make("nokiaaacenc"))

while True:
    bin.set_state(gst.STATE_PLAYING)
    bin.set_property("filename", "current.mp4")
    bin.set_property("mode",1)
    #starts recording
    bin.emit("user-start")

    time.sleep(60)

and then this.........

Code:


    # stops recording
    bin.emit("user-stop")
    bin.set_state(gst.STATE_PAUSED)
    bin.set_state(gst.STATE_NULL)
    try:
        os.remove("twominutesold.mp4")
    except OSError:
        print "No two-minutes-old file exists yet."
    try:
        os.rename("oneminuteold.mp4", "twominutesold.mp4")
    except OSError:
        print "No one-minute-old file exists yet."
    os.rename("current.mp4", "oneminuteold.mp4")

and what do you mean by saying this...


Code:

chmod 755 record.py; ./record.py
it says no such file or directory

skykooler 2012-02-24 17:48

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by nicholes (Post 1169305)
is there anything which a noob can understand? i dont know what to do i just start xterminal and type

python

(after pressing enter)

should i paste your code (whole code) at once

or i should paste this only.....

Code:

import gst
import time
import os

bin = gst.element_factory_make("camerabin")
bin.set_property("videoenc", gst.element_factory_make("dspmp4venc"))
bin.set_property("videomux", gst.element_factory_make("hantromp4mux"))
bin.set_property("audioenc", gst.element_factory_make("nokiaaacenc"))

while True:
    bin.set_state(gst.STATE_PLAYING)
    bin.set_property("filename", "current.mp4")
    bin.set_property("mode",1)
    #starts recording
    bin.emit("user-start")

    time.sleep(60)

and then this.........

Code:


    # stops recording
    bin.emit("user-stop")
    bin.set_state(gst.STATE_PAUSED)
    bin.set_state(gst.STATE_NULL)
    try:
        os.remove("twominutesold.mp4")
    except OSError:
        print "No two-minutes-old file exists yet."
    try:
        os.rename("oneminuteold.mp4", "twominutesold.mp4")
    except OSError:
        print "No one-minute-old file exists yet."
    os.rename("current.mp4", "oneminuteold.mp4")

and what do you mean by saying this...


Code:

chmod 755 record.py; ./record.py
it says no such file or directory

Copy the code I posted into a file called record.py. Then run:
Code:

chmod 755 record.py; ./record.py

nicholes 2012-02-24 18:07

Re: [Maemo 5] Keeping record of last two minute video recording?
 
2 Attachment(s)
Quote:

Originally Posted by skykooler (Post 1169312)
Copy the code I posted into a file called record.py. Then run:
Code:

chmod 755 record.py; ./record.py

i opened leafpad and paste your code and save it as record.py(in /home/user)

than i try to run it but first permission denied and import not found

so i sudo gainroot and than run it but still import not found

there are screen shot for you thanks in advance!

skykooler 2012-02-24 18:17

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Oops, add
Code:

#!/usr/bin/env python
to the beginning of that file.

nicholes 2012-02-24 18:29

Re: [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by skykooler (Post 1169327)
Oops, add
Code:

#!/usr/bin/env python
to the beginning of that file.

Finally it works!

Thanks to all of you guys and devlopers.

speacial Thanks to skykooler and int_ua

int_ua 2012-02-24 20:13

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
I just finished first attempt to get gst-launch working and queue works as expected with this code:
Code:

gst-launch v4l2src device=/dev/video0 ! queue leaky=upstream min-threshold-time=10000000000 ! autovideosink
(time in nanoseconds)
Now it would be great to try to use queue sink in the above python code instead of moving files :) That's all for today, I hope we will finish it tomorrow :)

int_ua 2012-02-25 08:20

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
I wouldn't say that it's solved because there is no adequate mechanism to save current state in separate files and to stop recording. And I didn't find an easy way to do this yet.

nicholes 2012-02-25 17:58

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
a few question


1. how do i save videos in MyDocs/.videos folder?

2.if i want to extend the time of current.mp4 should i edit the line ...

time.sleep(60) and change it to> time.sleep(120) for two minute....?

3. is there any way we can make a shortcut for this?

4.(if no shortcut) can we somehow get rid of sudo gainroot (it is frustrating) every time?

int_ua 2012-02-26 13:45

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
1. Just run the script in needed folder :)
2. Yes.
3. Since it doesn't have any adequate controls yet I wouldn't recommend using it without terminal.
4. Why do you use root? It's not required.

Did you try to use it? It's not ready for general usage, isn't it?

nicholes 2012-02-27 04:31

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
3 Attachment(s)
Hi,
as you said

"4. Why do you use root? It's not required."

in my case i have to use sudo gainroot.

And another thing, if record.py in MyDocs, even after sudo gainroot,it does not start camera and shows "permission denied"
thus i cannot save my videos in Mydocs folder

to use record.py in my phone. Record.py should be in root folder(home/user)

nicholes 2012-02-27 07:11

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by int_ua (Post 1169375)
I just finished first attempt to get gst-launch working and queue works as expected with this code:
Code:

gst-launch v4l2src device=/dev/video0 ! queue leaky=upstream min-threshold-time=10000000000 ! autovideosink
(time in nanoseconds)
Now it would be great to try to use queue sink in the above python code instead of moving files :) That's all for today, I hope we will finish it tomorrow :)

what does that mean?? i dont get it(sorry my noobness) can you plz explane it for me what to do with this code?

int_ua 2012-02-27 08:42

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by nicholes (Post 1170239)
And another thing, if record.py in MyDocs, even after sudo gainroot,it does not start camera and shows "permission denied"
thus i cannot save my videos in Mydocs folder

to use record.py in my phone. Record.py should be in root folder(home/user)

MyDocs is vfat filesystem mounted with noexec option which prevents you from making files executable on it. And thus you have no permission to execute it => "Permission denied". You can still run scripts from it by executing interpreter and passing the script name to it as an argument:
Code:

$ python record.py
But you don't need to put the script in the same folder. Just run it using absolute path:
Code:

$ cd MyDocs/.videos/or/whatever/wherever
$ /home/user/bin/record.py

It will use current folder as working directory.

And /home/user is not root folder, it's users' $HOME directory. $HOME for user root is typically /root and the root directory is /

int_ua 2012-02-27 08:48

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by nicholes (Post 1170251)
what to do with this code?

This code is just a half-proof of concept, it's far from being any useful :)

nicholes 2012-02-27 13:44

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
can you do the same for voice recording ??

Keeping record of last two minute voice recording!

i started a thread regarding this in past but i didn't get it.

can you help?

skykooler 2012-02-27 14:04

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by nicholes (Post 1170531)
can you do the same for voice recording ??

Keeping record of last two minute voice recording!

i started a thread regarding this in past but i didn't get it.

can you help?

That should be basically the same thing, but ignoring the video component. I'll look at it.

nicholes 2012-02-27 15:26

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by skykooler (Post 1170554)
That should be basically the same thing, but ignoring the video component. I'll look at it.

ya! you are quite right:) my mind didn't think like you:o

skykooler 2012-02-27 18:20

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
Code:

import gst
import time
import os

bin = gst.element_factory_make("camerabin")
bin.set_property("audioenc", gst.element_factory_make("nokiaaacenc"))

while True:
    bin.set_state(gst.STATE_PLAYING)
    bin.set_property("filename", "current.aac")
    bin.set_property("mode",1)
    #starts recording
    bin.emit("user-start")

    time.sleep(60)

    # stops recording
    bin.emit("user-stop")
    bin.set_state(gst.STATE_PAUSED)
    bin.set_state(gst.STATE_NULL)
    try:
        os.remove("twominutesold.aac")
    except OSError:
        print "No two-minutes-old file exists yet."
    try:
        os.rename("oneminuteold.aac", "twominutesold.aac")
    except OSError:
        print "No one-minute-old file exists yet."
    os.rename("current.aac", "oneminuteold.aac")

I think this should work to record just audio.

nicholes 2012-02-28 04:24

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
1 Attachment(s)
It does not work for me.

skykooler 2012-02-28 04:32

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by nicholes (Post 1171152)
It does not work for me.

Hmm. Maybe change all instances of "aac" to "ogg" or "mp4"?

nicholes 2012-02-28 15:06

Re: [Solved] [Maemo 5] Keeping record of last two minute video recording?
 
Quote:

Originally Posted by skykooler (Post 1171156)
Hmm. Maybe change all instances of "aac" to "ogg" or "mp4"?

i tried mp4,ogg.aac

nothing worked. the error is same as above, and the error comes exactly after 60 seconds.

int_ua 2012-06-07 15:59

Re: [Solved] [Maemo 5] Keeping record of last two minute Audio/video recording?
 
Just noticed the Camdrive application for Harmattan:
http://talk.maemo.org/showthread.php?t=84606
Looks very nice. Maybe it'll work with MeeCoLay on N900:
http://talk.maemo.org/showthread.php?t=84482

nicholes 2012-06-07 16:53

Re: [Solved] [Maemo 5] Keeping record of last two minute Audio/video recording?
 
Quote:

Originally Posted by int_ua (Post 1218988)
Just noticed the Camdrive application for Harmattan:
http://talk.maemo.org/showthread.php?t=84606
Looks very nice. Maybe it'll work with MeeCoLay on N900:
http://talk.maemo.org/showthread.php?t=84482

Great! Thanks for the hard work.

will it running via MeeCoLay on n900
or you are going to prot it to maemo?

BTW the GUI look cool!


All times are GMT. The time now is 07:14.

vBulletin® Version 3.8.8