ffmpeg trim/copy video without changing metadata

Started by gecko, October 05, 2020, 06:52:28 AM

Previous topic - Next topic

gecko

How can I trim and copy a video and preserve all metadata?

Phil Harvey

Honestly, I doubt that this is possible with any software on the market.

- 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 ($).

StarGeek

At the very least, you're likely to lose any EXIF data, any GPS tracks, and probably any Microsoft MP tags.  In the first two cases, there isn't a standard for this data in video streams and every camera manufacturer does it their own way.  In the case of the Microsoft video tags, there pretty much isn't a program out there that can edit them.

I listed a command in this post that I use to convert videos from one container to another without re-encoding, e.g. MKV/AVI to MP4, that tries to copy as much data as possible.  You could use that as a base.  Otherwise, you might try some other sites to ask, such as r/ffmpeg/ on Reddit or various StackExchange sites.
* 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).

delerious

I don't think there's a way to preserve all the metadata using the ffmpeg command (although I read you can use exiftool to copy all the metadata from the original video to the trimmed video).

But I have found that the -movflags use_metadata_tags option preserves some of the important tags (for me at least), like QuickTime:Model, QuickTime:Software, and QuickTime:CreationDate.

Also, I noticed that ffmpeg would set a lot of the timestamp tags, including QuickTime:CreateDate, to 0000:00:00 00:00:00. I found that the -map_metadata 0 option prevents that from happening.

wywh

I'd advice not try to include metadata in ffmpeg when re-encoding, or other tools when just trimming. Do it later in exiftool with -tagsFromFile.

ffmpeg '-map_metadata 0' does not keep custom/arbitrary meta keys. '-movflags use_metadata_tags' are written in an unconventional manner and Quicktime Player does not recognize them.

I did a quick test trim with macOS 13.4 QuickTime Player and Avidemux_2.8.1 (I original.mp4, II trimmed with QuickTime Player, III trimmed with Avidemux).

QuickTime Player seems preserve some tags but it puts them willy-nilly in other tags:

exiftool -a -G1 -s -n -api LargeFileSupport=1 -api QuickTimeUTC=1 -MacOS:FileCreateDate -System:FileModifyDate -QuickTime:CreateDate -Keys:All -UserData:All -ItemList:All original.mp4
[MacOS]         FileCreateDate                  : 2001:02:01 12:01:01+02:00
[System]        FileModifyDate                  : 2002:02:02 12:02:02+02:00
[QuickTime]     CreateDate                      : 2003:03:03 12:03:03+02:00
[Keys]          CreationDate                    : 2005:05:05 12:05:05+02:00
[Keys]          GPSCoordinates                  : -36.6101 -66.91515 119.9
[Keys]          Author                          : Author Keys
[Keys]          Description                     : Description Keys
[Keys]          DisplayName                     : DisplayName Keys
[Keys]          Keywords                        : Keywords 1 Keys,Keywords 2 Keys
[Keys]          Title                           : Title Keys
[Keys]          UserRating                      : 3
[Keys]          LocationName                    : LocationName Keys
[UserData]      DateTimeOriginal                : 2004:04:04 12:04:04+02:00
[UserData]      GPSCoordinates                  : 36.6101 -66.91515 119.9
[UserData]      Author                          : Author UserData
[UserData]      ClipFileName                    : ClipFileName UserData
[UserData]      Title                           : Title UserData:ID-titl
[UserData]      Title                           : Title UserData:ID-a9nam
[UserData]      UserRating                      : 2
[UserData]      LocationInformation             : 36.6101, 66.91515, 119.9 Role=shooting Lat=999.00000 Lon=999.00000 Alt=0.00 Body= Notes=
[ItemList]      Author                          : Author ItemList:ID-auth
[ItemList]      Keyword                         : Keyword 1 ItemList,Keyword 2 ItemList
[ItemList]      Author                          : Author ItemList:ID-a9aut
[ItemList]      Title                           : Title ItemList
[ItemList]      GPSCoordinates                  : -36.6101 66.91515 119.9
[ItemList]      Description                     : Description ItemList

exiftool -a -G1 -s -n -api LargeFileSupport=1 -api QuickTimeUTC=1 -MacOS:FileCreateDate -System:FileModifyDate -QuickTime:CreateDate -Keys:All -UserData:All -ItemList:All macOS13_QuickTime_Player_trim.mp4
[MacOS]         FileCreateDate                  : 2023:07:16 15:06:14+03:00
[System]        FileModifyDate                  : 2023:07:16 15:06:14+03:00
[QuickTime]     CreateDate                      : 2023:07:16 15:06:14+03:00
[UserData]      Author                          : Author Keys
[UserData]      Author                          : Author ItemList:ID-a9aut
[UserData]      Description                     : Description Keys
[UserData]      Description                     : Description ItemList
[UserData]      Title                           : DisplayName Keys
[UserData]      Title                           : Title ItemList
[UserData]      GPSCoordinates                  : 36.6101 -66.91515 119.9
[UserData]      LocationInformation             : (none) Role=shooting Lat=-36.61009 Lon=-66.91515 Alt=119.90 Body=earth Notes=
[UserData]      DateTimeOriginal                : 2005:05:05 12:05:05+02:00
[UserData]      DateTimeOriginal                : 2004:04:04 12:04:04+02:00

exiftool -a -G1 -s -n -api LargeFileSupport=1 -api QuickTimeUTC=1 -MacOS:FileCreateDate -System:FileModifyDate -QuickTime:CreateDate -Keys:All -UserData:All -ItemList:All Avidemux2.8_trim.mp4
[MacOS]         FileCreateDate                  : 2023:07:16 15:11:44+03:00
[System]        FileModifyDate                  : 2023:07:16 15:11:44+03:00
[QuickTime]     CreateDate                      : 1904:01:01 01:39:49+01:39
[ItemList]      Encoder                         : Lavf58.76.100

- Matti