comeradealexi
Posts: 4
Joined: Sun Dec 10, 2017 3:40 pm

raspivid -o Vid%04d.h264 does not work correctly. Outputs always as Vid0011.h264

Thu Oct 11, 2018 5:23 pm

Hi!

I've just downloaded and installed the latest version of rasparian OS and I've run into a problem with raspivid where the segmented output file name has stopped working.

This is my full command line:
sudo raspivid -w 1280 -h 720 -o Video_%04d.h264 -ex night -sg 3000 -wr 144 -sn 0 -t 0 -fps 7 -rot 180 -b 700000

However with this command line, the file produced is always Video_0011.h264. Even with %03d, it also produces the same file name. So even when it moves to the next file name, it just writes to the same file.

I've managed to get around the issue by using Video_%d.h264 instead for now, and this appears to work, though obviously doesn't output in the format I was originally trying to achieve (Video_0000.h264).

Is there a bug or something? I've updated to the latest version of everything and latest firmware.

My raspivid version is 1.3.12.

Thanks!

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5947
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: raspivid -o Vid%04d.h264 does not work correctly. Outputs always as Vid0011.h264

Thu Oct 11, 2018 8:02 pm

It looks like a rather crude assumption was made when saving to a timestamped filename was added
https://github.com/raspberrypi/userland ... id.c#L1094

Code: Select all

      // If %d or %u, assume a segment numnber, otherwise use the formatter as
      // input to strnftime
      if (strstr(filename,"%u") != NULL || strstr(filename,"%d") != NULL)
      {
          asprintf(&tempname, filename, pState->segmentNumber);
      }
      else
      {
         char temp_ts_str[100];
         time_t t = time(NULL);
         struct tm *tm = localtime(&t);
         strftime(temp_ts_str, 100, filename, tm);
         asprintf(&tempname, "%s", temp_ts_str);
}
So if you use %04d then it assumes you want to insert a timestamp and calls strftime instead.
It would be possible to make update that check to accept %03d - do you fancy creating a patch and pull request?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

comeradealexi
Posts: 4
Joined: Sun Dec 10, 2017 3:40 pm

Re: raspivid -o Vid%04d.h264 does not work correctly. Outputs always as Vid0011.h264

Thu Oct 11, 2018 8:37 pm

Thanks for pointing to the source code! Looks like the bug was introduced when timestamp support was added.

I'll submit a change now, this is how I modified the code:

It looks for the first percentage symbol then continues searching for valid numbers until it either reaches the end of the string or finds a 'u' or 'd'. Do you think this solution cuts the mustard?

Code: Select all

if (pState->segmentSize || pState->splitWait)
{
	// Create a new filename string

	//If %d/%u or any valid combination e.g. %04d is specified, assume segment number.
	bool bSegmentNumber = false;
	const char* pPercent = strstr(filename, "%");
	if (pPercent)
	{
		pPercent++;
		while (*pPercent != '\0' && isdigit(*pPercent))
			pPercent++;
		if (*pPercent == 'u' || *pPercent == 'd')
			bSegmentNumber = true;
	}

	if (bSegmentNumber)
	{
		asprintf(&tempname, filename, pState->segmentNumber);
	}
	else
	{
		char temp_ts_str[100];
		time_t t = time(NULL);
		struct tm *tm = localtime(&t);
		strftime(temp_ts_str, 100, filename, tm);
		asprintf(&tempname, "%s", temp_ts_str);
	}

	filename = tempname;
}

comeradealexi
Posts: 4
Joined: Sun Dec 10, 2017 3:40 pm

Re: raspivid -o Vid%04d.h264 does not work correctly. Outputs always as Vid0011.h264

Thu Oct 11, 2018 8:48 pm

I've made a pull request! I've never done this before! It's quite exciting! https://github.com/raspberrypi/userland/pull/491

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20944
Joined: Sat Jul 30, 2011 7:41 pm

Re: raspivid -o Vid%04d.h264 does not work correctly. Outputs always as Vid0011.h264

Thu Oct 11, 2018 9:18 pm

Not really a bug, just a cheap and cheerful bodge. Surprised it taken this long to be noticed....
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

Return to “Camera board”