Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)
(시리즈 글이 7개 있습니다.)
.NET Framework: 288. FFmpeg.exe를 이용한 C# 동영상 인코더 예제
; https://www.sysnet.pe.kr/2/0/1210

개발 환경 구성: 622. vcpkg로 ffmpeg를 빌드하는 경우 생성될 구성 요소 제어하는 방법
; https://www.sysnet.pe.kr/2/0/12900

개발 환경 구성: 623. ffmpeg.exe를 사용해 비디오 파일의 이미지를 PGM(Portable Gray Map) 파일 포맷으로 출력하는 방법
; https://www.sysnet.pe.kr/2/0/12912

개발 환경 구성: 626. ffmpeg.exe를 사용해 비디오 파일을 MPEG1 포맷으로 변경하는 방법
; https://www.sysnet.pe.kr/2/0/12923

개발 환경 구성: 634. ffmpeg.exe - 기존 동영상 컨테이너에 다중 스트림을 추가하는 방법
; https://www.sysnet.pe.kr/2/0/12947

개발 환경 구성: 636. ffmpeg.exe를 이용해 planar 포맷의 데이터를 packed 형식으로 변환하는 방법?
; https://www.sysnet.pe.kr/2/0/12957

개발 환경 구성: 639. ffmpeg.exe - Intel Quick Sync Video(qsv)를 이용한 인코딩
; https://www.sysnet.pe.kr/2/0/12973




ffmpeg.exe - Intel Quick Sync Video(qsv)를 이용한 인코딩

제 CPU는 Intel 12900K인데 아래의 문서에 의하면,

Access the power of hardware accelerated video codecs in your Windows applications via FFmpeg / libavcodec
; https://habr.com/en/company/intel/blog/575632/

2011년부터의 모든 Intel GPU에는 Intel QSV(Quick Sync Video)라는 인코딩/디코딩을 위한 하드웨어 코어가 장착되어 있다고 합니다. 그리고, ffmpeg의 경우 2.8 버전부터 이를 지원한다고 하는데요, 그렇다면 근래의 4.4 버전의 ffmpeg라면 qsv 사용이 가능하다는 이야기인데, "Access the power of hardware accelerated video codecs in your Windows applications via FFmpeg / libavcodec" 글을 읽어보면 ffmpeg가 qsv를 지원하도록 빌드되었는지 확인하라고 합니다.

  • For QSV based decoding on Windows OS either DXVA2 (Direct-X Video Acceleration API) or D3D11VA (Direct 3D 11 Video API) support is required.
  • For QSV based encoding libmfx (Intel proprietary library that provides hardware based video encoding) support is required.

우선, vcpkg로 빌드한 ffmpeg는 "--enable-dxva2 --enable-d3d11va --enable-libmfx" 옵션을 포함한 버전이 아닙니다.

C:\temp> ffmpeg -hwaccels
ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with Microsoft (R) C/C++ Optimizing Compiler Version 19.30.30705 for x64
  configuration: --prefix=/e/git_clone/vcpkg/packages/ffmpeg_x64-windows --toolchain=msvc --enable-pic --disable-doc 
  --enable-debug --enable-runtime-cpudetect --enable-asm --enable-x86asm --enable-nonfree --enable-gpl --enable-ffmpeg 
  --enable-ffplay --enable-ffprobe --disable-alsa --enable-avcodec --enable-avdevice --enable-avformat --enable-avfilter 
  --enable-postproc --enable-swresample --enable-swscale --disable-libaom --disable-libass --disable-avisynth 
  --disable-bzlib --disable-libdav1d --disable-libfdk-aac --disable-libfontconfig --disable-libfreetype 
  --disable-libfribidi --disable-iconv --disable-libilbc --disable-lzma --disable-libmp3lame --disable-libmodplug 
  --enable-cuda --enable-nvenc --enable-nvdec --enable-cuvid --enable-ffnvcodec --enable-opencl --disable-opengl 
  --disable-libopenh264 --disable-libopenjpeg --disable-openssl --disable-libopus --enable-sdl2 --disable-libsnappy 
  --disable-libsoxr --disable-libspeex --disable-libssh --disable-libtensorflow --disable-libtesseract --disable-libtheora 
  --disable-libvorbis --disable-libvpx --disable-libwebp --disable-libx264 --disable-libx265 --disable-libxml2 
  --disable-zlib --disable-static --enable-shared --extra-cflags='-DHAVE_UNISTD_H=0' --extra-cflags=-MD --extra-cxxflags=-MD
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Hardware acceleration methods:
cuda
dxva2
d3d11va
opencl

따라서 h264_qsv를 이용해 동영상을 트랜스코딩하면 그냥 h264_qsv를 지원하지 않는다고 나옵니다.

