Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Intel QSV hardware transcode fail #2626

Closed
frankyifei opened this issue Mar 18, 2020 · 72 comments
Closed

Windows Intel QSV hardware transcode fail #2626

frankyifei opened this issue Mar 18, 2020 · 72 comments
Labels
bug Something isn't working stale Stale and will be closed if no activity occurs

Comments

@frankyifei
Copy link

frankyifei commented Mar 18, 2020

Describe the bug

The transcode failed with the error in log. [AVHWDeviceContext @ 000001a1363ace00] Error initializing an MFX session: -3. Error creating a QSV device
It is strange that when I ran the same command in console there is no such error.
System (please complete the following information):

  • OS: windows 10
  • Virtualization: no
  • Clients: Android TV
  • Browser: [e.g. Firefox 72, Chrome 80, Safari 13]
  • Jellyfin Version: 15.01 nightly
  • Playback: Transcode
  • Installed Plugins: none
  • Reverse Proxy: none
  • Base URL:
  • Networking:
  • Storage:

To Reproduce

anything requires transcode, if I disable hardware transcode, it works

Logs

C:\Jellyfin\Server\ffmpeg.exe -c:v h264_qsv  -hwaccel qsv -c:v h264_qsv  -i file:"C:\Movies\BJ单身日记 (2001)\BJ单身日记 (2001) h264-1080p DTS-6ch.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset 7 -look_ahead 0 -b:v 12879509 -maxrate 12879509 -bufsize 25759018 -profile:v high -level 4.1 -copyts -vf "scale_qsv=format=nv12,subtitles=filename='C\:/Movies/BJ单身日记 (2001)/BJ单身日记 (2001) h264-1080p DTS-6ch.ass'" -vsync -1 -codec:a:0 libmp3lame -ac 2 -ab 384000 -af "volume=2" -f hls -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -hls_time 3 -individual_header_trailer 0 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "C:\Users\N\AppData\Local\Jellyfin\transcodes\b707e42ef3f511a2f610c800304cdff2%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "C:\Users\N\AppData\Local\Jellyfin\transcodes\b707e42ef3f511a2f610c800304cdff2.m3u8"


ffmpeg version N-95234-g35a63a9127 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.0 (Rev2, Built by MSYS2 project)
  configuration:  --disable-static --enable-shared --enable-amf --enable-bzlib --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-zlib --enable-sdl2 --enable-ffnvcodec --enable-nvdec --enable-gmp --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libdav1d --disable-debug --enable-fontconfig --enable-libass --enable-libbluray --enable-libfreetype --enable-libmfx --enable-libmysofa --enable-libopencore-amrnb --enable-libopenjpeg --enable-libsnappy --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwavpack --enable-libwebp --enable-libxml2 --enable-libzimg --enable-libshine --enable-gpl --enable-libxvid --enable-libopenmpt --enable-version3 --enable-libsvtav1 --enable-librtmp --enable-gnutls --extra-cflags=-DLIBTWOLAME_STATIC --extra-libs=-lstdc++ --extra-cflags=-DLIBXML_STATIC --shlibdir=/local64/bin-video
  libavutil      56. 35.100 / 56. 35.100
  libavcodec     58. 59.101 / 58. 59.101
  libavformat    58. 33.100 / 58. 33.100
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 62.100 /  7. 62.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, matroska,webm, from 'file:E:\Movies\BJ单身日记 (2001)\BJ单身日记 (2001) h264-1080p DTS-6ch.mkv':
  Metadata:
    encoder         : libebml v0.7.7 + libmatroska v0.8.1
    creation_time   : 2012-07-06T02:23:42.000000Z
  Duration: 01:36:59.79, start: 0.000000, bitrate: 12879 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1920x816, SAR 1:1 DAR 40:17, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
    Metadata:
      title           : 英语
Only '-vf scale_qsv=format=nv12,subtitles=filename='C\:/Movies/BJ单身日记 (2001)/BJ单身日记 (2001) h264-1080p DTS-6ch.ass'' read, ignoring remaining -vf options: Use ',' to separate filters
Only '-af volume=2' read, ignoring remaining -af options: Use ',' to separate filters
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (h264_qsv) -> h264 (h264_qsv))
  Stream #0:1 -> #0:1 (dts (dca) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[AVHWDeviceContext @ 0000012a3fed5d00] Error initializing an MFX session: -3.
Error creating a QSV device
qsv hwaccel requested for input stream #0:0, but cannot be initialized.
[h264_qsv @ 0000012a3fd3a840] Error initializing the MFX video decoder: invalid handle (-6)
Error while decoding stream #0:0: Invalid argument
[AVHWDeviceContext @ 0000012a3f8b80c0] Error initializing an MFX session: -3.
Error creating a QSV device
qsv hwaccel requested for input stream #0:0, but cannot be initialized.

Another logs shows:

C:\Jellyfin\Server\ffmpeg.exe -init_hw_device qsv=hw -filter_hw_device hw  -i file:"C:\Movies\BJ单身日记 (2001)\BJ单身日记 (2001) h264-1080p DTS-6ch.mkv" -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_qsv -force_key_frames "expr:gte(t,n_forced*5)" -vf "format=nv12|qsv,hwupload=extra_hw_frames=64,scale_qsv=format=nv12" -copyts -avoid_negative_ts disabled -start_at_zero -preset 7 -look_ahead 0 -b:v 12879509 -maxrate 12879509 -bufsize 25759018 -profile:v high -level 4.1 -vsync -1 -map_metadata -1 -map_chapters -1 -threads 0 -codec:a:0 aac -strict experimental -ac 2 -ab 192000 -af "volume=2" -y "C:\Users\NAS\AppData\Local\Jellyfin\transcodes\b8c1ee80cda71c0bf58dd4c149528a1f.mkv"


