Ask Your Question
0

Timestamp as filename of a recorded video

asked 2019-07-06 05:07:33 -0600

sonicmaster gravatar image

Hey i wanted to record a video from my webcam and save it and i have done that and saved the filename as out.avi but i want to save the recorded file as ‘TestVideo_YYYYMMDD_HHMMSS_x.mp4' ie i want the year month date and time while it was saved. So how can i do this?? please help me....

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2019-07-06 19:54:34 -0600

sjhalayka gravatar image

The following code will give you something close to what you want. If you like the solution that I provided, please mark it as correct, and upvote it. Thanks!

#include <iostream>
#include <ctime>
#include <sstream>

using namespace std;

int main(void)
{
    // http://www.tutorialspoint.com/cplusplus/cpp_date_time.htm

    time_t now = time(0);

    tm *ltm = localtime(&now);

    ostringstream oss;

    oss << "TestVideo_";
    oss << 1900 + ltm->tm_year;
    oss << 1 + ltm->tm_mon;
    oss << ltm->tm_mday;
    oss << '_';
    oss << 1 + ltm->tm_hour;
    oss << 1 + ltm->tm_min;
    oss << 1 + ltm->tm_sec;
    oss << "_x.mp4";

    cout << oss.str() << endl;

    return 0;
}
edit flag offensive delete link more

Comments

2

thank you so much for ur help, i will modify this to my convinence

sonicmaster gravatar imagesonicmaster ( 2019-07-07 23:56:08 -0600 )edit

Thanks for the upvote, etc. ostringstream is your best friend. :)

sjhalayka gravatar imagesjhalayka ( 2019-07-08 00:02:16 -0600 )edit
1

tq so much !!! I arrived at my requirement....

sonicmaster gravatar imagesonicmaster ( 2019-07-08 05:42:47 -0600 )edit

@sonicmaster -- you're welcome. The ostringstream is a mighty weapon.

sjhalayka gravatar imagesjhalayka ( 2019-07-11 13:46:29 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-06 05:07:33 -0600

Seen: 527 times

Last updated: Jul 06 '19