Skip to content

Videos: Incorrect playback when using QSV to transcode HEVC #5040

Closed

Description

@shtrophic

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

Activity

  1. lastzero commented on Jun 1, 2025

    @lastzero
    Member

    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?

  2. lastzero commented on Jun 1, 2025

    @lastzero
    Member

    I suggest you update to our latest release or try the development preview as that may solve your issue.

  3. shtrophic commented on Jun 1, 2025

    @shtrophic
    Author

    It seems to work when I omit the -r 30 in the ffmpeg cmdline. Also, the whole argument scale_qsv=...nv12 needs to be enclosed in "double quotes" for it to run in a shell.

    Are you sure this is a problem with our software, rather than eg FFmpeg or Intel QSV?

    Well, the way photoprism calls ffmpeg with QSV does not produce the desireable result.

    I suggest you update to our latest release

    I am already on that release - correct me if I'm wrong?

  4. lastzero commented on Jun 1, 2025

    @lastzero
    Member

    It looks like your are not using our latest release?

  5. shtrophic commented on Jun 2, 2025

    @shtrophic
    Author

    I upgraded to the development release and the issue still persists. Without changing settings, the ffmpeg commandline is mostly the same anyway:

    /usr/bin/ffmpeg -hide_banner -y -strict -2 -hwaccel qsv -hwaccel_output_format qsv -i input.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? -preset fast -r 30 -global_quality 25 -f mp4 -movflags frag_keyframe+empty_moov+default_base_moof+faststart input.mp4.avc
    

    It seems to work when I omit the -r 30 in the ffmpeg cmdline. Also, the whole argument scale_qsv=...nv12 needs to be enclosed in "double quotes" for it to run in a shell.

    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?

  6. added theissue type on Jun 9, 2025
  7. moved this to Preview 🐳 in Roadmap 🚀✨on Jun 9, 2025
  8. lastzero commented on Jun 9, 2025

    @lastzero
    Member

    @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.

  9. changed the title [-]QSV Transcoding: elongated videos with still image for multiple seconds at beginning[/-] [+]Videos: Incorrect playback when using QSV to transcode HEVC[/+] on Jun 9, 2025
  10. shtrophic commented on Jun 10, 2025

    @shtrophic
    Author

    I've built 2e2ebab and it seems to work properly now. Many thanks for your responsiveness!!

  11. added
    videoVideo Formats, Transcoding, FFmpeg, Streaming & Co
    on Jun 11, 2025
  12. added
    testedChanges have been tested successfully
    and removed
    please-testReady for manual testing & feedback
    on Jul 2, 2025
  13. moved this from Preview 🐳 to Release 🌈 in Roadmap 🚀✨on Jul 7, 2025
  14. moved this from Release 🌈 to Development 🐝 in Roadmap 🚀✨on Jul 7, 2025
  15. moved this from Development 🐝 to Release 🌈 in Roadmap 🚀✨on Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

testedChanges have been tested successfullyvideoVideo Formats, Transcoding, FFmpeg, Streaming & Co

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions