Jump to content

GPU Transcoding (Intel QuickSync and nVidia NVENC)


witteschnitte

Recommended Posts

MSattler

Ok so using this scripts I was able to successfully cross compile ffmpeg with nvenc. 

https://bannsecurity.com/index.php/tutorials/23-compiling-ffmpeg-for-windows-nvidia

grate script by the way kudos to the dev. 

I have tested it with running ffmpeg with command line and it works great.  My next step is how to implement this into Emby.  Is nvenc available in a dev branch?

 

Thanks,

Chris

 

Something you may want to test is if there is a limit of the number of concurrent transcodes Nvidia card's can make.  There was some talk in the past about a limitation of 2 transcodes, which could be a huge limitation if it is true.

 

Can you test that?

 

Thanks!

Link to comment
Share on other sites

chrismb

ok, I tested and I was only able to do 2 video transcodes at once.  However it worked great only about 50% cpu utilization which in my case left me enough overhead to run another libx264 transcode.  so 2 nvenc and 1 libx264.  this was using a 32bit ffmpeg didn't try with a 64 bit version.  For me the 2 streams are sufficent for what I need, as in most cases I'm not transcoding but doing direct play to a roku.  What I would like to get to work is using the zotec video card that I picked up from newegg for under $50 (fyi fanless) to allow my PC to be able to transcode using the nvenc so that when an h265 file is selected for playback on a roku I can utilize the hardware h264 encoding. 

 

P.S.

the script that I linked to I needed to add an option to curl --insecure it kept failing when trying to download from sourceforge for one of the packages.  I changed line 409 to 

  curl --insecure -4 $url -O || exit 1

 

from

 

  curl -4 $url -O || exit 1
 

 

Thanks,

Chris

Edited by chrismb
Link to comment
Share on other sites

Vlaves

no, you're all good for quicksync.

Seems like quicksync is only used for decoding. Can we use it for encoding too or is this laready the case?

I'm using Emby Server on Windows btw.

Edited by Vlaves
Link to comment
Share on other sites

witteschnitte

Hi at all.

 

I have a little one question. The ffmpeg shipped with emby for linux has build in libmfx. Did anyone got quicksync working with this build of ffmpeg in linux?

 

and yes quicksync is working on my linux machine with tvheadend and the Intel media Samples.

 

Regards

Link to comment
Share on other sites

witteschnitte

Hi

Maybe this is the right place to ask.

Ich compiled ffmpeg with all the emby ffmpeg is used and add the libmfx. (tried on ubuntu and centos)

 

Now normal emby transcode works fine. if i try to use quicksync it crashes. Now i look deeper and found (run ffmpeg by hand) that i can use h264_qsv to decode but if i try to encode with h264_qsv as emby does it crashes with memory dump.

 

Did i miss a switch in ffmpeg?

 

Regards

Link to comment
Share on other sites

I don't have your answer but in general I think you will get more responses from others by supplying some examples.

Link to comment
Share on other sites

witteschnitte

Ok Luke I think you are right.

 

So here are some examples

 

If i transcode with  ffmpeg -i "/home/test.mp4" -b:v 1000k -vcodec h264_qsv "/home/output.mp4"

I get

libva info: VA-API version 0.99.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk/lib64/iHD_drv_video.so
libva info: Found init function __vaDriverInit_0_32

 

and after that transcoding starts

it works fine but only decode.

 

If i transcode like emby does ffmpeg -c:v h264_qsv -i "/home/test.mp4" -b:v 1000k -vcodec h264_qsv "/home/output.mp4"

 

I get

 

libva info: VA-API version 0.99.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk/lib64/iHD_drv_video.so
libva info: Found init function __vaDriverInit_0_32

 

Speicherzugriffsfehler (Speicherabzug geschrieben)

 

so it does not work.

 

Sorry the error is in german i think it was a "segmentation fault"

 

regards

  • Like 1
Link to comment
Share on other sites

witteschnitte

@@Luke

i found it

 

quicksync on linux only works in emby when the transoding File is not h264 cpmpressed. with xvid for example emby transcode "ffmpeg -i "/home/test.mp4" -b:v 1000k -vcodec h264_qsv "/home/output.mp4""

(this is a simple example)

 

but with h264 emby begins ffmpeg with "c:v h264_qsv"

 

ffmpeg -c:v h264_qsv -i "/home/test.mp4" -b:v 1000k -vcodec h264_qsv "/home/output.mp4"

 

this does not work with ffmpeg.

 

if i copy the ffmpeg order from the log and leave the leading "h264_qsv" transoding with quicksync runs. by the way 5 times faster than normal transcode.

 

could i changed this? Or have you to changed this in the next Release?

 

unfortunately i need a self compiled ffmpeg

Link to comment
Share on other sites

witteschnitte

Ok i look deeper. it should work but for me it doesnt. I dont know what to do.

 

In the Intel docs are no examples with the leading h264_qsv. I tried with vc1_qsv this worked but no picture(of course my Video was h264;-) ) but decoding should work as you said. maybe its my ffmpeg?

 

regardd

