Weird timeline behavior when re-encoding home videos in photos

I have decided to re-encode all my home videos taken from my iphone, mostly because the plex app on most of my TVs refuses to play them. Most of them are taken in 4k and I have a beefly plex server, so I decided to encode them with h265 to save some space.

For some reason, my first test file is not going well. When encoding and copying all metadata over, plex timeline is showing the date as April 9th, when the original was taken on April 16th. There is no tag with April 9th as a date from exiftool output at all.

Here are my commands used to re-encode and copy over metadata:

ffmpeg -i "2018-04-16 10.01.01.MOV" -c:v libx265 -c:a copy -crf 21 -map_metadata 0:g "2018-04-16 10.01.01_21.mp4"
exiftool -tagsfromfile 2018-04-16\ 10.01.01.MOV "-gps*" 2018-04-16\ 10.01.01_21.mp4 -overwrite_original

Here is the new file’s metadata (gps data removed on purpose):

ExifTool Version Number         : 10.55
File Name                       : 2018-04-16 10.01.01_21.mp4
Directory                       : .
File Size                       : 132 MB
File Modification Date/Time     : 2018:04:18 10:51:07-04:00
File Access Date/Time           : 2018:04:18 10:51:19-04:00
File Inode Change Date/Time     : 2018:04:18 10:51:07-04:00
File Permissions                : rw-rw-r--
File Type                       : MP4
File Type Extension             : mp4
MIME Type                       : video/mp4
Major Brand                     : MP4  Base Media v1 [IS0 14496-12:2003]
Minor Version                   : 0.2.0
Compatible Brands               : isom, iso2, mp41
Movie Data Size                 : 137775130
Movie Data Offset               : 44
Movie Header Version            : 0
Time Scale                      : 1000
Duration                        : 0:01:39
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Track Header Version            : 0
Track Create Date               : 2018:04:17 13:26:41
Track Modify Date               : 2018:04:17 13:26:41
Track ID                        : 1
Track Duration                  : 0:01:39
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 3840
Image Height                    : 2160
Graphics Mode                   : srcCopy
Op Color                        : 0 0 0
Compressor ID                   : hev1
Source Image Width              : 3840
Source Image Height             : 2160
X Resolution                    : 72
Y Resolution                    : 72
Bit Depth                       : 24
Video Field Order               : Progressive; 0
Video Frame Rate                : 30
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2018:04:17 13:26:41
Media Modify Date               : 2018:04:17 13:26:41
Media Time Scale                : 44100
Media Duration                  : 0:01:39
Media Language Code             : und
Handler Description             : SoundHandler
Balance                         : 0
Audio Format                    : mp4a
Audio Channels                  : 2
Audio Bits Per Sample           : 16
Audio Sample Rate               : 44100
Handler Type                    : Metadata
Handler Vendor ID               : Apple
Encoder                         : Lavf56.25.101
XMP Toolkit                     : Image::ExifTool 10.55
Create Date                     : 2018:04:17 13:26:41
Modify Date                     : 2018:04:17 13:29:01
Avg Bitrate                     : 11.1 Mbps
Image Size                      : 3840x2160
Megapixels                      : 8.3
Rotation                        : 0

Here is the original file’s metadata (gps data removed on purpose):

ExifTool Version Number         : 10.55
File Name                       : 2018-04-16 10.01.01.MOV
Directory                       : .
File Size                       : 297 MB
File Modification Date/Time     : 2018:04:18 08:53:42-04:00
File Access Date/Time           : 2018:04:18 09:31:25-04:00
File Inode Change Date/Time     : 2018:04:18 08:53:42-04:00
File Permissions                : rw-r--r--
File Type                       : MOV
File Type Extension             : mov
MIME Type                       : video/quicktime
Major Brand                     : Apple QuickTime (.MOV/QT)
Minor Version                   : 0.0.0
Compatible Brands               : qt
Movie Data Size                 : 310925598
Movie Data Offset               : 36
Movie Header Version            : 0
Create Date                     : 2018:04:17 13:26:41
Modify Date                     : 2018:04:17 13:29:01
Time Scale                      : 600
Duration                        : 0:01:39
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 5
Track Header Version            : 0
Track Create Date               : 2018:04:17 13:26:41
Track Modify Date               : 2018:04:17 13:29:01
Track ID                        : 1
Track Duration                  : 0:01:39
Track Layer                     : 0
Track Volume                    : 100.00%
Balance                         : 0
Audio Format                    : mp4a
Audio Channels                  : 1
Audio Bits Per Sample           : 16
Audio Sample Rate               : 44100
Purchase File Format            : mp4a
Image Width                     : 3840
Image Height                    : 2160
Clean Aperture Dimensions       : 3840x2160
Production Aperture Dimensions  : 3840x2160
Encoded Pixels Dimensions       : 3840x2160
Graphics Mode                   : ditherCopy
Op Color                        : 32768 32768 32768
Compressor ID                   : avc1
Source Image Width              : 3840
Source Image Height             : 2160
X Resolution                    : 72
Y Resolution                    : 72
Compressor Name                 : H.264
Bit Depth                       : 24
Video Frame Rate                : 30.001
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2018:04:17 13:26:41
Media Modify Date               : 2018:04:17 13:29:01
Media Time Scale                : 600
Media Duration                  : 0:01:39
Media Language Code             : und
Gen Media Version               : 0
Gen Flags                       : 0 0 0
Gen Graphics Mode               : ditherCopy
Gen Op Color                    : 32768 32768 32768
Gen Balance                     : 0
Handler Class                   : Data Handler
Handler Vendor ID               : Apple
Handler Description             : Core Media Data Handler
Other Format                    : mebx
Handler Type                    : Metadata Tags
Make                            : Apple
Model                           : iPhone 7
Software                        : 11.4
Creation Date                   : 2018:04:16 10:01:01-04:00
Avg Bitrate                     : 25.1 Mbps
Image Size                      : 3840x2160
Megapixels                      : 8.3
Rotation                        : 0

OK, I just solved my issue. It seems that there was another corrupt video from April 9th that was causing the odd behavior. I removed that file and did another re-encode. It works now, but with a caveat.

I’m not sure what tag plex uses for timeline, but after encoding, the video was showing up 1 day off the actual time. Some of the dates in the orignal files’ metadata show this date, but the CreationDate is different. Even the file name has the 2018-04-16 date which was uploaded via plex app.

[docker photo]$ exiftool -s "2018-04-16 10.01.01.MOV" | grep -i date
FileModifyDate                  : 2018:04:18 08:53:42-04:00
FileAccessDate                  : 2018:04:18 09:31:25-04:00
FileInodeChangeDate             : 2018:04:18 08:53:42-04:00
CreateDate                      : 2018:04:17 13:26:41
ModifyDate                      : 2018:04:17 13:29:01
TrackCreateDate                 : 2018:04:17 13:26:41
TrackModifyDate                 : 2018:04:17 13:29:01
MediaCreateDate                 : 2018:04:17 13:26:41
MediaModifyDate                 : 2018:04:17 13:29:01
CreationDate                    : 2018:04:16 10:01:01-04:00

I had to run one more command, which seems to have updated the CreateDate and ModifyDate and also added DateTimeOriginal

exiftool "-AllDates<CreationDate" "2018-04-16 10.01.01.mp4"

After analyzing the file one more time, plex put it in the right place. I’ll just script all those commands and be done with it, but I still find it a bit odd that the encoded file behaves a bit differently than the original file that was uploaded with plex camera upload.