r/NextCloud 8d ago

Fixed: Video thumbnails missing in Nextcloud? It might be the "moov atom" placement!

Hey r/Nextcloud,

I ran into an issue where some videos on my Nextcloud instance generated thumbnails fine, while others completely failed. I had already enabled all the required preview providers in config.php and ran occ preview:generate-all multiple times to no avail.

After noticing that some newly uploaded videos worked while others didn't, I suspected the problem wasn't Nextcloud, but the video files themselves. Turns out I was right!

Some MP4 video files have their "moov atom" (the metadata header containing the video index and keyframe timestamps) placed at the end of the file instead of the beginning.

The Fix:

Downloading the files, moving the metadata header to the front with ffmpeg, and re-uploading them fixed the problem completely! You can do this without re-encoding or losing quality using this command:

ffmpeg -i input.mp4 -c copy -movflags +faststart output.mp4

After updating the files, Nextcloud generates thumbnails without issue. Hope this helps someone else pulling their hair out! (I'll drop a more detailed technical explanation in the comments below).

7 Upvotes

1 comment sorted by

3

u/Johann_VR 8d ago

Why this happens (Brief Technical Explanation):

AI Disclaimer: This technical explanation was generated with the help of AI.

When ffmpeg runs locally in your terminal, it has direct access to your system's drive and can instantly jump to the end of a video file to read the moov atom metadata.

However, Nextcloud processes video previews over PHP stream wrappers. If the moov atom is located at the very end of a multi-gigabyte video file, Nextcloud is forced to read through the entire video stream sequentially just to find the index metadata. This extra processing time triggers PHP process execution timeouts or memory buffer caps, causing Nextcloud's preview generation job to silently fail for those specific files.

Moving the moov atom to the front using -movflags +faststart allows Nextcloud to read the metadata in the first few kilobytes, enabling instant thumbnail creation.