Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using another filename convention #76

Open
birtezuidinga opened this issue Mar 31, 2022 · 2 comments
Open

Using another filename convention #76

birtezuidinga opened this issue Mar 31, 2022 · 2 comments

Comments

@birtezuidinga
Copy link

birtezuidinga commented Mar 31, 2022

Thank you for all your work regarding the last update! It is great that video files are not overwritten anymore.

However, I now found out that one of my own changes to the code is not working anymore as I intended, probably because I implemented it wrongly. What I would like is for all generated files, that the name does not only consist of the timestamp of recording start, but also the date and animal number. Basically, adding the name of the parent folder to the filename itself, like so:

C:\Users\zuidinga\Data\protocol_name\220331_f60\220331_f60_110908_video.mp4 instead of
C:\Users\zuidinga\Data\protocol_name\220331_f60\110908_video.mp4

(this change used to be enough for it to work for all files, since the write.py of the video process also used self.filename_base: birtezuidinga@7984edd)

Now that different methods are used in write.py to get the filename_base, I cannot get it to work anymore for the video and video_times files. I tried changing the __generate_filename code to the following:

def __generate_filename(self, filename: str) -> str:
        """
        Generates the filename dependent on the given filename and the extension.

        Parameters
        ----------
        filename
            a unique identifier to be used in the filename for saving the video file.
        """

        detailed_name = str(filename.parts[-2]) + "_" + str(filename.name)
        directory = filename.parent
        new_filename_base = directory / detailed_name

        return str(new_filename_base) + "video." + self._extension

Sometimes, it works correctly, and other times it gives this error:

Process :
Traceback (most recent call last):
  File "C:\Users\zuidinga\Miniconda3\envs\stytra_env_github\lib\multiprocessing\process.py", line 297, in _bootstrap
    self.run()
  File "C:\Users\zuidinga\PycharmProjects\stytra_birte\stytra\stytra\hardware\video\write.py", line 91, in run
    self._configure(current_frame.shape)
  File "C:\Users\zuidinga\PycharmProjects\stytra_birte\stytra\stytra\hardware\video\write.py", line 295, in _configure
    self._container = av.open(self.__container_filename, mode="w")
  File "av\container\core.pyx", line 364, in av.container.core.open
  File "av\container\core.pyx", line 146, in av.container.core.Container.__cinit__
ValueError: Could not determine output format

Do you have any idea how I could fix this? I probably don't understand the process of the filename queue correctly, I think I'd need to change some default string there, but I cannot find it.

@vilim
Copy link
Member

vilim commented Mar 31, 2022

I think it would be far easier to rely on the JSON that gets auto-generated with the video on getting metadata, or writing a small script in python that renames files rather than changing the internals of Stytra. What exactly are you doing with the videos afterwards that requires such a naming schema?

@birtezuidinga
Copy link
Author

Thank you for your reply. Did not realise it would be a difficult change to copy the folder name in front of the timestamp. But I will rename the files afterwards then.

The reason is that I prefer to immediately see which videos were from which flies on which day just from the name, since I am importing many videos separately into a behavioural classification model. The outputs of this model use the names of the video files. And so by having a unique name for each experimental trial, I can search through these outputs quickly to match it to other information saved in the metadata and other files. Since the videos in the analysis end up together in a different folder, the nice folder structure that Stytra outputs gets lost there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants