[メモ] FFmpeg で vcodec を hecv_qsv とした場合に hls で fMP4 の分割がされない件

スポンサーリンク

前のポスト Intel Media Server Studio 2017 R3 と FFmpegと Linux (CentOS 7.3 1611) で QSV (Quick Sync Video) では hevc_qsv でいわゆる普通の MP4 ファイルを生成できたのですが、hls の
fMP4 を生成できなかったという話。hecv_nvenc のほうでは問題ないので、ひとまず本件は放置。

  • Intel Media Server Studio 2017 R3
  • CentOS 7.3
  • FFmpeg (2017-08-11 の Snapshot)

hevc_qsv だと、m4s ファイルが分割されず、hevc0.m4s の 1 ファイルのみ作成されます。

ffmpeg -i sintel_trailer-1080p.mp4 -acodec copy -s 1920x1080 -vcodec hevc_qsv -init_hw_device qsv:hw -load_plugin hevc_hw -maxrate 50000k -b:v 11000k -threads 1 -f hls -hls_segment_type fmp4 -hls_time 2  /tmp/mokyu.m3u8

h264_qsv だと、hevc0.m4s, hevc1.m4s, hevc2.m4s, … とセグメント化されたファイルが作成されていきます。

ffmpeg -i sintel_trailer-1080p.mp4 -acodec copy -s 1920x1080 -vcodec h264_qsv -init_hw_device qsv:hw -load_plugin hevc_hw -maxrate 50000k -b:v 11000k -threads 1 -f hls -hls_segment_type fmp4 -hls_time 2  /tmp/mokyu.m3u8

少しソースを見てみました。

FFmpeg/FFmpeg
Mirror of git://source.ffmpeg.org/ffmpeg.git. Contribute to FFmpeg/FFmpeg development by creating an account on GitHub.

hlsenc.c に hls_write_packet という関数があり、can_split という変数があります。

can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
                    ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME));

で、hevc_qsv の場合は pkt->flags が常に 0 となってました。

h264_qsv は程良い間隔で can_split が 1 になってファイルがセグメント化されてました。

そのときの各変数の値は下記の通りで、どうも pkt->flags の部分が差異っぽいような。これ以上追っても徒労になりそうなのでここまで。

st->codecpar->codec_type= 0
AVMEDIA_TYPE_VIDEO = 0
pkt->flags = 1
AV_PKT_FLAG_KEY = 1

hevc_nvenc のほうがオプションも多いし・・・

ffmpeg -? encoder=hevc_nvenc
ffmpeg version N-86964-gf357104 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-11)
  configuration: --enable-libmfx
  libavutil      55. 73.100 / 55. 73.100
  libavcodec     57.102.100 / 57.102.100
  libavformat    57. 76.100 / 57. 76.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 98.100 /  6. 98.100
  libswscale      4.  7.102 /  4.  7.102
  libswresample   2.  8.100 /  2.  8.100
Encoder hevc_nvenc [NVIDIA NVENC hevc encoder]:
    General capabilities: delay 
    Threading capabilities: none
    Supported pixel formats: yuv420p nv12 p010le yuv444p yuv444p16le bgr0 rgb0 cuda
hevc_nvenc AVOptions:
  -preset            <int>        E..V.... Set the encoding preset (from 0 to 11) (default medium)
     default                      E..V.... 
     slow                         E..V.... hq 2 passes
     medium                       E..V.... hq 1 pass
     fast                         E..V.... hp 1 pass
     hp                           E..V.... 
     hq                           E..V.... 
     bd                           E..V.... 
     ll                           E..V.... low latency
     llhq                         E..V.... low latency hq
     llhp                         E..V.... low latency hp
     lossless                     E..V.... lossless
     losslesshp                   E..V.... lossless hp
  -profile           <int>        E..V.... Set the encoding profile (from 0 to 4) (default main)
     main                         E..V.... 
     main10                       E..V.... 
     rext                         E..V.... 
  -level             <int>        E..V.... Set the encoding level restriction (from 0 to 186) (default auto)
     auto                         E..V.... 
     1                            E..V.... 
     1.0                          E..V.... 
     2                            E..V.... 
     2.0                          E..V.... 
     2.1                          E..V.... 
     3                            E..V.... 
     3.0                          E..V.... 
     3.1                          E..V.... 
     4                            E..V.... 
     4.0                          E..V.... 
     4.1                          E..V.... 
     5                            E..V.... 
     5.0                          E..V.... 
     5.1                          E..V.... 
     5.2                          E..V.... 
     6                            E..V.... 
     6.0                          E..V.... 
     6.1                          E..V.... 
     6.2                          E..V.... 
  -tier              <int>        E..V.... Set the encoding tier (from 0 to 1) (default main)
     main                         E..V.... 
     high                         E..V.... 
  -rc                <int>        E..V.... Override the preset rate-control (from -1 to INT_MAX) (default -1)
     constqp                      E..V.... Constant QP mode
     vbr                          E..V.... Variable bitrate mode
     cbr                          E..V.... Constant bitrate mode
     vbr_minqp                    E..V.... Variable bitrate mode with MinQP (deprecated)
     ll_2pass_quality              E..V.... Multi-pass optimized for image quality (deprecated)
     ll_2pass_size                E..V.... Multi-pass optimized for constant frame size (deprecated)
     vbr_2pass                    E..V.... Multi-pass variable bitrate mode (deprecated)
     cbr_ld_hq                    E..V.... Constant bitrate low delay high quality mode
     cbr_hq                       E..V.... Constant bitrate high quality mode
     vbr_hq                       E..V.... Variable bitrate high quality mode
  -rc-lookahead      <int>        E..V.... Number of frames to look ahead for rate-control (from 0 to INT_MAX) (default 0)
  -surfaces          <int>        E..V.... Number of concurrent surfaces (from 0 to 64) (default 0)
  -cbr               <boolean>    E..V.... Use cbr encoding mode (default false)
  -2pass             <boolean>    E..V.... Use 2pass encoding mode (default auto)
  -gpu               <int>        E..V.... Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on. (from -2 to INT_MAX) (default any)
     any                          E..V.... Pick the first device available
     list                         E..V.... List the available devices
  -delay             <int>        E..V.... Delay frame output by the given amount of frames (from 0 to INT_MAX) (default INT_MAX)
  -no-scenecut       <boolean>    E..V.... When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts (default false)
  -forced-idr        <boolean>    E..V.... If forcing keyframes, force them as IDR frames. (default false)
  -spatial_aq        <boolean>    E..V.... set to 1 to enable Spatial AQ (default false)
  -temporal_aq       <boolean>    E..V.... set to 1 to enable Temporal AQ (default false)
  -zerolatency       <boolean>    E..V.... Set 1 to indicate zero latency operation (no reordering delay) (default false)
  -nonref_p          <boolean>    E..V.... Set this to 1 to enable automatic insertion of non-reference P-frames (default false)
  -strict_gop        <boolean>    E..V.... Set 1 to minimize GOP-to-GOP rate fluctuations (default false)
  -aq-strength       <int>        E..V.... When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive) (from 1 to 15) (default 8)
  -cq                <float>      E..V.... Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control (from 0 to 51) (default 0)
  -aud               <boolean>    E..V.... Use access unit delimiters (default false)
  -bluray-compat     <boolean>    E..V.... Bluray compatibility workarounds (default false)
  -init_qpP          <int>        E..V.... Initial QP value for P frame (from -1 to 51) (default -1)
  -init_qpB          <int>        E..V.... Initial QP value for B frame (from -1 to 51) (default -1)
  -init_qpI          <int>        E..V.... Initial QP value for I frame (from -1 to 51) (default -1)
  -qp                <int>        E..V.... Constant quantization parameter rate control method (from -1 to 51) (default -1)
  -weighted_pred     <int>        E..V.... Set 1 to enable weighted prediction (from 0 to 1) (default 0)
ffmpeg -? encoder=hevc_qsv
ffmpeg version N-86964-gf357104 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-11)
  configuration: --enable-libmfx
  libavutil      55. 73.100 / 55. 73.100
  libavcodec     57.102.100 / 57.102.100
  libavformat    57. 76.100 / 57. 76.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 98.100 /  6. 98.100
  libswscale      4.  7.102 /  4.  7.102
  libswresample   2.  8.100 /  2.  8.100
Encoder hevc_qsv [HEVC (Intel Quick Sync Video acceleration)]:
    General capabilities: delay 
    Threading capabilities: none
    Supported pixel formats: nv12 p010le qsv
hevc_qsv encoder AVOptions:
  -async_depth       <int>        E..V.... Maximum processing parallelism (from 0 to INT_MAX) (default 4)
  -avbr_accuracy     <int>        E..V.... Accuracy of the AVBR ratecontrol (from 0 to INT_MAX) (default 0)
  -avbr_convergence  <int>        E..V.... Convergence of the AVBR ratecontrol (from 0 to INT_MAX) (default 0)
  -preset            <int>        E..V.... (from 1 to 7) (default medium)
     veryfast                     E..V....
     faster                       E..V....
     fast                         E..V....
     medium                       E..V....
     slow                         E..V....
     slower                       E..V....
     veryslow                     E..V....
  -vcm               <int>        E..V.... Use the video conferencing mode ratecontrol (from 0 to 1) (default 0)
  -rdo               <int>        E..V.... Enable rate distortion optimization (from -1 to 1) (default -1)
  -max_frame_size    <int>        E..V.... Maximum encoded frame size in bytes (from -1 to 65535) (default -1)
  -max_slice_size    <int>        E..V.... Maximum encoded slice size in bytes (from -1 to 65535) (default -1)
  -bitrate_limit     <int>        E..V.... Toggle bitrate limitations (from -1 to 1) (default -1)
  -mbbrc             <int>        E..V.... MB level bitrate control (from -1 to 1) (default -1)
  -extbrc            <int>        E..V.... Extended bitrate control (from -1 to 1) (default -1)
  -adaptive_i        <int>        E..V.... Adaptive I-frame placement (from -1 to 1) (default -1)
  -adaptive_b        <int>        E..V.... Adaptive B-frame placement (from -1 to 1) (default -1)
  -b_strategy        <int>        E..V.... Strategy to choose between I/P/B-frames (from -1 to 1) (default -1)
  -cavlc             <int>        E..V.... Enable CAVLC (from 0 to 1) (default 0)
  -load_plugin       <int>        E..V.... A user plugin to load in an internal session (from 0 to 2) (default hevc_sw)
     none                         E..V....
     hevc_sw                      E..V....
     hevc_hw                      E..V....
  -load_plugins      <string>     E..V.... A :-separate list of hexadecimal plugin UIDs to load in an internal session (default "")
  -profile           <int>        E..V.... (from 0 to INT_MAX) (default unknown)
     unknown                      E..V....
     main                         E..V....
     main10                       E..V....
     mainsp                       E..V....
FFmpeg
スポンサーリンク
コピペワールド