Calculation of remaining time in video record mode - done - General Discussion and Assistance - CHDK Forum

Poll

Do you think this feature would be useful?

Yes, i'd really like to have that feature
10 (66.7%)
Nice to have, not important though
4 (26.7%)
Don't need it
1 (6.7%)

Total Members Voted: 15

Calculation of remaining time in video record mode - done

  • 20 Replies
  • 11725 Views
*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Calculation of remaining time in video record mode - done
« on: 17 / February / 2008, 18:41:33 »
Advertisements
edit: read remaining video time,overrides-cusomizations,no-raw@video,just _random_ stuff :D - it is done

Hi,

as my other project ( Calculation of remaining shots with RAW - done :D ) seems to be finished very soon, i want to start the second one, a small one. it's also having to do with calculating stuff, this time it is planned that there will be a new OSD item that tells you the remaining time when in video record mode.
this feature is neccessary (in my eyes) for a few reasons:
the built-in canon counter does only show the remaining time in idle mode, before shooting the movie. during recording you only see the time since the start of recording. even IF canon would show you everything while recording, it wouldnt make much sense if you choose to override the movie settings (quality, bitrate) via chdk.
as a temporary workaround for finding out how long you can record a movie (DURING shooting) you can use my filespace icon or TXT (in megabyte) (from the thread mentioned above - soon to be in official trunk).

I quickly searched the sourcecode, but i couldnt find anything i could use to find out if a movie recording is being made. i can only check if we are in playback mode or in rec mode (and WHICH rec mode, i.e. C, M or movie). i guess i can somehow circumvent this, but it will not be as accurate.

whim already had an idea for implementing it, pseudo-code wise:
Quote
// pseudo-code snippet for calc time left

if (video_recording_started) {
    original_space = GetFreeCardSpaceKb();
    original_time = get_current_time();

    while(video_recording) {
        space_eaten = original_space - GetFreeCardSpaceKb();
        time_elapsed = get_current_time() - original_time;

        avg_use = space_eaten / time_elapsed; // Kb/sec

        time_left = GetFreeCardSpaceKb() / avg_use
    }
}
but if we lack a check for "if video_rec started/running" it will be difficult.
devs - any ideas?
« Last Edit: 06 / April / 2008, 18:59:10 by PhyrePhoX »

*

Offline whim

  • ******
  • 2046
  • A495/590/620/630 ixus70/115/220/230/300/870 S95
Re: Calculation of remaining time in video record mode
« Reply #1 on: 17 / February / 2008, 19:14:48 »
Hi PhyrePhox - some out-loud-thinking here:

To start a video, what do we do --> switch to video mode (we can detect that)
then we press shoot full (we can detect that too)

wim



*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Calculation of remaining time in video record mode
« Reply #2 on: 17 / February / 2008, 20:11:09 »
good idea!
Code: (c) [Select]
static void gui_space_draw_mb() {
int o=mode_get(),m=(mode_get()&MODE_SHOOTING_MASK);
static int a;
if (((o&MODE_MASK) == MODE_REC) & ((m&MODE_SHOOTING_MASK)==MODE_VIDEO_STD))
{

if (kbd_is_key_pressed(KEY_SHOOT_FULL) == 1)
{
    a=!a;
}
if (a==1)
{
            draw_string(100, 100, "SHOOT!", conf.osd_color);
}
else
{
            draw_string(100,100, "NOT SHOOT", conf.osd_color);
}
}
you have to disable the check for kbd_is_key_pressed(KEY_SHOOT_HALF)!=1) down in that file when gui_space_draw_mb is called in order for that to work.
this actually works, but: since this is checked about 12 times a second, a is overwritten again, because no human can press a button within a timeframe of 1/12 s. we can extend that time (like i did in the RAW icon function) but then we maybe miss that the button is being pressed. there has got to be a way to find out if vide_rec is running. but i guess i'd have to analyze firmware or something. propcases doesnt seem to help here either.
edit: i will just add a timecheck... :)
edit2: hmm, i just patched gui_osd_draw_clock to show the seconds as well. might come in handy when you want to take a picture at an exact moment.
edit3: hm, too tired to test it. but we're getting there :D
« Last Edit: 17 / February / 2008, 20:38:51 by PhyrePhoX »

Re: Calculation of remaining time in video record mode
« Reply #3 on: 17 / February / 2008, 20:33:36 »
Deleted
« Last Edit: 22 / April / 2008, 12:15:23 by Barney Fife »
[acseven/admin commented out: please refrain from more direct offensive language to any user. FW complaints to me] I felt it imperative to withdraw my TOTAL participation. Nobody has my permission, nor the right, to reinstate MY posts. Make-do with my quoted text in others' replies only. Bye


