Nextcloud Video Preview / Thumbnail: How to Generate?

Please Subscribe to our YouTube Channel

nextcloud view preview

Nextcloud is one of the popular Cloud Storage that comes with a free Community Edition. You can save your photos, videos, documents, and almost everything. It even comes with the option to chat and work on a single document with the team. However, many people use it to back up their photos and videos only.

If you have installed NextCloud on your Linux server and you don’t see the preview for your Video Files, it’s normal. There are many posts on the Nextcloud forum and Reddit where you will find users discussing why this happens. Here is the step by step guide what you need to do.

Install FFMPEG if not already installed

sudo apt update
sudo apt upgrade
sudo apt install ffmpeg

Install Imagemagick and its PHP extension if it is not installed

sudo apt install imagemagick
sudo apt install php-imagick

Restart PHP

sudo systemctl restart php-fpm

Then Restart Ngnix or Apache depending on which webserver you use.

sudo systemctl restart nginx
sudo systemctl restart apache2

Set proper ownership and folder permission. Replace www-data with the same user that run the website files.

sudo chown -R www-data:www-data /var/www/nextcloud
sudo find /var/www/nextcloud -type d -exec chmod 755 {} \;
sudo find /var/www/nextcloud -type f -exec chmod 644 {} \;

If you have data folder outside the Nextcloud folder fix the permission as well.

sudo chown -R www-data:www-data /path/to/data
sudo find /path/to/data -type d -exec chmod 755 {} \;
sudo find /path/to/data -type f -exec chmod 644 {} \;

Install the Preview Generator app in next cloud

You can install the app opening your Nextcloud dashboard –> Clicking on your profile pic —> Clicking apps –> Selecting Multimedia –> Preview Generator or you can run this command to install and enable. Adjust the path and user if needed

cd /var/www/nextcloud
sudo -u www-data php occ app:install previewgenerator
sudo -u www-data php occ app:enable previewgenerator

Enabling Previews (if you nextcloud directory is located somewhere else, make sure you change it. You must be in the directory to run the enabledPreviewProviders command.

cd /var/www/nextcloud
sudo -u www-data php occ config:system:get enabledPreviewProviders

Now navigate to your NextCloud folder or use sudo nano command to edit config.php file which is located inside the nextcloud folder –> config folder and check the configuration. Make sure it has the preview section added. If not add these (adjust ffmpeg path if needed).

  'enable_previews' => true,
  'enabledPreviewProviders' => 
  array (
    0 => 'OC\\Preview\\Image',
    1 => 'OC\\Preview\\Movie',
    2 => 'OC\\Preview\\TXT',
    3 => 'OC\\Preview\\PDF',
    4 => 'OC\\Preview\\MP4',
    5 => 'OC\\Preview\\AVI',
    6 => 'OC\\Preview\\MOV',
    7 => 'OC\\Preview\\HEIC',
    8 => 'OC\\Preview\\HEIF',
    9 => 'OC\\Preview\\JPEG',
    10 => 'OC\\Preview\\PNG',
    11 => 'OC\\Preview\\GIF',
  ),
  'preview_max_x' => 1024,
  'preview_max_y' => 1024,
  'preview_max_scale_factor' => 1,
  'ffmpeg' => '/usr/bin/ffmpeg',

Save the config and restart your PHP

sudo systemctl restart php-fpm

Clear the preview (Make sure you are in the Nextcloud folder. If not, run cd /var/www/nextcloud ), but adjust the path if needed

sudo -u www-data php occ preview:pre-generate

Regenrare all previews

sudo -u www-data php occ preview:generate-all -vvv

Restart your Webserver (Ngnix/Apache) and Restart PHP.

Add a cron job to run the Preview Generation Command Periodically

sudo -u www-data crontab -e

Add this line that will run every 1 hour. (Adjust for longer duration if you rarely upload)

0 */1 * * * php /var/www/nextcloud/occ preview:pre-generate

Then press ctrl+o, press Enter to save, exit with ctrl+x

What if the Thumbnail or Video Preview stops generating for new Videos you upload or Doesn’t generate of Mobile’s NextCloud App?

NextCloud is quite annoying when it comes to generating Thumbnails for Videos. After doing all those it worked, but when I uploaded new videos and waited for the next cron job to run (you need to wait for that), it generated thumbnails and showed up on my Desktop’s Chrome. But, my iOS NextCloud app fails to do the same.

If you encounter the same issue, you need to run the Clearing The Preview command and then the Regenerate All Previews command again which is mentioned above. (At least that’s how I fixed it).