Samsung Trailer tag

Started by Ryan_Kinkar, March 20, 2024, 07:41:09 AM

Previous topic - Next topic

Ryan_Kinkar

Is there an application that can edit the Samsung Trailer Tab time stamp, or can exiftool do it if so how.

Phil Harvey

Your only option is with a hex editor.  Use the exiftool -v3 option to see where this time stamp is stored.

P.S.  I hope you do well on your assignment.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

doodspav

I'm not sure if I should start a new thread or just reply in this one, so I'll try replying here.

Editing the timestamp works with a hex editor because it's fixed length (I think).

I want to insert exif tags into a JPEG image that didn't previously have them, specifically:
- Samsung:TimeStamp
- Samsung:MccData
- Samsung:EmbeddedVideoType
- Samsung:EmbeddedVideoFile

These are all part of the Samsung trailer, and I'm worried about doing this manually in case some other size or offset field that I'm unaware of needs to be changed somewhere else in the file.

My goal is to create a Samsung compatible Motion Photo from a JPEG and MP4 file. Is it possible for me to write a config file that will make these fields writable? I'm not sure why they're not writable if ExifTool has no trouble reading them.

StarGeek

Quote from: doodspav on April 13, 2024, 05:24:04 PMI'm not sure if I should start a new thread or just reply in this one, so I'll try replying here.

When you see this

then it's time to start a new thread and refer back to the older one if necessary.  The problem is that inexperienced users think it's a related problem, when it's a completely different problem all together. It makes it harder to search and find things if unrelated subjects are grouped together, IMO.

QuoteEditing the timestamp works with a hex editor because it's fixed length (I think).

Yes.  I posted instructions somewhere, on a StackExchange site I think, though I may have posted here as well.  But the Samsung:TimeStamp is simply a Unix time stamp, which you can easily look up.  But as such, it doesn't contain a time zone, so it has to be adjusted to get an accurate value.

QuoteI want to insert exif tags into a JPEG image that didn't previously have them, specifically:
- Samsung:TimeStamp
- Samsung:MccData
- Samsung:EmbeddedVideoType
- Samsung:EmbeddedVideoFile

Just a nitpick, these are, as it says, Samsung tags, not EXIF tags. All EXIF data is metadata, but not all metadata is EXIF data.  See the Tags Names page.

QuoteThese are all part of the Samsung trailer, and I'm worried about doing this manually in case some other size or offset field that I'm unaware of needs to be changed somewhere else in the file.

Samsung:TimeStamp shouldn't be a problem, as it is a fixed length. I don't know anything about the others to comment.

QuoteIs it possible for me to write a config file that will make these fields writable?

I do not believe so, though Phil would have to verify. It would require code to specifically write this chunk and do so without corrupting something else in the file, and I don't think such code that could write this is currently part of the program. As you mentioned, there may be other offsets in the file pointing to the trailer, though I don't think there are.

QuoteI'm not sure why they're not writable if ExifTool has no trouble reading them.

Reading data and writing data according to the specs so you don't damage anything else in the file are two entirely different things.  Especially, as in this case, there isn't any documentation on what the spec should be.  Additionally, camera companies are constantly changing their MakerNotes between various camera models, so you have to account for each and every one of these changes.

For example, one of the main reasons exiftool doesn't have the ability to change metadata in MP3s is, as Phil said
Quote from: Phil Harvey on December 28, 2017, 05:42:04 AMBut writing MP3 is a different story.  I don't have any suggestions about what to do there.  ExifTool would have already supported writing ID3 metadata in MP3 files, but the ID3 specification was written by idiots, and omits key details which are necessary to be able to write it properly.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

This StackOverflow question is where I detailed how to edit the Samsung:TimeStamp.

I forgot to respond to this
QuoteMy goal is to create a Samsung compatible Motion Photo from a JPEG and MP4 file.

Do you have instructions on how this could be done?
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

doodspav

> Do you have instructions on how this could be done?

Not instructions so much as a set of requirements.

Google Photos requires:
- MP4 file is appended to the end of the JPEG file (actually it can be anywhere in the file, e.g. in the Samsung trailer, this is just the default behaviour by Google Pixels)
- MicroVideo: 1
- MicroVideoVersion: 1
- MicroVideoOffset: offset from end of combined file to start of mp4 file in the combined file
- MicroVideoPresentationTimestampUs: ommitted, set to -1, or set to some value whose meaning i'm unsure of

Google Gallery additionally requires:
- filename begin with 'MV'

