Intel QSV Codecs

Website, builds, or other suggestions.
User avatar
mikeversteeg
Posts: 16
Joined: Fri Feb 19, 2016 1:22 pm

Re: Intel QSV Codecs

Post by mikeversteeg » Mon May 23, 2016 8:02 am

Anyone know if this is being handled? With all the pr Intel is giving ffmpeg, it seems like a waste to let this opportunity go by (and in fact reflect poorly on ffmpeg). The ticket seems dead.

HorikawaOtane
Posts: 2
Joined: Tue Jun 07, 2016 1:58 am

Re: Intel QSV Codecs

Post by HorikawaOtane » Tue Jun 07, 2016 2:05 am

I have verified this exact situation on my own build of ffmpeg from git. I am running this on an Intel HD 3000 on my Core i7 2640m (on my XPS 15z). This is a Second Generation Intel CPU, rather than a Fourth.

The command

Code: Select all

ffmpeg.exe -i "Somehow.mp4" -loglevel debug -c:v h264_qsv -look_ahead 0 -y -an out.qsv.mp4
Produces

Code: Select all

ffmpeg version N-80215-g808356c Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (Rev5, Built by MSYS2 project)
  configuration: --prefix=/mingw64 --extra-cflags='-I/home/HorikawaOtane/sandbox/bonus-libs/include -I/usr/local/include' --extra-ldflags='-L/home/HorikawaOtane/sandbox/bonus-libs/lib -L/usr/local/lib' --target-os=mingw32 --arch=x86_64 --disable-debug --enable-static --enable-small --enable-avresample --enable-cuda --enable-dxva2 --enable-d3d11va --enable-avisynth --enable-bzlib --enable-frei0r --enable-iconv --enable-libfdk-aac --enable-fontconfig --enable-gnutls --enable-gpl --enable-libass --enable-libbluray --enable-libcaca --enable-libcelt --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx265 --enable-libxvid --enable-libvpx --enable-nonfree --enable-openal --enable-opencl --enable-libwavpack --enable-pic --enable-postproc --enable-runtime-cpudetect --enable-shared --enable-static --enable-swresample --enable-version3 --enable-zlib --disable-doc --enable-pthreads --enable-libbs2b --enable-libgme --enable-libilbc --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libsnappy --enable-libsoxr --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwebp --enable-libxavs --enable-libzimg --enable-lzma --enable-libkvazaar
  libavutil      55. 24.100 / 55. 24.100
  libavcodec     57. 44.101 / 57. 44.101
  libavformat    57. 37.101 / 57. 37.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 46.100 /  6. 46.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Splitting the commandline.
Reading option '-i' ... matched as input file with argument 'Somehow.mp4'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'h264_qsv'.
Reading option '-look_ahead' ... matched as AVOption 'look_ahead' with argument '0'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-an' ... matched as option 'an' (disable audio) with argument '1'.
Reading option 'out.qsv.mp4' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file Somehow.mp4.
Successfully parsed a group of options.
Opening an input file: Somehow.mp4.
[file @ 000001d6a31c65c0] Setting default whitelist 'file,crypto'
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001d6a31c5fc0] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001d6a31c5fc0] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001d6a31c5fc0] Unknown dref type 0x08206c7275 size 12
    Last message repeated 1 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001d6a31c5fc0] Before avformat_find_stream_info() pos: 5054457 bytes read:47690 seeks:1
[h264 @ 000001d6a31d75c0] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 000001d6a31d75c0] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 000001d6a31d75c0] nal_unit_type: 5, nal_ref_idc: 3
[h264 @ 000001d6a31d75c0] no picture
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001d6a31c5fc0] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001d6a31c5fc0] After avformat_find_stream_info() pos: 96052 bytes read:175015 seeks:2 frames:3
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Somehow.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.37.101
  Duration: 00:00:11.40, start: 0.000000, bitrate: 3546 kb/s
    Stream #0:0(und), 2, 1/90000: Video: h264, 1 reference frame (avc1 / 0x31637661), yuv420p(left), 1234x1080 (0x0) [SAR 1:1 DAR 617:540], 0/1, 3435 kb/s, 60 fps, 60 tbr, 90k tbn, 120 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und), 1, 1/44100: Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Successfully opened the file.
Parsing a group of options: output file out.qsv.mp4.
Applying option c:v (codec name) with argument h264_qsv.
Applying option an (disable audio) with argument 1.
Successfully parsed a group of options.
Opening an output file: out.qsv.mp4.
[file @ 000001d6a31c0600] Setting default whitelist 'file,crypto'
Successfully opened the file.
detected 4 logical cores
[graph 0 input from stream 0:0 @ 000001d6a31dbee0] Setting 'video_size' to value '1234x1080'
[graph 0 input from stream 0:0 @ 000001d6a31dbee0] Setting 'pix_fmt' to value '0'
[graph 0 input from stream 0:0 @ 000001d6a31dbee0] Setting 'time_base' to value '1/90000'
[graph 0 input from stream 0:0 @ 000001d6a31dbee0] Setting 'pixel_aspect' to value '1/1'
[graph 0 input from stream 0:0 @ 000001d6a31dbee0] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 000001d6a31dbee0] Setting 'frame_rate' to value '60/1'
[graph 0 input from stream 0:0 @ 000001d6a31dbee0] w:1234 h:1080 pixfmt:yuv420p tb:1/90000 fr:60/1 sar:1/1 sws_param:flags=2
[format @ 000001d6a325e240] compat: called with args=[nv12|qsv]
[format @ 000001d6a325e240] Setting 'pix_fmts' to value 'nv12|qsv'
[auto-inserted scaler 0 @ 000001d6a325e660] Setting 'flags' to value 'bicubic'
[auto-inserted scaler 0 @ 000001d6a325e660] w:iw h:ih flags:'bicubic' interl:0
[format @ 000001d6a325e240] auto-inserting filter 'auto-inserted scaler 0' between the filter 'Parsed_null_0' and the filter 'format'
[AVFilterGraph @ 000001d6a31c52a0] query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
[auto-inserted scaler 0 @ 000001d6a325e660] w:1234 h:1080 fmt:yuv420p sar:1/1 -> w:1234 h:1080 fmt:nv12 sar:1/1 flags:0x4
[h264 @ 000001d6a53ecee0] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 000001d6a53ecee0] nal_unit_type: 8, nal_ref_idc: 3
[h264_qsv @ 000001d6a532e820] Initialized an internal MFX session using software implementation
[h264_qsv @ 000001d6a532e820] Using the average variable bitrate (AVBR) ratecontrol method
[h264_qsv @ 000001d6a532e820] Error retrieving encoding parameters.
Output #0, mp4, to 'out.qsv.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.37.101
    Stream #0:0(und), 0, 0/0: Unknown: none, SAR 1:1 DAR 0:0 (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.44.101 h264_qsv
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_qsv))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[AVIOContext @ 000001d6a51cee60] Statistics: 0 seeks, 0 writeouts
[AVIOContext @ 000001d6a31ce7a0] Statistics: 175015 bytes read, 2 seeks
So at a minimum the git version as of today still has this issue.

AlcyonaHaramix
Posts: 3
Joined: Sat Jun 18, 2016 11:44 am

Re: Intel QSV Codecs

Post by AlcyonaHaramix » Sat Jun 18, 2016 1:13 pm

just a few tips , in case you forgot about these :

> make sure that > your monitor is connected to the integrated intel graphics , which is inside an (for example) > i7 4790k cpu > (monitor is connected to the motherboard , monitor is NOT connected to the external GAMING graphics card)

> make sure that > intel drivers for integrated graphics are installed > (i really dont remember , what version of intel drivers are installed , on my windows 10 , with my i7 4790k cpu)

,

when zeranoe did include an > [[[ --enable-libmfx ]]] > in the builds... then it was already working fine for me , from the very first build with > [[[ --enable-libmfx ]]] > (but i really dont remember what build that was) ... well , at least in debug output mode > [[[ -v verbose ]]] > ffmpeg did > (yes , it DID , lol) > output something like this... (i just now searched the old TXT document , and found these old PARTS of logs from ffmpeg) :

notice the first 2 lines... yes , this log is NOT full , because its really old... the full log , just wasnt saved , for some reason...

Code: Select all


[h264_qsv @ 000002664f245e20] Initialized an internal MFX session using hardware accelerated implementation
[h264_qsv @ 000002664f245e20] Using the intelligent constant quality with lookahead (LA_ICQ) ratecontrol method

,