Edited by witteschnitte
Link to comment
Share on other sites

witteschnitte

ok. it was ffmpeg 3.0. with this its not working at the Moment.

I switch to ffmpeg 2.8.6 and now it runs.

Link to comment
Share on other sites

inkubux

I have trouble playing HEVC files in chrome with  hardware transcoding activated. x264 videos don't seem to cause the issue If I enable HW transcoding

 

I have no issues listening to the same movie with HW decoding disabled

 

here is a copy of my log if it helps:

http://belanger.ddns.net:8096/emby/videos/80de1149d8dc53464622172858fe3d01/stream.mkv?DeviceId=deebfd1abde280182b1e9ff624d745bdf456dc0f&MediaSourceId=80de1149d8dc53464622172858fe3d01&VideoCodec=h264&AudioCodec=aac&AudioStreamIndex=1&VideoBitrate=548251429&AudioBitrate=320000&MaxAudioChannels=6&StartTimeTicks=12524071044&Level=41&Profile=high&PlaySessionId=455c086e27cd4e1db9f1afeacd360570&api_key=3601211bc6064561ab766c5c093b7a02&CopyTimestamps=true&ForceLiveStream=false

{"Protocol":"File","Id":"80de1149d8dc53464622172858fe3d01","Path":"/mnt/user/Media/TV Shows/Game Of Thrones/Season 6/Game of Thrones - S06E01 - The Red Woman.mkv","Type":"Default","Container":"mkv","Name":"1080P/HEVC/AAC","RunTimeTicks":29982600000,"ReadAtNativeFramerate":false,"SupportsTranscoding":true,"SupportsDirectStream":true,"SupportsDirectPlay":true,"RequiresOpening":false,"RequiresClosing":false,"VideoType":"VideoFile","MediaStreams":[{"Codec":"hevc","IsInterlaced":false,"BitRate":1540043,"RefFrames":1,"IsDefault":true,"IsForced":false,"Height":1078,"Width":1920,"AverageFrameRate":23.97602,"RealFrameRate":23.97602,"Profile":"Main","Type":"Video","AspectRatio":"16:9","Index":0,"IsExternal":false,"IsTextSubtitleStream":false,"SupportsExternalStream":false,"PixelFormat":"yuv420p","Level":120,"IsAnamorphic":false},{"Codec":"aac","IsInterlaced":false,"ChannelLayout":"5.1","Channels":6,"SampleRate":48000,"IsDefault":true,"IsForced":false,"Profile":"HE-AAC","Type":"Audio","Index":1,"IsExternal":false,"IsTextSubtitleStream":false,"SupportsExternalStream":false,"Level":0},{"Codec":"srt","Language":"eng","IsInterlaced":false,"IsDefault":false,"IsForced":false,"Type":"Subtitle","Index":2,"IsExternal":true,"IsTextSubtitleStream":true,"SupportsExternalStream":true,"Path":"/mnt/user/Media/TV Shows/Game Of Thrones/Season 6/Game of Thrones - S06E01 - The Red Woman.eng.srt"}],"PlayableStreamFileNames":[],"Formats":[],"Bitrate":1540043,"RequiredHttpHeaders":{}}

/bin/ffmpeg -ss 00:20:52.407 -fflags +genpts -noaccurate_seek -i file:"/mnt/user/Media/TV Shows/Game Of Thrones/Season 6/Game of Thrones - S06E01 - The Red Woman.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 "scale=trunc(min(max(iw\,ih*dar)\,1280)/2)*2:trunc(ow/dar/2)*2" -copyts -avoid_negative_ts disabled -start_at_zero -preset 7 -look_ahead 0 -b:v 1540043 -maxrate 1540043 -bufsize 3080086 -vsync vfr -profile:v high -level 4.1 -map_metadata -1 -threads 0 -codec:a:0 aac -strict experimental -ac 6 -ab 320000 -af "aresample=async=1" -y "/config/transcoding-temp/bc06819ddc32d6f0eb69f535b1ebbe95.mkv"


ffmpeg version 3.0.1-static http://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.1 (Debian 5.3.1-13) 20160323
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libwebp --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-fontconfig --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus --enable-libass --enable-gnutls --enable-libvidstab --enable-libsoxr --enable-frei0r --enable-libfribidi --disable-indev=sndio --disable-outdev=sndio --enable-librtmp --enable-libmfx --enable-libzimg --cc=gcc
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
[aac @ 0x3bb1400] element type mismatch 3 != 0
[aac @ 0x3bb1400] element type mismatch 1 != 0
    Last message repeated 1 times
