Repository navigation
Videos: Incorrect playback when using QSV to transcode HEVC #5040
Description
1. What is not working as documented?
I've set FFmpegEncoder: intel and FFmpegSize: 1920 for the webui to show transcoded videos, however, the transcoded videos are malformed. According to logs of level trace, everything runs smoothly. Please see the videos below, for reference. The ffmpeg commandline looks like this:
/usr/bin/ffmpeg -y -strict -2 -hwaccel qsv -hwaccel_output_format qsv -i /path/to/some/video.mp4 -c:a aac -vf scale_qsv=w='if(gte(iw,ih), min(1920, iw), -1)':h='if(gte(iw,ih), -1, min(1920, ih))':format=nv12 -c:v h264_qsv -map 0:v:0 -map 0:a:0? -r 30 -b:v 1M -bitrate 1M -f mp4 -movflags frag_keyframe+empty_moov+default_base_moof+faststart /path/to/sidecar/video.mp4.avc
orig.mp4
orig.mp4.avc.mp4
You can see that the transcoded video "keeps playing" beyond the playtime of the original video - and at some point, after ~25s the actual transcoded result starts playing.
This is independent of the UI, as the actual transcoded file is erroneous - playing it in mpv gives the same result. Note that invoking that cmdline manually does not work as there seems to be some issue with a filter chain - I don't know enough about ffmpeg to fix this invocation by myself:
ffmpeg version n7.1.1 Copyright (c) 2000-2025 the FFmpeg developers
built with gcc 15.1.1 (GCC) 20250425
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-frei0r --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libdvdnav --enable-libdvdread --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgsm --enable-libharfbuzz --enable-libiec61883 --enable-libjack --enable-libjxl --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libplacebo --enable-libpulse --enable-librav1e --enable-librsvg --enable-librubberband --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpl --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-vapoursynth --enable-version3 --enable-vulkan
libavutil 59. 39.100 / 59. 39.100
libavcodec 61. 19.101 / 61. 19.101
libavformat 61. 7.100 / 61. 7.100
libavdevice 61. 3.100 / 61. 3.100
libavfilter 10. 4.100 / 10. 4.100
libswscale 8. 3.100 / 8. 3.100
libswresample 5. 3.100 / 5. 3.100
libpostproc 58. 3.100 / 58. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/path/to/some/video.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2025-02-08T10:32:06.000000Z
com.android.version: 14
com.android.capture.fps: 60.000000
Duration: 00:00:02.62, start: 0.000000, bitrate: 42556 kb/s
Stream #0:0[0x1](eng): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, bt709), 3840x2160, 41571 kb/s, 59.64 fps, 60 tbr, 90k tbn (default)
Metadata:
creation_time : 2025-02-08T10:32:06.000000Z
handler_name : VideoHandle
vendor_id : [0][0][0][0]
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
Metadata:
creation_time : 2025-02-08T10:32:06.000000Z
handler_name : SoundHandle
vendor_id : [0][0][0][0]
[AVFilterGraph @ 0x60565cc14a80] No option name near 'if(gte(iw'
[AVFilterGraph @ 0x60565cc14a80] Error parsing a filter description around: ,ih), -1, min(1920, ih)):format=nv12
[AVFilterGraph @ 0x60565cc14a80] Error parsing filterchain 'scale_qsv=w=if(gte(iw,ih), min(1920, iw), -1):h=if(gte(iw,ih), -1, min(1920, ih)):format=nv12' around: ,ih), -1, min(1920, ih)):format=nv12
Error opening output file /path/to/sidecar/video.mp4.avc.
Switching to vaapi works fine, but is way less performant and the video quality is ... sub-par, to say the least.
6. Which software versions do you use?
(a) PhotoPrism Architecture & Build Number: 250426-27ec7a128-Linux-x86_64
(b) Database Type & Version: PostgreSQL
(c) Operating System Types & Versions: Arch Linux
(d) Browser Types & Versions: Firefox
7. On what kind of device is PhotoPrism installed?
(a) Device / Processor Type: Intel Core 5 Ultra 225T
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsRelease 🌈
Activity
lastzero commentedon Jun 1, 2025
Are you sure this is a problem with our software, rather than eg FFmpeg or Intel QSV? If so, how else should the FFmpeg command flags look like to fix it?
lastzero commentedon Jun 1, 2025
I suggest you update to our latest release or try the development preview as that may solve your issue.
shtrophic commentedon Jun 1, 2025
It seems to work when I omit the
-r 30in the ffmpeg cmdline. Also, the whole argumentscale_qsv=...nv12needs to be enclosed in "double quotes" for it to run in a shell.Well, the way photoprism calls ffmpeg with QSV does not produce the desireable result.
I am already on that release - correct me if I'm wrong?
lastzero commentedon Jun 1, 2025
It looks like your are not using our latest release?
shtrophic commentedon Jun 2, 2025
I upgraded to the development release and the issue still persists. Without changing settings, the ffmpeg commandline is mostly the same anyway:
Why do you require the output framerate to be fixed at 30 anyway? Couldn't this be made configurable, say, with something like
FFmpegForceFramerate: true/false?Videos: Improve downloading, remuxing, and transcoding #4982 #4892 #5040
lastzero commentedon Jun 9, 2025
@shtrophic The above changes remove the fixed frame rate and update the list of mov flags. You can test them using our updated development preview image:
Note that since you are using PostgreSQL, your build may be based on outdated code or dependencies. If the preview build works, you will need to update your custom build to use the same/latest code and dependencies.
[-]QSV Transcoding: elongated videos with still image for multiple seconds at beginning[/-][+]Videos: Incorrect playback when using QSV to transcode HEVC[/+]shtrophic commentedon Jun 10, 2025
I've built 2e2ebab and it seems to work properly now. Many thanks for your responsiveness!!
M2TS: Extract embedded metadata with ExifTool #4982 #4892 #5040
M2TS: Improve inline code docs #4982 #4892 #5040
Videos: Extract embedded metadata with ExifTool #4982 #4892 #5040