d:\media_sample> ffmpeg -i theade-i-was-young.mp4 -q 0 -vcodec h264_qsv out_qsv.mp4
...[생략]...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'theade-i-was-young.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:03:08.01, start: 0.000000, bitrate: 575 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], 439 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
Unknown encoder 'h264_qsv'




반면, 다음의 사이트에서 배포하는 ffmpeg.exe의 경우,

CODEX FFMPEG - ffmpeg-release-essentials.zip 77MB
; https://www.gyan.dev/ffmpeg/builds/

(FFmpeg.AutoGen에서도 쓰고 있는 GPL 라이선스의 버전입니다.)

아래와 같이 qsv 지원이 포함돼 있습니다.

c:\temp> ffmpeg -codecs | findstr qsv
ffmpeg version 5.0-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 11.2.0 (Rev5, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig
        --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt 
        --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 
        --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype 
        --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm 
        --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx 
        --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora 
        --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex 
        --enable-libvorbis --enable-librubberband
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
 DEV.L. av1                  Alliance for Open Media AV1 (decoders: libaom-av1 av1 av1_cuvid av1_qsv ) (encoders: libaom-av1 )
 DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_qsv h264_cuvid ) (encoders: libx264 libx264rgb h264_amf h264_nvenc h264_qsv )
 DEV.L. hevc                 H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_qsv hevc_cuvid ) (encoders: libx265 hevc_amf hevc_nvenc hevc_qsv )
 DEVIL. mjpeg                Motion JPEG (decoders: mjpeg mjpeg_cuvid mjpeg_qsv ) (encoders: mjpeg mjpeg_qsv )
 DEV.L. mpeg2video           MPEG-2 video (decoders: mpeg2video mpegvideo mpeg2_qsv mpeg2_cuvid ) (encoders: mpeg2video mpeg2_qsv )
 D.V.L. vc1                  SMPTE VC-1 (decoders: vc1 vc1_qsv vc1_cuvid )
 DEV.L. vp8                  On2 VP8 (decoders: vp8 libvpx vp8_cuvid vp8_qsv ) (encoders: libvpx )
 DEV.L. vp9                  Google VP9 (decoders: vp9 libvpx-vp9 vp9_cuvid vp9_qsv ) (encoders: libvpx-vp9 vp9_qsv )

c:\temp> ffmpeg -hwaccels
...[생략]...
Hardware acceleration methods:
cuda
dxva2
qsv
d3d11va

이와 함께, 컴퓨터에 Intel CPU의 사용 준비가 되었으면,

Intel CPU의 내장 그래픽 GPU가 작업 관리자에 없다면?
; https://www.sysnet.pe.kr/2/0/12972

이번에는 트랜스코딩이 잘 됩니다.

d:\media_sample> ffmpeg -i theade-i-was-young.mp4 -q 0 -vcodec h264_qsv out_qsv.mp4 
...[생략]...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'd:\media_sample\theade-i-was-young.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:03:08.01, start: 0.000000, bitrate: 575 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 640x360 [SAR 1:1 DAR 16:9], 439 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_qsv))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, mp4, to 'out_qsv.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.16.100
  Stream #0:0(und): Video: h264 (avc1 / 0x31637661), nv12(tv, bt709, progressive), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 1000 kb/s, 29.97 fps, 30k tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.18.100 h264_qsv
    Side data:
      cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: N/A
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.18.100 aac
frame= 5633 fps=1102 q=3.0 Lsize=  215290kB time=00:03:08.01 bitrate=9380.5kbits/s speed=36.8x
video:212397kB audio:2687kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.095878%
[aac @ 000002437d25cd40] Qavg: 120.000

d:\media_sample> ffprobe out_qsv.mp4 
...[생략]...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out_qsv.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.16.100
  Duration: 00:03:08.01, start: 0.000000, bitrate: 9380 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 640x360 [SAR 1:1 DAR 16:9], 9257 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 117 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 4/6/2022]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2022-02-17 10시08분
[이승준] 트랜스코딩을 하면서 다른작업을 많이 할 경우가 아니라면 가급적 퀵싱크는 사용을 안하는것이 좋습니다.
화질에 따른 성능 순서가 libx264 > h264_nvenc > Intel QuickSync 순서 입니다.
Media Foundation이랑 AMD AMF는 비교적 최근에 들어간 옵션이라 제가 화질까지는 테스트 해보지 못했습니다.
특히 인텔 코덱이 중저 비트레이트에서 화질이 많이 취약하고 qp나 crf, abr, vbr등의 옵션이 좀 취약합니다.