Input #0, matroska,webm, from 'file:/mnt/user/Media/TV Shows/Game Of Thrones/Season 6/Game of Thrones - S06E01 - The Red Woman.mkv':
  Metadata:
    encoder         : libebml v1.3.1 + libmatroska v1.4.2
    creation_time   : 2016-04-25 06:14:34
  Duration: 00:49:58.26, start: 0.000000, bitrate: 1540 kb/s
    Stream #0:0: Video: hevc (Main), yuv420p(tv), 1920x1078, SAR 255:254 DAR 122400:68453, 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
    Metadata:
      BPS             : 1350512
      BPS-eng         : 1350512
      DURATION        : 00:49:58.245000000
      DURATION-eng    : 00:49:58.245000000
      NUMBER_OF_FRAMES: 71886
      NUMBER_OF_FRAMES-eng: 71886
      NUMBER_OF_BYTES : 506146086
      NUMBER_OF_BYTES-eng: 506146086
      _STATISTICS_WRITING_APP: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_DATE_UTC: 2016-04-25 06:14:34
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-04-25 06:14:34
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    Stream #0:1: Audio: aac (HE-AAC), 48000 Hz, 5.1, fltp (default)
    Metadata:
      BPS             : 187692
      BPS-eng         : 187692
      DURATION        : 00:49:58.229000000
      DURATION-eng    : 00:49:58.229000000
      NUMBER_OF_FRAMES: 70271
      NUMBER_OF_FRAMES-eng: 70271
      NUMBER_OF_BYTES : 70342993
      NUMBER_OF_BYTES-eng: 70342993
      _STATISTICS_WRITING_APP: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_APP-eng: mkvmerge v7.8.0 ('River Man') 32bit built on Mar 27 2015 16:18:02
      _STATISTICS_WRITING_DATE_UTC: 2016-04-25 06:14:34
      _STATISTICS_WRITING_DATE_UTC-eng: 2016-04-25 06:14:34
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
[h264_qsv @ 0x3bf6160] Error initializing an internal MFX session
Output #0, matroska, to '/config/transcoding-temp/bc06819ddc32d6f0eb69f535b1ebbe95.mkv':
    Stream #0:0: Video: h264, none, q=2-31, 128 kb/s, SAR 39015:39116 DAR 0:0, 23.98 fps (default)
    Metadata:
      encoder         : Lavc57.24.102 h264_qsv
    Stream #0:1: Audio: aac, 0 channels, 128 kb/s (default)
    Metadata:
      encoder         : Lavc57.24.102 aac
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> h264 (h264_qsv))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Thanks for your help

Edited by inkubux
Link to comment
Share on other sites

witteschnitte

Some ffmpeg Parameter seems to be wrong.  And as i See you having trouble with the infernal mfx session. Is the Intel media SDK installed?

Link to comment
Share on other sites

witteschnitte

I also have a problem transcoding files with DTS sound using quicksync.

I am getting

[hls @ 0x34349c0] Non-monotonous DTS in output stream 0:0; previous: 5005, current: 2002; changing to 5006. This may result in incorrect timestamps in the output file.

 

The Video stutters.

 

HD files with Dolby runs normal.

 

This DTS transcoding also runs normal using ffmpeg without quicksync.

Did someone have any ideas?

Edited by witteschnitte
Link to comment
Share on other sites

inkubux

Some ffmpeg Parameter seems to be wrong.  And as i See you having trouble with the infernal mfx session. Is the Intel media SDK installed?

 

Honestly I used the Docker (from this site) image on my unraid system so I really don't know.

 

How can I verify this ?

Link to comment
Share on other sites

witteschnitte

Ok.

Unfortunately Intel Media SDK does not run in Docker and without Intel Media SDK quicksync not runs in Linux.

Edited by witteschnitte
Link to comment
Share on other sites

witteschnitte

So i tried to figure out what causes the
[hls @ 0x34349c0] Non-monotonous DTS in output stream 0:0; previous: 5005, current: 2002; changing to 5006. This may result in incorrect timestamps in the output file.

I found that obmit the "vsync" let the problem disappear.

This Problem only comes when transcoding videos with DTS sound.

my question @@Luke.

Is the vsync parameter nessecery?

 

Or can you set vsync with parameter "-1"?

 

Or is there a way to manually edit the ffmpeg parameters emby uses?

-vsync -1

 this is the auto Switch it decide between cfr an vfr

with "-1" it works very nice.

Regards

Edited by witteschnitte
Link to comment
Share on other sites

witteschnitte

So i tested around with the 

vsync -1

And found only good results in all kind of videos.

And news from the developers?

How do i get transcoding working by changing the ffmpeg vsync parameter from "vfr" to "-1" ?

 

Regards

Felix

Edited by witteschnitte
Link to comment
Share on other sites

Deihmos

I had to turn quick sync off because videos are playing jerky with it on even when direct streaming in the edge browser.

Link to comment
Share on other sites

witteschnitte

I only found its playing jerky if the sound is dts . with changing the vsync parameter to "-1" it play smooth.

 

I like to here whether its going to bei changed in emby.

Edited by witteschnitte
Link to comment
Share on other sites

Deihmos

I installed the beta and now it works fine.

 

Edit. Quicksync isn't working in the beta. Cpu use went from 30% and below to now 80% but the log says qvs

Edited by Deihmos
Link to comment
Share on other sites

I installed the beta and now it works fine.

 

Edit. Quicksync isn't working in the beta. Cpu use went from 30% and below to now 80% but the log says qvs

 

Please make sure to see how to report a problem. Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...