[h264_qsv @ 000002664f245e20] profile: high; level: 30
[h264_qsv @ 000002664f245e20] GopPicSize: 250; GopRefDist: 4; GopOptFlag: closed ; IdrInterval: 0
[h264_qsv @ 000002664f245e20] TargetUsage: 1; RateControlMethod: LA_ICQ
[h264_qsv @ 000002664f245e20] ICQQuality: 0; LookAheadDepth: 100
[h264_qsv @ 000002664f245e20] NumSlice: 1; NumRefFrame: 3
[h264_qsv @ 000002664f245e20] RateDistortionOpt: OFF
[h264_qsv @ 000002664f245e20] RecoveryPointSEI: OFF IntRefType: 0; IntRefCycleSize: 0; IntRefQPDelta: 0
[h264_qsv @ 000002664f245e20] MaxFrameSize: 176640; MaxSliceSize: 0;
[h264_qsv @ 000002664f245e20] BitrateLimit: ON; MBBRC: OFF; ExtBRC: unknown
[h264_qsv @ 000002664f245e20] Trellis: off
[h264_qsv @ 000002664f245e20] RepeatPPS: ON; NumMbPerSlice: 0; LookAheadDS: off
[h264_qsv @ 000002664f245e20] AdaptiveI: unknown; AdaptiveB: unknown; BRefType: off
[h264_qsv @ 000002664f245e20] MinQPI: 0; MaxQPI: 0; MinQPP: 0; MaxQPP: 0; MinQPB: 0; MaxQPB: 0
[h264_qsv @ 000002664f245e20] Entropy coding: CABAC; MaxDecFrameBuffering: 3
[h264_qsv @ 000002664f245e20] NalHrdConformance: OFF; SingleSeiNalUnit: ON; VuiVclHrdParameters: OFF VuiNalHrdParameters: OFF

,

here is the command , that was used , and i am using it now also... (yes i know , its really long) ... the command is for live desktop stream... but i think , you can try to adapt it for your needs...

Code: Select all


ffmpeg.exe -v verbose -rtbufsize 777555777 -threads 16 -thread_queue_size 444 -f gdigrab -framerate 23.976 -offset_x 0 -offset_y 0 -video_size 644x484 -draw_mouse 1 -r 23.976 -i desktop -f dshow -channel_layout stereo -i audio="@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{794BFCF0-FD05-463C-9F81-3C93096B7328}" -pix_fmt nv12 -global_quality:v 3 -c:v h264_qsv -async_depth 4 -avbr_accuracy 0 -avbr_convergence 0 -preset veryslow -vcm 0 -cavlc 0 -idr_interval 0 -pic_timing_sei 1 -max_dec_frame_buffering 0 -look_ahead 1 -look_ahead_depth 100 -look_ahead_downsampling off -trellis:v P -profile:v high -a53cc 0 -minrate 7111111 -bufsize 7111111 -sample_fmt s16p -compression_level 10 -c:a libmp3lame -b:a 192k -ar 44100 -ac 2 -joint_stereo false -reservoir true -abr false -f flv tcp://127.114.115.117:55755/

,

and just for completeness sake... i will quote some stuff... from > ( /_ffmpeg_intel_qsv_draft_.txt )

The family of Intel QuickSync Video encoders (MPEG-2 , H.264 , HEVC)

The ratecontrol method is selected as follows :

-- When [-global_quality:v] is specified, a quality-based mode is used
-- Specifically this means either

- CQP - constant quantizer scale, when the [-qscale:v] codec flag is also set (the [-qscale:v] or [-q:v] ffmpeg option)
- LA_ICQ - intelligent constant quality with lookahead, when the [-look_ahead] option is also set
- ICQ - intelligent constant quality otherwise

-- Otherwise, a bitrate-based mode is used
-- For all of those, you should specify at least the desired average bitrate with the [-b] option

- LA - VBR with lookahead, when the [-look_ahead] option is specified
- VCM - video conferencing mode, when the [-vcm] option is set
- CBR - constant bitrate, when [-maxrate] is specified and equal to the average bitrate [-b] option
- VBR - variable bitrate, when [-maxrate] is specified, but is higher than the average bitrate [-b] option
- AVBR - average VBR mode, when [-maxrate] is not specified, this mode is further configured by the [-avbr_accuracy] and [-avbr_convergence] options

Note that depending on your system, a different mode than the one you specified may be selected by the encoder
Set the verbosity level to verbose [[[ -loglevel verbose ]]] or [[[ -v verbose ]]] or higher, to see the actual settings used by the QSV runtime

Additional libavcodec global options are mapped to MSDK ( Media SDK ) options as follows :

-- ( g / gop_size ) -> GopPicSize
-- ( bf / max_b_frames+1 ) -> GopRefDist
-- ( rc_init_occupancy / rc_initial_buffer_occupancy ) -> InitialDelayInKB
-- slices -> NumSlice
-- refs -> NumRefFrame
-- ( b_strategy / b_frame_strategy ) -> BRefType
-- ( cgop / CLOSED_GOP codec flag ) -> GopOptFlag
-- For the CQP mode, the ( i_qfactor / i_qoffset ) and ( b_qfactor / b_qoffset ) set the difference between ( QPP and QPI ) and ( QPP and QPB ) respectively
-- Setting the [-coder] option to the value [-vlc] will make the H.264 encoder use CAVLC instead of CABAC
,