ffmpeg version N-95234-g35a63a9127 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.0 (Rev2, Built by MSYS2 project)
  configuration:  --disable-static --enable-shared --enable-amf --enable-bzlib --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-zlib --enable-sdl2 --enable-ffnvcodec --enable-nvdec --enable-gmp --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libdav1d --disable-debug --enable-fontconfig --enable-libass --enable-libbluray --enable-libfreetype --enable-libmfx --enable-libmysofa --enable-libopencore-amrnb --enable-libopenjpeg --enable-libsnappy --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwavpack --enable-libwebp --enable-libxml2 --enable-libzimg --enable-libshine --enable-gpl --enable-libxvid --enable-libopenmpt --enable-version3 --enable-libsvtav1 --enable-librtmp --enable-gnutls --extra-cflags=-DLIBTWOLAME_STATIC --extra-libs=-lstdc++ --extra-cflags=-DLIBXML_STATIC --shlibdir=/local64/bin-video
  libavutil      56. 35.100 / 56. 35.100
  libavcodec     58. 59.101 / 58. 59.101
  libavformat    58. 33.100 / 58. 33.100
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 62.100 /  7. 62.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
[AVHWDeviceContext @ 00000245b26f4000] Error initializing an MFX session: -3.
Device creation failed: -1313558101.
Failed to set value 'qsv=hw' for option 'init_hw_device': Unknown error occurred
Error parsing global options: Unknown error occurred

Seems similar to this problem
https://trac.ffmpeg.org/ticket/8379

@frankyifei frankyifei added the bug Something isn't working label Mar 18, 2020
@frankyifei frankyifei changed the title Windows Intel QSV hardware transcode fail but same ffmpeg command works in console Windows Intel QSV hardware transcode fail Mar 18, 2020
@nyanmisaka
Copy link
Member

Are you using a headless system? Is your graphics card driver up to date?

@frankyifei
Copy link
Author

Are you using a headless system? Is your graphics card driver up to date?

No, I'm using windows 10 and all drivers up to date.

@frankyifei
Copy link
Author

frankyifei commented Mar 18, 2020

Test command line in windows console, I found the current FFMpeg does not support scale_qsv
the original command line jellyfin use is

ffmpeg.exe -c:v h264_qsv  -hwaccel qsv -c:v h264_qsv  -i file:"c:\1.mkv" -map 0:0 -map 0:1 -codec:v:0 h264_qsv -force_key_frames "expr:gte(t,n_forced*5)" -copyts -vf "scale_qsv=format=nv12,subtitles=filename='c:\1.ass'" -avoid_negative_ts disabled -start_at_zero -preset 7 -look_ahead 0 -b:v 12879509 -maxrate 12879509 -bufsize 25759018 -profile:v high -level 4.1 -vsync -1 -map_metadata -1 -map_chapters -1 -threads 0 -codec:a:0 aac -strict experimental -ac 2 -ab 192000 -af "volume=2" -y "tmp.mkv"

run this command will give an error

Impossible to convert between the formats supported by the filter 'Parsed_scale_qsv_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream

I then change the scale_qsv in first command into vpp_qsv and the hardware accelerated encoding works

The code responsible for this behaviour is here:
https://github.com/jellyfin/jellyfin/blob/release-10.5.z/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs#L1727

@nyanmisaka
Copy link
Member

This is due to some problems about the qsv encoder in the ffmpeg command line, which needs improvement. I will look into it when I have time. Similar problems have been solved on VAAPI.

@Sp4rky001
Copy link

This is due to some problems about the qsv encoder in the ffmpeg command line, which needs improvement. I will look into it when I have time. Similar problems have been solved on VAAPI.

@nyanmisaka
Hello, I posted a solution to this on the Jellyfin Reddit: Burn-in Subtitle with Intel Quick Sync (QSV), found a solution.

The problem is that subtitles is a software filter so it is necessary to download the frame from the video card to the system, overlay the subtitles, then upload to video card again. I've been trying to get a dev's eyes on my solution so I'm hoping my reply here will do just that.

@nyanmisaka
Copy link
Member

@nyanmisaka
Hello, I posted a solution to this on the Jellyfin Reddit: Burn-in Subtitle with Intel Quick Sync (QSV), found a solution.

The problem is that subtitles is a software filter so it is necessary to download the frame from the video card to the system, overlay the subtitles, then upload to video card again. I've been trying to get a dev's eyes on my solution so I'm hoping my reply here will do just that.

Thanks for your suggestion. I know it can be solved in this way, and before that I want to try to find if there are other more efficient solutions.

@frankyifei
Copy link
Author

I modified MediaBrowser.Controller now that jellyfin use vpp_qsv instead of scale_qsv. This command line works if you type it in windows console but jellyfin does not work. It still says error.

@frankyifei
Copy link
Author

frankyifei commented Mar 18, 2020

This is hardware decode and encode command:

D:\Jellyfin\Server\ffmpeg.exe -c:v h264_qsv  -hwaccel qsv -c:v h264_qsv  -i file:"E:\Movies\寄生虫 (2019)\寄生虫 (2019) 1080p AAC.mp4" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset 7 -look_ahead 0 -b:v 5121682 -maxrate 5121682 -bufsize 10243364 -profile:v high -level 4.1 -copyts -vf "`**~~scale_qsv~~ vpp_qsv** `=format=nv12,subtitles=filename='E\:/Movies/寄生虫 (2019)/寄生虫 (2019) 1080p AAC.ass'" -vsync -1 -codec:a:0 libmp3lame -ac 2 -ab 320000  -f hls -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -hls_time 3 -individual_header_trailer 0 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "C:\Users\NAS\AppData\Local\Jellyfin\transcodes\transcodes\0b64d2dc55dc732212b189c52b8cc99e%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "C:\Users\NAS\AppData\Local\Jellyfin\transcodes\transcodes\0b64d2dc55dc732212b189c52b8cc99e.m3u8"

Error in Logs:

[AVHWDeviceContext @ 000002540147ee80] Error initializing an MFX session: -3.
Error creating a QSV device
qsv hwaccel requested for input stream #0:0, but cannot be initialized.
[h264_qsv @ 000002547f6b5040] Error initializing the MFX video decoder: invalid handle (-6)
Error while decoding stream #0:0: Invalid argument

This is software decode and hardware encode command:

