How can you add custom metadata to a video (.mov, .mp4) with AVFoundation? - swift

Although this question has been asked before, I still have not found a single working example of how to do this.
I have a golf swing analysis app that allows the user to save 10 positions in the videoclip that can be navigated to with a shortcut. Until now I have saved the position data separately from the video-file, which is less than ideal for obvious reasons, so I would like to save the position data as metadata in the video-file.
Can anyone give me a working example of saving a String (I'll use Codable to encode the data structure which is not very large) to a custom metadata key (ex. "posi") given an AVAsset?

Related

Add 3 star based score system to Unity2d Game

I am having difficulties implementing a 3 star based rating system in my 2d game. What I have managed to implement is that when a level is completed, it displays the star rating for that level (1 stars, 2 Stars or 3 Stars) by taking advantage of an integer I stored in PlayerPrefs. Now I want to display the star gotten in the level select screen for each level. Each time a level is finished, it deletes the previous PlayerPrefs that is stored with a new value. And I also want it to only change or display the star in the level select screen only if what you got is larger than what you got before. Very challenging :(
How can I go about this?
If I were you, I would look into read/writing to files. Storing each star rating, for each level on a separate line, for example. I wouldn't use PlayerPrefs as they should only really be used for storing a few values, especially if you plan to have many levels. If you want to have some sort of encryption for the file (so it's a little but harder to edit), you could look into converting text files to binary files. But, otherwise look into saving data to files, good luck!.

Saving Data in Firebase Realtime Database with Unique Key + custom name

I'm wondering if there is a problem with saving Data like this.
Json-tree
As you can see I have used a unique ID but wrote the title infront of it to make it easier to identify what I'm looking at as a human.
the reference looks like this:
let storyLocation = Database.database().reference().child("storyDetails").child("\(titel)(\(storyID!))")
It works all fine at this point but I'm not sure if this is the right way to go, when the project gets bigger.
Right now I see 3 potential problems.
This might require a bit more storage
It could slow down writing and retrieving from the Database
If we assume that a Title could later be changed, it has to be changed in different places at the same time.
I'm still quite new to this Topic. So I would like to know if someone with more experience would save data like this or if there is a better solution.
I'd personally save JUST the id as the key instead of title and storyId combined. I also wouldn't save the id inside of that as you can simply get a hold of the id by accessing the key like so let id = snapshot.key. Simply store the author and title inside it to be more efficient.

Where to store a real time strategy data?

I'm trying to make a basic RTS, but I have no idea where can I store data, for example units, buildings, etc. I'd like to avoid making a hundreds of .txt files (or one, very big .txt file). Well, I could just write a header with a class of every single object, but wouldn't it be too much? I mean, if I make about 20 units (in total, of course) with similar stats (range, attack value, health, etc.) and only with different special abilities, I think it is quite strange to set everything in 20 constructors, doesn't it?
Another problem is with storing a map. I think I'll try the .txt solution here, but I'm probably going to write some kind of map editor in WinAPI or sth like that, setting the map in the .txt file would be a torment. So I know how to represent tiles (I want the map to be a tiled one, it will be much easier to implement, I suppose), but what if there is a unit that takes more than only one tile, how can I deal with this?
Txt and XML are not great solutions, and also writing and reading from disk isn't the cheapest operation you can do in real time. The way to do this in Unity is through Serialization, basically you write a class that allow you to store data without instantiating a GameObject for it, and whenever you'd like to, you can save or load it at runtime. There is also a great tutorial about data persistence on Unity Tutorials page. (Link Here)
I highly recommend the Easy Save plugin. I'd set it up so it only saves to disk every few seconds, not a constant stream. Also, with Easy Save you can save just bits and pieces to a larger save file rather than saving everything with each pass. If the game crashes, you might lose a couple seconds of progress, but that should be an acceptable loss in the case of a crash or quit.

How do I obtain a hash of the payload of a digital photo container, ideally in Java?

I have edited EXIF properties on digital pictures, and would like to be able to identify them as identical. I believe this implies extracting the payload stream and computing a hash. What is the best way to do this, ideally in the Java language, most ideally in Java using a native implementation for performance.
JPEG files are a series of 'segments'. Some contain image data, others don't.
Exif data is stored in the APP1 segment. You could write some code to compare the other segments, and see if they match. A hash seems like a reasonable approach here. For example, you might compare a hash of only the SOI, DQT or DHT segments. You'd need to experiment to see which of these gives the best result.
Check out the JpegSegmentReader class from my metadata-extractor library.
Java: https://github.com/drewnoakes/metadata-extractor
.NET: https://github.com/drewnoakes/metadata-extractor-dotnet
With that class you can pull out specific segment(s) from a JPEG for processing.
Let us know how you get on!

How to get the date from a NSImage

I'm working on a Mac App. I am relatively new to cocoa development and I'm struggling with a problem. Is there a way, to get the creation date information from a NSImage using Swift? I couldn't find a way to do this. And is there a way to get other metadata (exif) from a NSImage as well?
Thank you!
If you mean a file creation date, not all images are associated with files and even those that are don't expose an API for querying what that file is or any information about it.
For the EXIF data, you can iterate over the representations of the image. If any of them are of class NSBitmapImageRep, you can query rep.valueForProperty(NSImageEXIFData) to get a dictionary of EXIF key-value pairs. The keys are documented here. Note that an image may have no bitmap image reps, may have one, or may have multiple. It's up to you to figure out what to do in each case.