!! (HTH) !! > (hope this helpes) ... someone of you...
Last edited by AlcyonaHaramix on Wed Sep 13, 2017 3:29 am, edited 4 times in total.

User avatar
Zeranoe
Site Admin
Posts: 640
Joined: Sat May 07, 2011 7:12 pm
Contact:

Re: Intel QSV Codecs

Post by Zeranoe » Tue Jun 21, 2016 6:42 am

I've submitted a patch to resolve the "Error while opening encoder for output stream" error. https://ffmpeg.org/pipermail/ffmpeg-dev ... 95544.html

User avatar
Zeranoe
Site Admin
Posts: 640
Joined: Sat May 07, 2011 7:12 pm
Contact:

Re: Intel QSV Codecs

Post by Zeranoe » Tue Nov 01, 2016 4:06 am

QSV has been significantly rewritten and will work again on fourth gen CPUs.

Please test QSV and report any issues.

User avatar
mikeversteeg
Posts: 16
Joined: Fri Feb 19, 2016 1:22 pm

Re: Intel QSV Codecs

Post by mikeversteeg » Thu Jan 12, 2017 12:17 pm

Thanks Kyle, although I quickly browse the revision lists I must have missed that (as well as your post). Just tried my last code and indeed it now sort of works, the error is indeed gone. But CPU usage is through the roof (and video is suddenly upside down, but that's not a problem). I'll have to reread all docs again to see if I missed something as I was expecting less CPU usage (and more latency).

rkan
Posts: 3
Joined: Tue Jan 12, 2016 9:10 am

Re: Intel QSV Codecs

Post by rkan » Sun Jan 15, 2017 3:21 am

Could we also get decoder support for more than just h264? I need to run a MJPEG (webcam etc) source from a very low power device (x5-Z8300), which currently doesn't seem to be able to run 1280x720 just displaying it... I wonder if this is because of ffmpeg or something else, since CPU and GPU usage are below 50%..

I checked the decoders and encoders in the current Zeranoe build and they seem to include mjpeg hardware acceleration only for NVIDIA (mjpeg_cuvid). There is H265, H264, VC-1 and MPEG2 support for QSV. MFX / QSV got mjpeg hw support in 2015 according to this post: http://ffmpeg.org/pipermail/ffmpeg-deve ... 76624.html

So could we get mjpeg_qsv decoder and why not the encoder as well. Encoder should be supported from 6th gen Intel chips onwards.

BiDouiLle
Posts: 42
Joined: Wed Oct 17, 2012 7:45 am
Location: Corsica

Re: Intel QSV Codecs

Post by BiDouiLle » Sun Jan 15, 2017 3:02 pm

Hi Rkan,

It's a patch, seems it's not merged.

You have to apply it on ffmpeg sources.

Status about using libmfx dispatcher by lu_zero or native dispatcher provided by Intel Media SDK is not clear to me.

Anyway, qsv as of last version, is also able to encode/decode jpeg, vp8, vp9, mvc and even aac but is also able to do processing like inverse telecine, de-interlacing and scaling. It's a matter of wrapper in libmfx first and then ffmpeg implementation to support it.

QSV processors compatibility matrix

Intel® Media Software Development Kit 2016 R2 Release Notes

EDIT : added links to compatibility matrix and Media SDK 2016 R2 release note

rkan
Posts: 3
Joined: Tue Jan 12, 2016 9:10 am

Re: Intel QSV Codecs

Post by rkan » Tue Jan 17, 2017 5:58 am

I dunno where my problems are now... When using the webcam with OBS, it seems to work fine (once it gets enough light... :lol:), but no matter what I do with ffmpeg, I cannot get it to do anything else but to fill up the real-time buffer and stop transmitting. This can be probably disregarded as having any relation to Zeranoe itself, but something in ffmpeg..

To another problem on another CPU (Sandy Bridge i5-2520m). For some reason I now get "Unknown encoder 'h264_qsv'" when I try to run something with h264_qsv... I also cannot find it in the "ffmpeg -encoders" list. Now I did run this couple days ago and it was there. I haven't changed the build or anything, it just seems it's gone?? Anyone got anything to get me forwards?

BiDouiLle
Posts: 42
Joined: Wed Oct 17, 2012 7:45 am
Location: Corsica

Re: Intel QSV Codecs

Post by BiDouiLle » Wed Jan 18, 2017 7:30 pm

Are you using the i5-2520m with a discrete graphic card ? If yes, perhaps you need to ensure bios or uefi settings force it to present both to the OS

Also perhaps HD3000 need to have an attached monitor to enable QSV, I remember such stories using old core gen.

Post Reply