추가로 이게 많이 거슬리는 점인데. 코덱별로 qp, crf, cbr, avr, vbr 옵션 설정이 다 다릅니다.
그나마 *br 계열은 비슷한데. qp랑 crf는 옵션이 판이하게 다릅니다.
[guest]
2022-02-17 04시21분
ffmpeg에 qsvdec.c 소스코드를 포팅하면서 한번 테스트를 한 것인데, 잘 쓰이지 않는다니 다행(?)입니다. ^^ 그 외에, qp, crf, abr, vbr 등의 이야기는 언젠가 이해할 날이 오겠지요. ^^
정성태
2022-02-17 09시39분
[guest] 저도 화명 촬영 기능 만들때 코덱종류?? h264_nvenc로 햇엇는데 이거 보니까 gpu 가 없으면 동작 안되는거같더군요... 그래서 libx264로 바꿔서 햇더니 잘됫던거같아요ㅋㅋㅋ
[guest]

... 106  107  [108]  109  110  111  112  113  114  115  116  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11224정성태6/13/201718187.NET Framework: 661. Json.NET의 DeserializeObject 수행 시 속성 이름을 동적으로 바꾸는 방법파일 다운로드1
11223정성태6/12/201716835개발 환경 구성: 318. WCF Service Application과 WCFTestClient.exe
11222정성태6/10/201720561오류 유형: 399. WCF - A property with the name 'UriTemplateMatchResults' already exists.파일 다운로드1
11221정성태6/10/201717536오류 유형: 398. Fakes - Assembly 'Jennifer5.Fakes' with identity '[...].Fakes, [...]' uses '[...]' which has a higher version than referenced assembly '[...]' with identity '[...]'
11220정성태6/10/201722917.NET Framework: 660. Shallow Copy와 Deep Copy [1]파일 다운로드2
11219정성태6/7/201718229.NET Framework: 659. 닷넷 - TypeForwardedFrom / TypeForwardedTo 특성의 사용법
11218정성태6/1/201721040개발 환경 구성: 317. Hyper-V 내의 VM에서 다시 Hyper-V를 설치: Nested Virtualization
11217정성태6/1/201716920오류 유형: 397. initerrlog: Could not open error log file 'C:\...\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG'
11216정성태6/1/201719042오류 유형: 396. Activation context generation failed
11215정성태6/1/201719995오류 유형: 395. 관리 콘솔을 실행하면 "This app has been blocked for your protection" 오류 발생 [1]
11214정성태6/1/201717707오류 유형: 394. MSDTC 서비스 시작 시 -1073737712(0xC0001010) 오류와 함께 종료되는 문제 [1]
11213정성태5/26/201722497오류 유형: 393. TFS - The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
11212정성태5/26/201721830오류 유형: 392. Windows Server 2016에 KB4019472 업데이트가 실패하는 경우
11211정성태5/26/201720864오류 유형: 391. BeginInvoke에 전달한 람다 함수에 CS1660 에러가 발생하는 경우
11210정성태5/25/201721312기타: 65. ActiveX 없는 전자 메일에 사용된 "개인정보 보호를 위해 암호화된 보안메일"의 암호화 방법
11209정성태5/25/201768244Windows: 143. Windows 10의 Recovery 파티션을 삭제 및 새로 생성하는 방법 [16]
11208정성태5/25/201727970오류 유형: 390. diskpart의 set id 명령어에서 "The specified type is not in the correct format." 오류 발생
11207정성태5/24/201728292Windows: 142. Windows 10의 복구 콘솔로 부팅하는 방법
11206정성태5/24/201721575오류 유형: 389. DISM.exe - The specified image in the specified wim is already mounted for read/write access.
11205정성태5/24/201721274.NET Framework: 658. C#의 tail call 구현은? [1]
11204정성태5/22/201730810개발 환경 구성: 316. 간단하게 살펴보는 Docker for Windows [7]
11203정성태5/19/201718742오류 유형: 388. docker - Host does not exist: "default"
11202정성태5/19/201719810오류 유형: 387. WPF - There is no registered CultureInfo with the IetfLanguageTag 'ug'.
11201정성태5/16/201722567오류 유형: 386. WPF - .NET 3.5 이하에서 TextBox에 한글 입력 시 TextChanged 이벤트의 비정상 종료 문제 [1]파일 다운로드1
11200정성태5/16/201719355오류 유형: 385. WPF - 폰트가 없어 System.IO.FileNotFoundException 예외가 발생하는 경우
11199정성태5/16/201721173.NET Framework: 657. CultureInfo.GetCultures가 반환하는 값
... 106  107  [108]  109  110  111  112  113  114  115  116  117  118  119  120  ...