NextCloudで動画のサムネイル表示対応

Table of Contents

NextCloudで動画のサムネイル表示対応
インストールの前提条件は、EPELがインストール済み

PowerToolsリポジトリを有効にする

# dnf config-manager --set-enabled powertools

RPM Fusionのリポジトリをインストール

# dnf install https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm

ffmpegをインストールする

自分の環境で追加が必要だったRPMも一緒にインストール

# dnf install ffmpeg ImageMagick ghostscript libva libmfx libdrm

# ffmpeg
ffmpeg version 4.2.8 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 8 (GCC)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsrt --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

ImageMagickのポリシーファイルを変更してPDFからjpgの生成を有効化

# cd /etc/ImageMagick-6/
# cp policy.xml policy.xml.org
# vi policy.xml
  <!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
  ↓
  <!-- <policy domain="module" rights="read|write" pattern="{PS,PDF,XPS}" /> -->

Preview Generatorをインストールする

NextCloud 上からアプリ追加画面で「Preview Generator」と検索してブラウザ上からインストールして有効化する

config.phpに追記

  'preview_max_x' => 1024,
  'preview_max_y' => 1024,
  'jpeg_quality' => '60',
  'preview_max_scale_factor' => 1,
  'enable_previews' => true,
  'enabledPreviewProviders' =>
  array (
    0 => 'OC\\Preview\\Movie',
    1 => 'OC\\Preview\\PNG',
    2 => 'OC\\Preview\\JPEG',
    3 => 'OC\\Preview\\GIF',
    4 => 'OC\\Preview\\BMP',
    5 => 'OC\\Preview\\XBitmap',
    6 => 'OC\\Preview\\MP3',
    7 => 'OC\\Preview\\MP4',
    8 => 'OC\\Preview\\MKV',
    9 => 'OC\\Preview\\AVI',
    10 => 'OC\\Preview\\TXT',
    11 => 'OC\\Preview\\MarkDown',
    12 => 'OC\\Preview\\PDF',
  ),
  • preview_max_x‘ => 1024
    preview_max_y‘ => 1024
    サムネイルサイズの横方向と縦方向何れかに最大 1024 ピクセルまでのサムネイルに指定
  • jpeg_quality‘ => ’60’
    jpgのサムネイルを60%の画質で生成する
  • preview_max_scale_factor‘ => 1
    サムネイルのスケーリングを無効化

サービスの再起動

# systemctl restart httpd

Preview Generator の使い方

  • preview:generate-all [user-id]
     全てのファイルのサムネイルを生成する。user-id の指定があった場合はそのユーザーのサムネイルだけ生成する。
     例) sudo -u apache php /opt/nextcloud/occ preview:generate-all -vvv

  • preview:pre-generate
     前回生成以降の新しいファイルや変更されたファイルのサムネイルだけを生成する。
     これは単体実行するというよりも cron で 10 分置きなどの定期実行をさせて使う。

定期的にサムネイルを生成させる

$ sudo crontab -u apache -e
*/10 * * * * /usr/bin/php -f /opt/nextcloud/occ preview:pre-generate

サムネイルの再作成

サムネイルディレクトリの削除後に全てのファイルのサムネイルの生成する。

# cd /data/appdata_xxxxxxxx/
# rm -Rf preview
$ sudo -u apache  php /opt/nextcloud/occ preview:generate-all -vvv

参考URL

Install FFmpeg on CentOS 8 with RPMFusion repo ← RootLinks Co., Ltd.
NextCloud の Gallery で使われるサムネイルを一括生成したり自動生成させる – ぶっちろぐ
続けるブログ: Nextcloudで動画のサムネイルを表示させる
Install Preview Generator in Nextcloud – ServerOK
ImageMagickでPDF変換失敗と対応|サカ之シタ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です