D:\Jellyfin\Server\ffmpeg.exe -init_hw_device qsv=hw -filter_hw_device hw  -i file:"E:\Movies\寄生虫 (2019)\寄生虫 (2019) 1080p AAC.mp4" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset 7 -look_ahead 0 -b:v 5121682 -maxrate 5121682 -bufsize 10243364 -profile:v high -level 4.1 -copyts -vf "format=nv12|qsv`,~~_**hwupload=extra_hw_frames=64,**_~~ `vpp_qsv=format=nv12,subtitles=filename='E\:/Movies/寄生虫 (2019)/寄生虫 (2019) 1080p AAC.ass'" -vsync -1 -codec:a:0 libmp3lame -ac 2 -ab 320000  -f hls -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -hls_time 3 -individual_header_trailer 0 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "C:\Users\NAS\AppData\Local\Jellyfin\transcodes\transcodes\1a8f22b2e3b9e7a33a0d6575f90e3620%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "C:\Users\NAS\AppData\Local\Jellyfin\transcodes\transcodes\1a8f22b2e3b9e7a33a0d6575f90e3620.m3u8"

Error in Logs:

[AVHWDeviceContext @ 00000254d40242c0] Error initializing an MFX session: -3.
Device creation failed: -1313558101.
Failed to set value 'qsv=hw' for option 'init_hw_device': Unknown error occurred
Error parsing global options: Unknown error occurred

Both works in console and not in Jellyfin. I wonder there is something missing here. The bold text is where I modify the command. Because I modified EncodingHelper.cs, I thought the same command should also work in Jellyfin. But it does not work.

@frankyifei
Copy link
Author

This is due to some problems about the qsv encoder in the ffmpeg command line, which needs improvement. I will look into it when I have time. Similar problems have been solved on VAAPI.

@nyanmisaka
Hello, I posted a solution to this on the Jellyfin Reddit: Burn-in Subtitle with Intel Quick Sync (QSV), found a solution.

The problem is that subtitles is a software filter so it is necessary to download the frame from the video card to the system, overlay the subtitles, then upload to video card again. I've been trying to get a dev's eyes on my solution so I'm hoping my reply here will do just that.

I think it is a different problem here. With the two command lines, Subtitles work perfectly but only if you type in console. Why are there different outcomes?

@nyanmisaka
Copy link
Member

nyanmisaka commented Mar 18, 2020

On my HD630 iGPU notebook, these commands works fine on both console and JF. Do you have other discrete graphics cards installed on your computer? It may be that the conflict between drivers prevents ffmpeg from using iGPU. You can force ffmpeg.exe to use iGPU in the graphics settings of Windows 10 settings. If that doesn't work, you can try to use DDU to clean up all graphics card drivers, then download and install the latest one here.

@frankyifei
Copy link
Author

frankyifei commented Mar 18, 2020

I only have HD600 on my NAS. The commands works for me now.
After my modification to the commands, it now works great. I don't really understand ffmpeg but somehow it works now. Can anyone check if this is correct or make a better patch? I only changed several lines in EncodingHelper.cs to make the commands work.
The diff

@@ -1714,29 +1714,29 @@ namespace MediaBrowser.Controller.MediaEncoding
                 // Given the input dimensions (inputWidth, inputHeight), determine the output dimensions
                 // (outputWidth, outputHeight). The user may request precise output dimensions or maximum
                 // output dimensions. Output dimensions are guaranteed to be even.
                 var outputWidth = width.Value;
                 var outputHeight = height.Value;
-                var vaapi_or_qsv = string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) ? "qsv" : "vaapi";
+                var vaapi_or_qsv = string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) ? "vpp_qsv" : "scale_vaapi";
 
                 if (!videoWidth.HasValue
                     || outputWidth != videoWidth.Value
                     || !videoHeight.HasValue
                     || outputHeight != videoHeight.Value)
                 {
                     // Force nv12 pixel format to enable 10-bit to 8-bit colour conversion.
                     filters.Add(
                         string.Format(
                             CultureInfo.InvariantCulture,
-                            "scale_{0}=w={1}:h={2}:format=nv12",
+                            "{0}=w={1}:h={2}:format=nv12",
                             vaapi_or_qsv,
                             outputWidth,
                             outputHeight));
                 }
                 else
                 {
-                    filters.Add(string.Format(CultureInfo.InvariantCulture, "scale_{0}=format=nv12", vaapi_or_qsv));
+                    filters.Add(string.Format(CultureInfo.InvariantCulture, "{0}=format=nv12", vaapi_or_qsv));
                 }
             }
             else if ((videoDecoder ?? string.Empty).IndexOf("_cuvid", StringComparison.OrdinalIgnoreCase) != -1
                 && width.HasValue
                 && height.HasValue)
@@ -1982,11 +1982,11 @@ namespace MediaBrowser.Controller.MediaEncoding
             // If we are software decoding, and hardware encoding
             if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase)
                 && (string.IsNullOrEmpty(videoDecoder) || !videoDecoder.Contains("qsv", StringComparison.OrdinalIgnoreCase)))
             {
                 filters.Add("format=nv12|qsv");
-                filters.Add("hwupload=extra_hw_frames=64");
+                //filters.Add("hwupload=extra_hw_frames=64");
             }
 
             if (state.DeInterlace("h264", true))
             {
                 if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))

@Sp4rky001
Copy link