Samsung Native Photo Viewer requires:
- EmbeddedVideoType: MotionPhoto_Data
- EmbeddedVideoFile: <binary contents of MP4 file>

I haven't verified if Samsung additionally requires the Micro tags that Google requires, but I have confirmed that a file that has all of the above requirements works on all the applications mentioned above, as well as on some non-Samsung/Pixel android devices (running Google Photos I think).

If you're asking about how one would go about writing the Samsung tags in a "Samsung standards compliant manner", unfortunately I have no idea at the moment (that's why I came here).

Phil Harvey

Quote from: StarGeek on April 13, 2024, 05:58:22 PM
Quote from: doodspav on April 13, 2024, 05:24:04 PMIs it possible for me to write a config file that will make these fields writable?

I do not believe so

Correct.  New code would have to be added to ExifTool to allow this.

There is basic code to write the Samsung trailer in ProcessSamsung of lib/Image/ExifTool/Samsung.pm, but it doesn't have the ability to add new tags.  There are offsets in this trailer that need to be adjusted if the position of anything changes, which is the reason that ExifTool needs to be able to rewrite this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

doodspav

That's unfortunate but understandable. For now, since really I only need two of the fields, I'm going to try to fudge it manually.

I found that I can do:
exiftool -b -trailer <file> > out.bin
so hopefully I can also do:
exiftool -trailer=<in.bin

One small thing though, when I do:
exiftool -b -EmbeddedVideoFile > video.mp4
how does the tool know how big the file is?
I'm not seeing any size data for this field like I am for the other fields.
Does it just assume it'll be the last field, and takes the rest of the trailer?

doodspav

Also followup question (since I can't find a good answer anywhere else online).
The JPEG images created by Apple from a Live Photo already contain trailer data.
Can an image have multiple "trailer sections" from different vendors, or is this generally unsupported/unexpected?
My understanding is that trailer sections are vendor specific so it would be odd to have multiple, but I'm wondering if you'd ever seen it before?

(I don't mind removing the trailer data if multiple trailers aren't possible, indeed it makes this much easier, I was just wondering).

StarGeek

I would say that is unknown territory.  Only way to know is to try it out.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

doodspav

Ok so small update:
- I've decided to do away with the iOS trailer, I'm assuming that no android device will know what to do with it, so there's not much point in keeping it
- Samsung doesn't require any EXIF data for their Motion Photo implementation; I removed all AppN segments from the JPEG file, and the Motion Photo still worked fine, solely off of the trailer data (unless metadata can be stored in other segments, but I think that's unlikely)

However I'm a bit stuck with replacing the video in the trailer with my own.
I've confirmed that that EmbeddedVideoFile trailer tag starts directly after the EmbeddedVideoType tag ("MotionPhoto_Data"), and I'm working under the assumption that it extends to the end of the file. I've also fairly certain that the size of the EmbeddedVideoFile is not specified anywhere in the trailer.

Unfortunately when I replace the EmbeddedVideoFile (a.k.a. truncate the JPEG file after "MotionPhoto_Data" and append my own MP4 file), ExifTool ceases to be able to detect the Samsung trailer at all, a.k.a. exiftool -Samsung:all <file> shows nothing. (Fwiw Samsung's Gallery app also can't play it as a Motion Photo, so it's not just ExifTool, but easier to make ExifTool happy for now, and then worry about Samsung.)

I would appreciate some help in crafting a Samsung trailer with a custom MP4 video that ExifTool is happy with, and I'm hoping that this might be relatively straightforward for people experienced with the codebase/tool?

Unfortunately I can't upload the Samsung JPEG Motion Photo file I'm using because it says it's a security risk, but I got it from here on GitHub so in case anyone wants to try to help, they can get it directly from there too.
I'm also open to suggestions on what to try, as well as links to relevant documentation.

Phil Harvey

Files may have multiple trailers.  This sample has 7 trailers, including a Samsung trailer.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

doodspav

Quote from: Phil Harvey on April 15, 2024, 07:35:19 AMFiles may have multiple trailers.  This sample has 7 trailers, including a Samsung trailer.

How can you tell? Is there some way that exiftool can give me this information, or you just know it because you've looked at the file before?

Running exiftool -trailer ExifTool.jpg just gives me a single trailer with 3573 bytes.

Phil Harvey

Take a look at ExifTool's -htmldump output in your web browser.

You can also look at the -v output.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

doodspav

Wow, htmldump is an amazing tool. And with that, I finally have the bare minimum I need and I can finally make my own Motion Photos :) Thanks for all the help (code is here but still a work in progress).