*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Calculation of remaining time in video record mode
« Reply #4 on: 17 / February / 2008, 20:54:56 »
that indeed is a snafu. thanks for the input! i still have the feeling we will make it, somehow :)

*

Offline whim

  • ******
  • 2046
  • A495/590/620/630 ixus70/115/220/230/300/870 S95
Re: Calculation of remaining time in video record mode
« Reply #5 on: 17 / February / 2008, 22:43:27 »
@PhyrePhox

Funny, i had gone to bed, couldn't fall asleep and dreamed up something very similar
to your code, abstractly. Then saw your code and reworked it a bit:

Code: (c) [Select]
// since this gets called in gui_osd_draw(), the main loop (?) in gui_osd.c,
// it should follow the appropiate naming convention, looks better ;)
// Note: Also needs an 'extern void gui_osd_draw_movie_time_left();' in gui_osd.h
 
void gui_osd_draw_movie_time_left()  {
 
static int card_used, init_space, elapsed, avg_use, time_left;
static long init_time;
static int movie_running = 0;
static int init = 0;
static unsigned int skipcalls = 15;
 
int o=(mode_get() & MODE_MASK), m=(mode_get() & MODE_SHOOTING_MASK);
unsigned int hour=0, min=0, sec=0;

    // allow it to be turned on/off
    // if (!conf.show_movie_time_left) return;
   
    if ( (o != MODE_REC) || (m != MODE_VIDEO_STD) )  return;

    if (kbd_is_key_pressed(KEY_SHOOT_FULL) == 1)  movie_running = !movie_running ;

    if (!movie_running)  {
        // it's off, reset init
        init = 0;
        return;
        }
    else {
        //movie recording engaged
        if( !init )  {
            // initialize
            init_space = GetFreeCardSpaceKb();
            init_time  = get_tick_count();
            init = 1;
            }
        else {
            // already running
            if (--skipcalls ==0) {
                // only calc at every 15 th interrupt (should equal every 1 sec for about 15 interupt calls/sec)
                card_used = init_space - GetFreeCardSpaceKb();
                // Note: there's 1000 ticks to a second
                elapsed = (int) ( get_tick_count() - init_time ) / 1000;
                // End Note
                if (elapsed < 10) return;    // initially give it a minimum of say 10 secs to settle ...
                avg_use = card_used / elapsed;  // running average Kb/sec
                time_left = (GetFreeCardSpaceKb() / avg_use);
                hour = time_left / 3600;
                min = (time_left % 3600) / 60;
                sec = (time_left % 3600) % 60;
                skipcalls = 15;
                }
            // called at every interrupt   
            sprintf(osd_buf, "Avg. %d KB/s ; %2d:%2d:%2d left", avg_use, hour, min, sec);
            // use this if we decide to make it configurable ....
            // draw_string(conf.mode_movie_time_left.x, conf.mode_movie_time_left.y, osd_buf, conf.osd_color);
            // for testing ...
            draw_string( 50, 50, osd_buf, conf.osd_color);
            }
        }

}

unchecked of course ...
talk to you later and now zzzzzzzzzzzzzz
wim

edit: code improved, we're getting there ...
edit2: gone off to test it now
edit3: compiles OK, but doesn't seem to function ...
« Last Edit: 18 / February / 2008, 13:05:27 by whim »

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Calculation of remaining time in video record mode
« Reply #6 on: 18 / February / 2008, 07:18:11 »
can't wait to try it this evening (i'm at work right now :() :)

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Calculation of remaining time in video record mode
« Reply #7 on: 18 / February / 2008, 12:27:16 »
heya whim, does this compile, does it work? will somehow test it right now.


*

Offline whim

  • ******
  • 2046
  • A495/590/620/630 ixus70/115/220/230/300/870 S95
Re: Calculation of remaining time in video record mode
« Reply #8 on: 18 / February / 2008, 13:03:27 »
Hi Phox,
I got it compile without errors, but running ? Can't tell - see nothing  :(

I'll update previous post, because I haven't done that for almost 3 hours ...

wim



*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Calculation of remaining time in video record mode
« Reply #9 on: 18 / February / 2008, 15:09:23 »
yeah it compiles, you are right. and it shows the string with "avg ..." but the values are zero.
hm. too bad there is no debugger :D

i think the problem is ,that when you press the button, the part where you set movie_running = !movie_running ; is called more than once.

edit: doesnt seem to be the only problem. hm. tough.
« Last Edit: 18 / February / 2008, 15:16:57 by PhyrePhoX »

 

Related Topics