I'm so happy seeing all this work on the problem that's been plaguing me for weeks now, starting with Plex (its clients can't play videos for sh!t, if it's not audio not playing, it's transcoding crashing plex itself).

@frankyifei
Copy link
Author

I'm so happy seeing all this work on the problem that's been plaguing me for weeks now, starting with Plex (its clients can't play videos for sh!t, if it's not audio not playing, it's transcoding crashing plex itself).

I also found a problem related to this one. The QSV transcode cannot work from JellyfinTray. With the above fix, it still not transcoding and gives a error of "failed to create Direct3d device". Then I found a post about this from FFmpeg https://trac.ffmpeg.org/ticket/6827

@nyanmisaka
Copy link
Member

I also found a problem related to this one. The QSV transcode cannot work from JellyfinTray. With the above fix, it still not transcoding and gives a error of "failed to create Direct3d device". Then I found a post about this from FFmpeg https://trac.ffmpeg.org/ticket/6827

If you choose to newly install Jellyfin as a system network service, does ffmpeg qsv work properly?

@Sp4rky001
Copy link

I also found a problem related to this one. The QSV transcode cannot work from JellyfinTray. With the above fix, it still not transcoding and gives a error of "failed to create Direct3d device". Then I found a post about this from FFmpeg https://trac.ffmpeg.org/ticket/6827

If you choose to newly install Jellyfin as a system network service, does ffmpeg qsv work properly?

I can confirm that hardware transcoding is not possible when running as a service. I found the same problem when I used NSSM on Plex. The compromise that I ended up with was to use RBTray to send Jellyfin to the system tray

@nyanmisaka
Copy link
Member

I can confirm that hardware transcoding is not possible when running as a service. I found the same problem when I used NSSM on Plex. The compromise that I ended up with was to use RBTray to send Jellyfin to the system tray

It does happen, but he cannot use ffmpeg qsv on his computer even with the tray. Have you encountered similar issues?

[AVHWDeviceContext @ 000001a1363ace00] Error initializing an MFX session: -3. Error creating a QSV device

@frankyifei
Copy link
Author

frankyifei commented Mar 19, 2020

Sorry, maybe a false alarm about the Jellyfin tray. It was the command that use QSV for both decoding and encoding.
@nyanmisaka 's idea is working.
solution
From his post:

Specifically:
-vf "scale_qsv=format=nv12,hwdownload,subtitles='E\:/sampleAnime.mkv:si=0',hwupload=extra_hw_frames=64,format=qsv"

What adding the bold parts do is after scaling the frame via QSV, we download the frame from Video RAM to System RAM, do a software overlay of the subtitles, then upload it back up to Video Ram for output processing.

@nyanmisaka
Copy link
Member

nyanmisaka commented Mar 19, 2020

@nyanmisaka
Hello, I posted a solution to this on the Jellyfin Reddit: Burn-in Subtitle with Intel Quick Sync (QSV), found a solution.

The problem is that subtitles is a software filter so it is necessary to download the frame from the video card to the system, overlay the subtitles, then upload to video card again. I've been trying to get a dev's eyes on my solution so I'm hoping my reply here will do just that.

I found a way to use the QSV decoder and encoder and improve the text subtitle burning performance. Unlike using scale_vaapi, subtitles cannot be burned successfully using scale_qsv and hwmap unless hwdownload and hwupload are used to exchange data between the CPU and GPU, which will bring a huge performance cost and the GPU and CPU utilization is very low.

You can try the following commands to see the transcoding speed and hardware utilization.

no downscaling
C:\Server\Daemons\Jellyfin\ffmpeg.exe -c:v h264_qsv -i file:"E:\sampleAnime.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset fast -copyts -vf "subtitles='E\:/sampleAnime.mkv:si=0'" -y C:\Server\Temp\Jellyfin\temp.mp4

downscaling to 720p
C:\Server\Daemons\Jellyfin\ffmpeg.exe -c:v h264_qsv -i file:"E:\sampleAnime.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset fast -copyts -vf "scale=1280:720,subtitles='E\:/sampleAnime.mkv:si=0'" -y C:\Server\Temp\Jellyfin\temp.mp4

This method uses QSV as a hw decoder and hw encoder, and will also take up 40% ~ 55% of my i5 7300hq to render text subtitles. When the original video is 1080p, the transcoding rate can reach 100fps ~ 180fps depending on the original video encoding format and resolution. Compared to using libx264 for software coding or your proposal, the performance is much better.

@frankyifei
Copy link
Author

My Nas was not as powerful so it only runs at about speed=2x

@nyanmisaka
Copy link
Member

My Nas was not as powerful so it only runs at about speed=2x

For a NAS with a low power processor, this performance is already very good when burning subtitles. Does the MFX error still exist in Jellyfin?

@frankyifei
Copy link
Author

frankyifei commented Mar 19, 2020

My Nas was not as powerful so it only runs at about speed=2x

For a NAS with a low power processor, this performance is already very good when burning subtitles. Does the MFX error still exist in Jellyfin?

it is still there. it only happens when I set hw decoding + hw encoding. Now I use soft decoding + hw encoding. Because the current command jellyfin will cause a error of

Impossible to convert between the formats supported by the filter 'Parsed_scale_qsv_0' and the filter 'auto_scaler_0'
Error reinitializing filters!

I suspect it is the reason that cause MFX error

@nyanmisaka
Copy link
Member

nyanmisaka commented Mar 19, 2020

it is still there. it only happens when I set hw decoding + hw encoding. Now I use soft decoding + hw encoding.

This is a filter related error I known. But MFX error is unable to create a QSV device.
Error creating a QSV device

Here is the reason

D3D is not available from a Windows service and require the program to be launched from an interactive user session
https://trac.ffmpeg.org/ticket/6827

I just tried to install Jellyfin as a service and got similar MFX errors.
If you want to use QSV, do not install Jellyfin as a Windows service.

@Artiume
Copy link
Contributor

Artiume commented Mar 19, 2020

@anthonylavado
Copy link
Member

@Artiume I’ve never tried QSV myself, so this is news. The Microsoft link you’ve posred says this should work starting with DX11.1, but who knows if that’s getting called by FFMpeg or not. I guess not.

I have a couple of ideas to try and fix this from the Windows service side, but they require some build changes.

@Sp4rky001
Copy link

Sp4rky001 commented Mar 19, 2020

@Artiume I’ve never tried QSV myself, so this is news. The Microsoft link you’ve posred says this should work starting with DX11.1, but who knows if that’s getting called by FFMpeg or not. I guess not.

I have a couple of ideas to try and fix this from the Windows service side, but they require some build changes.

I think the note about DX11.1 is that WARP is supported in DX11.1, but that is a software rasterizer...

I found a way to use the QSV decoder and encoder and improve the text subtitle burning performance. Unlike using scale_vaapi, subtitles cannot be burned successfully using scale_qsv and hwmap unless hwdownload and hwupload are used to exchange data between the CPU and GPU, which will bring a huge performance cost and the GPU and CPU utilization is very low.

You can try the following commands to see the transcoding speed and hardware utilization.

no downscaling
C:\Server\Daemons\Jellyfin\ffmpeg.exe -c:v h264_qsv -i file:"E:\sampleAnime.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset fast -copyts -vf "subtitles='E\:/sampleAnime.mkv:si=0'" -y C:\Server\Temp\Jellyfin\temp.mp4

downscaling to 720p
C:\Server\Daemons\Jellyfin\ffmpeg.exe -c:v h264_qsv -i file:"E:\sampleAnime.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset fast -copyts -vf "scale=1280:720,subtitles='E\:/sampleAnime.mkv:si=0'" -y C:\Server\Temp\Jellyfin\temp.mp4

This method uses QSV as a hw decoder and hw encoder, and will also take up 40% ~ 55% of my i5 7300hq to render text subtitles. When the original video is 1080p, the transcoding rate can reach 100fps ~ 180fps depending on the original video encoding format and resolution. Compared to using libx264 for software coding or your proposal, the performance is much better.

I have an i7-7500U in a NUC form factor and I tried the two commands @nyanmisaka suggested. The no scaling: renders at 38-43 FPS with 19-24% CPU utilization
Scaling to 720p: renders at 39-41 FPS with 19-24% CPU utilization

Does "scale=1280:720" mean it is doing the scaling in software?

Edit: To append to this, I tried the scaling command on a 1080p source with an external SRT subtitle and the results were: renders at 40-43 fps but the CPU goes to 27%

Edit 2: One more edit. I tried the command I originally posted that used hwdownload/hwupload on the 1080p source with srt subtitle and the results were:
Renders at 28FPS but CPU hovers around 9 - 11%.
So I guess because of the bottleneck of copying the frames around, the FPS is much lower, and because of that, the system has less work to do.

@nyanmisaka
Copy link
Member

I have an i7-7500U in a NUC form factor and I tried the two commands @nyanmisaka suggested. The no scaling: renders at 38-43 FPS with 19-24% CPU utilization
Scaling to 720p: renders at 39-41 FPS with 19-24% CPU utilization

Does "scale=1280:720" mean it is doing the scaling in software?

Edit: To append to this, I tried the scaling command on a 1080p source with an external SRT subtitle and the results were: renders at 40-43 fps but the CPU goes to 27%

Edit 2: One more edit. I tried the command I originally posted that used hwdownload/hwupload on the 1080p source with srt subtitle and the results were:
Renders at 28FPS but CPU hovers around 9 - 11%.
So I guess because of the bottleneck of copying the frames around, the FPS is much lower, and because of that, the system has less work to do.

The conversion speed of U-series low-voltage processors is usually lower than that of HQ-series processors. If it is a desktop processor, it will perform even better. Memory frequency and channel number may also be influencing factors. I use the command you suggest to get only 40fps under the same conditions, but the command I recommend can reach at least 100fps. Using scale_qsv here still needs to hwdownload the frames to memory and then process them with subtitles, and then hwupload them to the GPU for output. It is better to use software scaling directly when necessary and avoid using hwdownload and hwupload.

@Sp4rky001
Copy link

I have an i7-7500U in a NUC form factor and I tried the two commands @nyanmisaka suggested. The no scaling: renders at 38-43 FPS with 19-24% CPU utilization
Scaling to 720p: renders at 39-41 FPS with 19-24% CPU utilization
Does "scale=1280:720" mean it is doing the scaling in software?
Edit: To append to this, I tried the scaling command on a 1080p source with an external SRT subtitle and the results were: renders at 40-43 fps but the CPU goes to 27%
Edit 2: One more edit. I tried the command I originally posted that used hwdownload/hwupload on the 1080p source with srt subtitle and the results were:
Renders at 28FPS but CPU hovers around 9 - 11%.
So I guess because of the bottleneck of copying the frames around, the FPS is much lower, and because of that, the system has less work to do.

The conversion speed of U-series low-voltage processors is usually lower than that of HQ-series processors. If it is a desktop processor, it will perform even better. Memory frequency and channel number may also be influencing factors. I use the command you suggest to get only 40fps under the same conditions, but the command I recommend can reach at least 100fps. Using scale_qsv here still needs to hwdownload the frames to memory and then process them with subtitles, and then hwupload them to the GPU for output. It is better to use software scaling directly when necessary and avoid using hwdownload and hwupload.

That's interesting that it is a higher cost to hwdown/hwupload than software scaling. Thanks for all this info.
I've tried to build the project using VSCode but it didn't work. I also tried the build .ps1 script in deployment folder. Just wondering when this change might make it into the nightlies. I suppose you need to first make a decision on the command to use first?

@nyanmisaka
Copy link
Member

nyanmisaka commented Mar 19, 2020

That's interesting that it is a higher cost to hwdown/hwupload than software scaling. Thanks for all this info.
I've tried to build the project using VSCode but it didn't work. I also tried the build .ps1 script in deployment folder. Just wondering when this change might make it into the nightlies. I suppose you need to first make a decision on the command to use first?

@frankyifei @Sp4rky001
I found out why we have such a big difference in transcoding speed. I may have overestimated the impact of the processor. It looks like some optimizations have been made in the 4.3 version of ffmpeg I'm using. You can download the latest version down below, extract all the files in /bin into the Jellyfin directory, and look at the transcoding speed again.

https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-latest-win64-shared.zip

@frankyifei
Copy link
Author

Ok, it should be someting upstream

@Sp4rky001
Copy link

I just wanted to share a few things that I learned in the last few days. As I've been playing various files, including x265, and Hi10 with image-based subtitles that require overlay, I've been modifying the source code and building Jellyfin to fit my own needs. A few conclusions that I've arrived at:

  • If we add "-hwaccel qsv" or "-init_hw_device qsv=hw -filter_hw_device hw ", it can sometimes error when trying to burn in subtitles.
  • If we add "-hwaccel qsv" or "-init_hw_device qsv=hw -filter_hw_device hw ", Jellyfin will not be able to transcode while running as a service.
  • When we remove "-hwaccel qsv" and "-init_hw....", it is no longer necessary to have lines that perform "hwupload=extra_hw_frame=64"
  • When burning subtitles, "scale_qsv" and "overlay_qsv" cause transcoding to fail, so they should be changed to the "scale" and "overlay" filters respectively.
  • The latest FFMPEG (linked by @nyanmisaka previously) increases the transcoding framerate dramatically.

With these changes, a text-based subtitle video transcodes at 140fps at around 48% cpu while an image-based subtitle video transcodes at 90fps at around 40% cpu, all while running Jellyfin as a service created manually using NSSM. I think this is acceptable performance and still preferable over software transcoding, which takes 100% cpu.

These are just my suggested changes and I'm attaching my patch file for reference.
patch.txt

@Sp4rky001
Copy link

this filter complex will work
"[0:2]scale=1280:690[sub];[0:0][sub]overlay=x=(W-w)/2:y=(H-h)/2"

I ran into the same problem with image-based subtitles and in my own code, I implemented the changes that you describe here (remove hwupload and change overlay_qsv to overlay). While this works beautifully, I get this annoying warning with EVERY SINGLE FRAME that's transcoded:

[graph 0 input from stream 0:2 @ 000001ec31dde0c0] Changing video frame properties on the fly is not supported by all filters.

any idea how to avoid this warning? I've tried all sorts of combinations of parameters but still get this warning. I can try to add -loglevel warning but I'm still looking for the best place in the code to add it.

@nyanmisaka
Copy link
Member

this filter complex will work
"[0:2]scale=1280:690[sub];[0:0][sub]overlay=x=(W-w)/2:y=(H-h)/2"

I ran into the same problem with image-based subtitles and in my own code, I implemented the changes that you describe here (remove hwupload and change overlay_qsv to overlay). While this works beautifully, I get this annoying warning with EVERY SINGLE FRAME that's transcoded:

[graph 0 input from stream 0:2 @ 000001ec31dde0c0] Changing video frame properties on the fly is not supported by all filters.

any idea how to avoid this warning? I've tried all sorts of combinations of parameters but still get this warning. I can try to add -loglevel warning but I'm still looking for the best place in the code to add it.

The problem we discussed earlier is the use of scale_qsv and subtitles filters based on the text subtitles. But there is no problem using overlay_qsv for burning graphical subtitles. You did not use overlay_qsv in your command to reduce CPU usage.

example:

ffmpeg -c:v -h264_qsv -hwaccel qsv -i file:"sample.mp4" -c:v h264_qsv 
-filter_complex "[0:2]scale=1280:690,hwupload=extra_hw_frames=64[sub];[0:0][sub]overlay_qsv=x=(W-w)/2:y=(H-h)/2,scale_qsv=format=nv12"
-y "out.mp4"

Linux + ffmpeg 4.3 is requied for the above commands and the reasons are explained earlier.

@frankyifei
Copy link
Author

@nyanmisaka , since the problem of overlay_qsv is from upstream ffmpeg, can we avoid using it on windows machine to work around this problem for now until it gets fixed by ffmpeg developers. I know there is an increase of CPU load but it is better to have it work for now. at least it still use gpu for decoding and encoding.

@stale
Copy link

stale bot commented Aug 1, 2020

This issue has gone 120 days without comment. To avoid abandoned issues, it will be closed in 21 days if there are no new comments.
If you're the original submitter of this issue, please comment confirming if this issue still affects you in the latest release or nightlies, or close the issue if it has been fixed. If you're another user also affected by this bug, please comment confirming so. Either action will remove the stale label.
This bot exists to prevent issues from becoming stale and forgotten. Jellyfin is always moving forward, and bugs are often fixed as side effects of other changes. We therefore ask that bug report authors remain vigilant about their issues to ensure they are closed if fixed, or re-confirmed - perhaps with fresh logs or reproduction examples - regularly. If you have any questions you can reach us on Matrix or Social Media.

@stale stale bot added the stale Stale and will be closed if no activity occurs label Aug 1, 2020
@stale stale bot closed this as completed Aug 22, 2020
@frankyifei
Copy link
Author

frankyifei commented Dec 17, 2020

I have to revive this. Server is running on windows 10, client is Chrome. The movie contains vodsub subtitles. Now the error message is
Stream mapping:
Stream #0:0 (h264_qsv) -> vpp_qsv (graph 0)
Stream #0:8 (dvdsub) -> scale (graph 0)
overlay (graph 0) -> Stream #0:0 (h264_qsv)
Stream #0:1 -> #0:1 (flac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=0.0 size=N/A time=-577014:32:22.77 bitrate=N/A speed=N/A
[matroska,webm @ 00000141704b7140] sub2video: using 1920x1040 canvas
Output #0, hls, to 'C:\Users\NAS\AppData\Local\Jellyfin\transcodes\dec2ffa397965dd1f90011b8b30627c5.m3u8':
Metadata:
encoder : Lavf58.48.100
Stream #0:0: Video: h264 (h264_qsv), nv12, 1920x1040 [SAR 1:1 DAR 24:13], q=-1--1, 15919 kb/s, 23.98 fps, 90k tbn, 23.98 tbc (default)
Metadata:
encoder : Lavc58.96.100 h264_qsv
Side data:
cpb: bitrate max/min/avg: 1591965/0/15919651 buffer size: 31839302 vbv_delay: N/A
Stream #0:1: Audio: mp3 (libmp3lame), 48000 Hz, stereo, s32p (24 bit), 192 kb/s (default)
Metadata:
encoder : Lavc58.96.100 libmp3lame
[AVHWFramesContext @ 0000014170c337c0] Error synchronizing the operation: -3
Error while add the frame to buffer source(Unknown error occurred).
[AVHWFramesContext @ 0000014170c337c0] Error synchronizing the operation: -3
Error while filtering: Unknown error occurred
Failed to inject frame into filter network: Unknown error occurred
Error while processing the decoded data for stream #0:0
[libmp3lame @ 0000014170c2f740] 3 frames left in the queue on closing
Conversion failed!

And the command in use is this

D:\Jellyfin\Server\ffmpeg.exe -c:v h264_qsv -hwaccel qsv -i file:"E:\Movies\风之谷 (1984)\风之谷 (1984) h264-1080p FLAC-2ch.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset 7 -look_ahead 0 -b:v 15919651 -maxrate 15919651 -bufsize 31839302 -profile:v high -level 4.1 -g 72 -keyint_min 72 -sc_threshold 0 -filter_complex "[0:8]scale=1920x1040[sub];[0:0]vpp_qsv=format=nv12[base];[base][sub]overlay" -start_at_zero -vsync -1 -codec:a:0 libmp3lame -ac 2 -ab 192000 -copyts -avoid_negative_ts disabled -f hls -max_delay 5000000 -hls_time 3 -individual_header_trailer 0 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "C:\Users\NAS\AppData\Local\Jellyfin\transcodes\dec2ffa397965dd1f90011b8b30627c5%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "C:\Users\NAS\AppData\Local\Jellyfin\transcodes\dec2ffa397965dd1f90011b8b30627c5.m3u8"

@Artiume
Copy link
Contributor

Artiume commented Dec 17, 2020

are you trying 10.6.4 or 10.7.0-rc1

@frankyifei
Copy link
Author

are you trying 10.6.4 or 10.7.0-rc1

10.6.4, I think there is not any new change in 10.7.0

@frankyifei
Copy link
Author

on 10.7 , the error message is
Stream mapping:
Stream #0:0 (h264_qsv) -> vpp_qsv (graph 0)
Stream #0:2 (dvdsub) -> scale (graph 0)
overlay (graph 0) -> Stream #0:0 (h264_qsv)
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[AVHWDeviceContext @ 0000013c90f77cc0] Error setting child device handle: -6

@nyanmisaka
Copy link
Member

nyanmisaka commented Dec 17, 2020

I cannot reproduce that on Intel 7th Gen HD 630. Update your driver an try again.

ffmpeg.exe -c:v hevc_qsv -hwaccel qsv -i file:"Tamako love story (2014).mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -codec:v:0 h264_qsv -preset 7 -look_ahead 0 -b:v 3616000 -maxrate 3616000 -bufsize 7232000 -profile:v:0 high -level 41 -g:v:0 72 -keyint_min:v:0 72 -sc_threshold:v:0 0 -filter_complex "[0:4]scale=1280x720[sub];[0:0]vpp_qsv=w=1280:h=720:format=nv12[base];[base][sub]overlay" -start_at_zero -vsync -1 -codec:a:0 aac -ac 2 -ab 384000 -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "R:\transcodes\16bc458afc075f69fa570cacd94e99a7%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "R:\transcodes\16bc458afc075f69fa570cacd94e99a7.m3u8"

Stream mapping:
  Stream #0:0 (hevc_qsv) -> vpp_qsv (graph 0)
  Stream #0:4 (pgssub) -> scale (graph 0)
  overlay (graph 0) -> Stream #0:0 (h264_qsv)
  Stream #0:1 -> #0:1 (flac (native) -> aac (native))
Press [q] to stop, [?] for help
[matroska,webm @ 0000012f174e40c0] sub2video: using 1920x1080 canvas
Output #0, hls, to 'R:\transcodes\16bc458afc075f69fa570cacd94e99a7.m3u8':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: h264 (h264_qsv), nv12, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 3616 kb/s, 23.98 fps, 90k tbn, 23.98 tbc (default)
    Metadata:
      encoder         : Lavc58.91.100 h264_qsv
    Side data:
      cpb: bitrate max/min/avg: 3616000/0/3616000 buffer size: 7232000 vbv_delay: N/A
    Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp (24 bit), 384 kb/s (default)
    Metadata:
      encoder         : Lavc58.91.100 aac
frame=    2 fps=0.0 q=0.0 size=N/A time=00:00:00.29 bitrate=N/A speed=0.45x    
frame=   70 fps= 60 q=26.0 size=N/A time=00:00:03.11 bitrate=N/A speed=2.67x    
[hls @ 0000012f17583a00] Opening 'R:\transcodes\16bc458afc075f69fa570cacd94e99a70.ts' for writing
frame=  134 fps= 80 q=26.0 size=N/A time=00:00:05.41 bitrate=N/A speed=3.25x    
[hls @ 0000012f17583a00] Opening 'R:\transcodes\16bc458afc075f69fa570cacd94e99a71.ts' for writing
frame=  191 fps= 88 q=26.0 size=N/A time=00:00:07.89 bitrate=N/A speed=3.62x    
[hls @ 0000012f17583a00] Opening 'R:\transcodes\16bc458afc075f69fa570cacd94e99a72.ts' for writing
frame=  244 fps= 90 q=12.0 size=N/A time=00:00:10.62 bitrate=N/A speed=3.94x    
[hls @ 0000012f17583a00] Opening 'R:\transcodes\16bc458afc075f69fa570cacd94e99a73.ts' for writing
frame=  310 fps= 97 q=13.0 size=N/A time=00:00:13.43 bitrate=N/A speed= 4.2x    
frame=  343 fps= 92 q=14.0 size=N/A time=00:00:14.20 bitrate=N/A speed=3.81x    

@Sp4rky001
Copy link

Hi again! In the past few months, I've settled on a setup that I can live with. My setup is a Windows 10 on a 6th gen i7 with embedded Intel graphics. I run in headless mode and access the PC through remote desktop.

What I discovered is that graphics acceleration only really works when you have an active desktop session that's logged in. The video driver just isn't fully accessible in a locked session or in a remote desktop session. I verified this with a video that showed blue when I logged in through remote desktop but transcodes just fine when logged in to the pc. So because I remote into the PC, Jellyfin ends up running in a remote desktop session.

My solution was to use RDP Wrap which tricks Windows into allowing multiple interactive sessions. I created a user named Jellyfin that logs in to the PC automatically on bootup (control userpassword2) and have Jellyfin start automatically, then set the computer to never sleep or log out. I'm then free to log in through remote desktop with a second account for everything else I need to do.

With this, I've had almost no issues transcoding the various videos that I threw at it. I hope this helps.

@nyanmisaka
Copy link
Member

nyanmisaka commented Dec 17, 2020

Good idea!
The current QSV implementation on Windows is still based on DXVA2, which requires a connected monitor to get it worked.

I have looked into the patchwork of ffmpeg. Intel stuffs have sent a series of patches to make it possible to init QSV on D3D11VA, which supports headless mode well. But it's still pending due to some discussions.

@wlau2929
Copy link

Hi again! In the past few months, I've settled on a setup that I can live with. My setup is a Windows 10 on a 6th gen i7 with embedded Intel graphics. I run in headless mode and access the PC through remote desktop.

What I discovered is that graphics acceleration only really works when you have an active desktop session that's logged in. The video driver just isn't fully accessible in a locked session or in a remote desktop session. I verified this with a video that showed blue when I logged in through remote desktop but transcodes just fine when logged in to the pc. So because I remote into the PC, Jellyfin ends up running in a remote desktop session.

My solution was to use RDP Wrap which tricks Windows into allowing multiple interactive sessions. I created a user named Jellyfin that logs in to the PC automatically on bootup (control userpassword2) and have Jellyfin start automatically, then set the computer to never sleep or log out. I'm then free to log in through remote desktop with a second account for everything else I need to do.

With this, I've had almost no issues transcoding the various videos that I threw at it. I hope this helps.

I too normally remote desktop (RD) into my server from my laptop, though my server has a display connected. I was reading this thread via RD into my server as I was having some issues with QSV and ffmpeg (looks to be a subtitle issue). I played a video on a client while logged in with RD and it did transcode pretty normally. I then logged out of RD and tried playing the same file and it errored out. I then logged into an active session on my server and played the same file on the same client and it worked just fine. I bet we can't be the only ones experiencing this issue. Is this in any of the guides or install instructions?

I'll give your solution a try since I remote into the server for purposes other than just Jellyfin. What is "RDP Wrap"?

@nyanmisaka
Copy link
Member

@wlau2929 Hey! There is a fix for QSV on headless machine. Would you like to try it?

Backup your data first. Download the jellyfin-ffmpeg 4.3.1-4 from the link below and extract all into your jellyfin installation folder. Restart jellyfin and give a try on QSV.
jellyfin-ffmpeg_4.3.1-4-windows_amd64.zip

@frankyifei
Copy link
Author

frankyifei commented Feb 4, 2021

@wlau2929 Hey! There is a fix for QSV on headless machine. Would you like to try it?

Backup your data first. Download the jellyfin-ffmpeg 4.3.1-4 from the link below and extract all into your jellyfin installation folder. Restart jellyfin and give a try on QSV.
jellyfin-ffmpeg_4.3.1-4-windows_amd64.zip

This works for me in most cases except dvdsub subtitles transcoding stills fails, on Intel j4105.

@nyanmisaka
Copy link
Member

@frankyifei Any logs?

@frankyifei
Copy link
Author

frankyifei commented Feb 6, 2021

@frankyifei Any logs?

using hardware decoding and encoding at the same time does not work.
log.txt

using cpu decoding and qsv encoding works.
log1.txt

I don't know if this is caused by my machine's low spec or something else.

@nyanmisaka
Copy link
Member

Does the error only happen to this video?

https://github.com/FFmpeg/FFmpeg/blob/069d2b4a50a6eb2f925f36884e6b9bd9a1e54670/libavutil/hwcontext_qsv.c#L872

    do {
        err = MFXVideoCORE_SyncOperation(s->session_download, sync, 1000);
    } while (err == MFX_WRN_IN_EXECUTION);
    if (err < 0) {
        av_log(ctx, AV_LOG_ERROR, "Error synchronizing the operation: %d\n", err);
        return AVERROR_UNKNOWN;
    }

@frankyifei
Copy link
Author

frankyifei commented Feb 6, 2021

@nyanmisaka, I tried two other movies and both had same error. This is one of the log
log2.txt

@Dark4Codrutz
Copy link

@wlau2929 Hey! There is a fix for QSV on headless machine. Would you like to try it?

Backup your data first. Download the jellyfin-ffmpeg 4.3.1-4 from the link below and extract all into your jellyfin installation folder. Restart jellyfin and give a try on QSV.
jellyfin-ffmpeg_4.3.1-4-windows_amd64.zip

I've looked at your nyanmisaka/jellyfin-ffmpeg@98afe79 commit but I couldn't understand why a "custom hwupload filter" would fix this, then I noticed you bumped the intel dependencies versions ... after some digging I found Intel-Media-SDK/MediaSDK@e3f10e7 commit.

I wanted to ask you if this is the change that now allows for QSV to work headless ? just wanting to better understand

@nyanmisaka
Copy link
Member

Hi! The jellyfin-ffmpeg repo is only for Linux for the time being. So I didn't submit the Windows specific patches there.

Please reference to this branch. I have merged some DX11 QSV stuff there.
https://github.com/nyanmisaka/FFmpeg/commits/scale_cuda

@Dark4Codrutz
Copy link

@Pljushevij open your own thread/issue man.
You are out of topic and also necroing a closed issue.

@Pljushevij
Copy link

@Pljushevij open your own thread/issue man.
You are out of topic and also necroing a closed issue

Sorry, man! :)

TimothyGu pushed a commit to FFmpeg/FFmpeg that referenced this issue Sep 8, 2021
…icitly select d3d11va/DX11 device type

UPD: Rebase of last patch set over current master and use DX9 as default device type.

Makes selection of dxva2/DX9 device type by default as before with explicit d3d11va/DX11 usage to cover more HW configurations.
Added warning message to expect changing default device type in the future.

Fixes TGL / AV1 decode as requires DX11 with explicit DX11 type
selection.

Add headless/multi adapter support and fixes:
    https://trac.ffmpeg.org/ticket/7511
    https://trac.ffmpeg.org/ticket/6827
    http://ffmpeg.org/pipermail/ffmpeg-trac/2017-November/041901.html
    https://trac.ffmpeg.org/ticket/7933
    InitialForce@338fbcd
    jellyfin/jellyfin#2626 (comment)

Any other fixes are welcome including OpenCL interop patch since I don't have proper setup to validate this use case

Decoding, encoding, transcoding have been validated.

child_device_type option is responsible for d3d11va/dxva2 device selection

Usage examples:

DirectX 11:
    -init_hw_device qsv:hw,child_device_type=d3d11va
    -init_hw_device qsv:hw,child_device_type=d3d11va,child_device=0
OR
    -init_hw_device d3d11va=dx -init_hw_device qsv@dx

DirectX 9 is still supported but requires explicit selection:
    -init_hw_device qsv:hw,child_device_type=dxva2
OR
    -init_hw_device dxva2=dx -init_hw_device qsv@dx

Signed-off-by: Artem Galin <artem.galin@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale Stale and will be closed if no activity occurs
Projects
None yet
Development

No branches or pull requests

8 participants