The Goal
convert several 1080 h.265 (hevc) HDR (yuv420p10le) iPhone recorded video files to h.264 (avc) SDR to share with older devices using nextcloud
Solution #1 Software encoding
Nextcloud → Personal Settings → Media Conversion
DJI OsmoAction5 Pro h.265/4K/50FPS/10bitSDR → h.264/1080/25FPS/10bitSDR
-movflags +faststart -movflags use_metadata_tags -map_metadata 0 -c:a copy -vf scale=-1:1080,fps=25 -vcodec libx264 -preset VerySlow -strict -2
+ CROP (before resize)
important to have an even number in cropped size
-movflags +faststart -movflags use_metadata_tags -map_metadata 0 -c:a copy -vf "crop=w=3360:h=1890:x=320:y=184,scale=-1:1080,fps=25" -vcodec libx264 -preset VerySlow -strict -2
Software convert h.265 HDR to h.265 HDR
tbd
Software convert h.264 SDR to h.265 SDR
Additional ffmpeg flags (output file options )
# -movflags use_metadata_tags -map_metadata 0 -c:a copy -vcodec libx265 -preset VerySlow -movflags +faststart -movflags use_metadata_tags -map_metadata 0 -c:a copy -vcodec libx265 -preset veryslow -strict -2
Software convert h.265 HDR to h.264 SDR (without resize)
Additional ffmpeg flags (output file options )
-movflags +faststart -movflags use_metadata_tags -map_metadata 0 -vf zscale=t=linear:npl=550,format=gbrpf32le,tonemap=tonemap=mobius:desat=0,zscale=p=bt709:t=bt709:m=bt709:r=tv,format=yuv420p -vcodec libx264 -preset VerySlow -strict -2
Software convert h.265/4K/SDR to h.264/1080/SDR (no color processing)
Additional ffmpeg flags (output file options )
-movflags +faststart -movflags use_metadata_tags -map_metadata 0 -c:a copy -vf scale=-1:1080 -vcodec libx264 -preset VerySlow
Software convert h.265/4K/HDR to h.264/1080/SDR (both resize and color processing)
Additional ffmpeg flags (output file options )
-movflags +faststart -movflags use_metadata_tags -map_metadata 0 -vf zscale=t=linear:npl=550,format=gbrpf32le,tonemap=tonemap=mobius:desat=0,zscale=p=bt709:t=bt709:m=bt709:r=tv,format=yuv420p -vf scale=-1:1080 -vcodec libx264 -preset Fast -strict -2
root@server3:~# ps -ef |grep ffmpeg www-data 429600 429599 99 15:35 ? 01:08:50 ffmpeg -threads 8 -i /tmp/oc_tmp_MXIx5O-.MOV -movflags use_metadata_tags -map_metadata 0 -vf zscale=t=linear:npl=550,format=gbrpf32le,tonemap=tonemap=mobius:desat=0,zscale=p=bt709:t=bt709:m=bt709:r=tv,format=yuv420p -vcodec libx264 -preset VerySlow -strict -2 /tmp/oc_tmp_KzK7Z7-.mp4 www-data 430706 430705 99 15:40 ? 00:24:40 ffmpeg -threads 8 -i /tmp/oc_tmp_KzK7Z7-.MOV -movflags use_metadata_tags -map_metadata 0 -vf zscale=t=linear:npl=550,format=gbrpf32le,tonemap=tonemap=mobius:desat=0,zscale=p=bt709:t=bt709:m=bt709:r=tv,format=yuv420p -vcodec libx264 -preset VerySlow -strict -2 /tmp/oc_tmp_KzK7Z7-.mp4
queue will start execution after next cron run (in about 5 minutes)
Solution #2 Intel hardware encoding
Since 1.10.3
Intel hardware conver h.265 HDR to h.264 SDR
Input file options (ffmpeg 5)
-init_hw_device qsv
Output file options (ffmpeg 5)
-movflags +faststart -movflags use_metadata_tags -map_metadata 0 -c:a copy -c:v h264_qsv -profile:v high -global_quality 24 -level 41 -sn -filter_complex format=nv12
input options (draft ffmpeg 6)
-c:v hevc -y
output options (draft ffmpeg 6)
-movflags +faststart -movflags use_metadata_tags -map_metadata 0 -c:a copy -c:v h264_qsv -profile:v high -global_quality 24 -level 41 -sn -filter_complex format=nv12
use vaapi
input options
-y -init_hw_device vaapi=va:/dev/dri/renderD128 -filter_hw_device va -hwaccel vaapi -hwaccel_output_format vaapi
output options
-map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_vaapi -rc_mode VBR -b:v 4000000 -maxrate 5000000 -bufsize 28542590 -vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,scale_vaapi=format=nv12:extra_hw_frames=24" -codec:a:0 copy
Workarounds for workflow_media_converter 1.9.3
Workaround for Select Folder button that is not work
in Nextcloud 28.0.2 (docker) + Automated media conversion 1.9.3
cp -R custom_apps/workflow_media_converter apps/workflow_media_converter chown www-data:www-data -R apps/workflow_media_converter
Fix options issues
in Nextcloud 28.0.2 (docker) + Automated media conversion 1.9.3
https://github.com/cwilby/nextcloud-workflow-media-converter/issues/413
/var/www/nextcloud/apps/workflow_media_converter/lib/BackgroundJobs/ConvertMediaJob.php
-$command = "ffmpeg -threads $threads {$additionalConversionFlags} -i {$this->tempSourcePath} {$this->tempOutputPath}" +$command = "ffmpeg -threads $threads -i {$this->tempSourcePath} {$additionalConversionFlags} {$this->tempOutputPath}"
Workaround for FFmpeg output options is not needed anymore in 1.10.3 (it is now an Output file option)
Workarounds for workflow_media_converter 1.10.3
The Workaround of Choose Folder button does not work
cp -R custom_apps/workflow_media_converter apps/workflow_media_converter chown www-data:www-data -R apps/workflow_media_converter cp /var/www/html/apps/workflow_media_converter/js/*.js /var/www/html/apps/workflow_media_converter/
for this HW acceleration needs to be enabled first see video encoding HW acceleration for nextcloud in docker
Workarounds for FFmpeg 6
#1 Downgrade (and use old options)
Errors examples
use FFmpeg 4/5 QSV options with FFmpeg 6 cause errors like
[AVHWDeviceContext @ 0x55ecb03e8e40] VAAPI driver: Intel iHD driver for Intel(R) Gen Graphics - 23.1.1 (). [AVHWDeviceContext @ 0x55ecb03e8e40] Driver not found in known nonstandard list, using standard behaviour. [AVHWDeviceContext @ 0x55ecb03e8940] Use Intel(R) oneVPL to create MFX session, API version is 2.9, the required implementation version is 1.3 [AVHWDeviceContext @ 0x55ecb03e8940] Error creating a MFX session: -9. Device creation failed: -1313558101. Failed to set value '/dev/dri/renderD128' for option 'qsv_device': Unknown error occurred Error parsing global options: Unknown error occurred
ffmpeg version downgrade
#fix for ffmpeg6 incopatibility with qsv by rollback to ffmpeg 5 apt remove ffmpeg apt install ffmpeg=7:5.1.4-0+deb12u1
[AVHWDeviceContext @ 0x55e6b3aff000] VAAPI driver: Intel iHD driver for Intel(R) Gen Graphics - 23.1.1 (). [AVHWDeviceContext @ 0x55e6b3aff000] Driver not found in known nonstandard list, using standard behaviour. [AVHWDeviceContext @ 0x55e6b3afeb00] Initialize MFX session: API version is 1.35, implementation version is 1.35 Applying option filter_complex (create a complex filtergraph) with argument format=nv12. Successfully parsed a group of options. Parsing a group of options: input url /tmp/oc_tmp_rD1ii2-.MOV. Successfully parsed a group of options. Opening an input file: /tmp/oc_tmp_rD1ii2-.MOV.
#2 Find out new options that work with FFmpeg 6
TBD