-
Notifications
You must be signed in to change notification settings - Fork 27
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
Include napari version information in output video metadata #167
Conversation
Codecov Report
@@ Coverage Diff @@
## main #167 +/- ##
==========================================
+ Coverage 85.31% 86.22% +0.90%
==========================================
Files 24 26 +2
Lines 926 987 +61
==========================================
+ Hits 790 851 +61
Misses 136 136
... and 3 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
"""Test output video file contians napari version metadata()""" | ||
animation = animation_with_key_frames | ||
output_filename = tmp_path / f"test{ext}" | ||
animation.animate(output_filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that the other tests (like test_animate_filenames
above) are very careful to mock/patch the video writer, so I'm not sure if you won't like that it actually runs here.
I'm not really sure how best to test this without generating real output video files though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is okay, that was done because the output wasn't being checked for anything afaik
Link to a notebook I used while I was figuring this out: https://gist.github.com/GenevieveBuckley/72e438539ab03c792d52040ccb9e8f02 The trick was, you need to SEPARATE the "-metadata" string from the "title=MyTitle" string in the output_params list that gets passed in to imageio_ffmpeg. output_params = ["-metadata", f'title="{description}"'] It will NOT work if you pass it all as one string, eg: Plus, you just extend the idea if you want to pass in more metadata keys. The only problem is, not many metadata keys are supported by a wide variety of file formats. output_params = [
"-metadata", f'title="My Title"',
"-metadata", f'description="Description goes here"', # description metadata supported by .mp4, but not .mov, .avi, and possibly many other file formats
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! thanks for the PR - made a tiny change so there wasnt a spurious reference to __version__
within the package but otherwise this is great!
"""Test output video file contians napari version metadata()""" | ||
animation = animation_with_key_frames | ||
output_filename = tmp_path / f"test{ext}" | ||
animation.animate(output_filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is okay, that was done because the output wasn't being checked for anything afaik
Thanks for the review! |
Description
Companion to PR napari/napari#5494
This adds a digital watermark to the video files output by napari-animation. That means in the future it may be possible to scrape publications & supplementary data, eg: like this analysis done for matplotlib https://github.com/mrocklin/arxiv-matplotlib
Try it out!
Now, you can run the examples to create a video file:
...and then look at the metadata embedded in the video file header with ffmpeg. This ffmpeg command writes the metadata to a text file:
And when you look at the output
...you see something like this (note the new "title" metadata field, which was not there before:
Actually, here is a simpler way to read the metadata from the video file:
Additional details
I have stuffed the napari version information into the "title" metadata key, because that seems to be the most widely available. (.mp4 files do allow a "description" metadata field, but that is not supported by .avi, .mov, and possibly many other file formats).