Fix Synology Photos Not Playing HVEC Videos And Not Reading Taken Timestamp

If you are still running Synology DSM 6 and are looking into migrating to Synology DSM 7, and one of the main Synology apps you use is Photo Station, there are some major changes in how Synology handles photo uploading in the new Synology Photos app.

Before migrating, I had read (and watched) a lot of reviews about the changes from Synology Photo Station/Synology Moments in DSM 6 to Synology Photos in DSM 7, but nobody mentioned there is a huge difference in how photos, and especially videos, are uploaded and handled by Synology Photos.

Rather than me listing the different ways to upload photos/videos, I will leave you with the official guide: https://kb.synology.com/en-us/DSM/tutorial/How_do_I_batch_upload_photos_to_Synology_Photos

The problem is that if you choose to sync from your computer or by mapping the /photos directory and copy-paste, you are more likely to run into issues with video files and Synology Photos not reading the correct Date Taken. But rather, Synology Photos will read the date the video file was created and use that as the Date Taken to display in the Timeline view. Date taken and file creation dates can be totally different.

Synology Photos will also not play videos encoded with HVEC, also known as H.265. So if your phone is set to record video with this encoding, Synology Photos won’t play your videos.

One solution is to always use the Synology Photos mobile app to upload all your photos and videos, however, if you are like me and rather use the computer to pick and choose what to upload, or to bulk upload, you will have to do some video pre-processing before uploading to your NAS.

Fix Video Files Taken Timestamp

To fix this you will need a tool called ExifTool (https://exiftool.org/). If you inspect a video file by typing the below command you will see all the metadata for that video

 exiftool video.mp4

And highlighted below are the important pieces of info we are interested in

ExifTool Version Number         : 12.57
File Name                       : video.mp4
Directory                       : .
File Size                       : 141 MB
File Modification Date/Time     : 2023:01:10 03:39:50-06:00
File Access Date/Time           : 2023:03:14 21:28:35-05:00
File Inode Change Date/Time     : 2023:03:14 21:28:34-05:00
..... <<DELETED FOR BREVITY>>
Create Date                     : 2023:01:10 03:39:50
Modify Date                     : 2023:01:10 03:39:50
..... <<DELETED FOR BREVITY>>
Track Create Date               : 2023:01:10 03:39:50
Track Modify Date               : 2023:01:10 03:39:50
..... <<DELETED FOR BREVITY>>
Compressor ID                   : hvc1
..... <<DELETED FOR BREVITY>>

The idea is to copy the Track Create Date into the Create and Modify Date. To accomplish this, use the following command

exiftool "-FileCreateDate<TrackCreateDate" "video.mp4"
exiftool "-FileModifyDate<TrackCreateDate" "video.mp4"

By inspecting the video file again, you will see the same date timestamp as the track date.

Compressor ID hvc1 means the video file was encoded with HVEC (H.265).

Refer to the official FAQ for more detailed options: https://exiftool.org/faq.html.

Transcode HVEC (H.265) to H.264

To accomplish this you will need ffmpeg (https://ffmpeg.org/) utility. Mac users more than likely already have ffmpeg installed, however, I recommend downloading the latest version and replacing the one on the Mac. Windows users might need to download it.

Use the following command to transcode the video file

ffmpeg -i "source_video.mp4" -c:v libx264 -crf 23 -c:a aac -map_metadata 0 "output_video.mp4"

We are encoding the video with libx264, with a constant rate factor (CRF) of 23, which is the default. If you want a more visually lossless encoding, consider 17 or 18. The lower the number, the “better” the output.

Refer to the official Wiki for more detailed options: https://trac.ffmpeg.org/wiki/Encode/H.264.

Putting It All Together To Process Video Files for Synology Photos (GitHub Repo)

I have created a Bash script (sorry Windows users) to automate the taken timestamp correction and the transcoding to H.264.

Take a look at the repo on my GitHub profile: https://github.com/esausilva/process-videos-synology

The script takes in a path as the first argument where the video files that need processing are saved. Make sure to enclose the path with quotation marks.

./script.sh "/path/to/directory"

Before running the script, you might need to assign executable permissions chmod +x script.sh.

It finds all video files (mp4) in the given directory and subdirectories, modifies the timestamps, and finally transcodes to H.264.

The first step is to copy the original taken timestamp into the “created” and “modified” metadata using the exiftool tool.

The second step is to transcode video files taken with HVEC (H.265) encoding to H.264 since Synology Photos cannot play or index videos encoded with HVEC. For this step, the script uses ffmpeg tool.

To find out what video files, if any, need transcoding, the script examines the current video file with exiftool, then greps the output to find the compressor ID, if the ID is equal to hvc1, then the video file is encoded with HVEC. Finally proceeds to transcode it.

The transcoded video file will have the same name as the original file, but with _out string appended at the end and it will be created in the same directory as the original video file.

References


Consider giving back by getting me a coffee (or a couple) by clicking the following button:

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.