时光流逝 发表于 2020-10-19 10:30:15

使用libx265转码和cenc加密的mp4,ffpay播放失败

本帖最后由 时光流逝 于 2020-10-19 10:32 编辑

我在ubuntu下编译了ffmpeg 4.2, configure参数 --enable-libx264 --enable-libx265 --enable-gpl --enable-shared --enable-pthreads。做了以下测试:
(1)
h264转码并使用cenc加密
      ffmpeg -i input -vcodec libx264 -acodec copy-encryption_scheme cenc-aes-ctr -encryption_key xxxxxxxxx -encryption_kid xxxxxxxxx output.mp4
之后在windows下使用zeranoe提供的bin播放
      ffplay -i output.mp4 -decryption_key xxxxxxxxx
这样是可以成功播放的,去掉解密参数播放失败,说明cenc是生效的。
(2)
h265转码
       ffmpeg -i input -vcodec libx265 -acodec copy output.mp4
cenc加密
         ffmpeg -i output.mp4 -c copy -encryption_scheme cenc-aes-ctr -encryption_key xxxxxxxxx -encryption_kid xxxxxxxxx output_encrypted.mp4
之后在windows下播放      ffplay -i output_encrypted.mp4 -decryption_key xxxxxxxxx 可以正常播放。(3)h265转码并使用cenc加密      ffmpeg -i input -vcodec libx265 -acodec copy-encryption_scheme cenc-aes-ctr -encryption_key xxxxxxxxx -encryption_kid xxxxxxxxx output.mp4之后在windows下播放      ffplay -i output.mp4 -decryption_key xxxxxxxxx 播放失败。
ffplay打印的log信息如下:libavutil      55. 78.100 / 55. 78.100
libavcodec   57.107.100 / 57.107.100
libavformat    57. 83.100 / 57. 83.100
libavdevice    57. 10.100 / 57. 10.100
libavfilter   6.107.100 /6.107.100
libswscale      4.8.100 /4.8.100
libswresample   2.9.100 /2.9.100
libpostproc    54.7.100 / 54.7.100
failed to read iv from the auxiliary info
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\test.mp4':
Metadata:
    major_brand   : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.29.100
Duration: 00:00:10.09, bitrate: 884 kb/s
    Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 1920x1080 , 743 kb/s, 23 fps, 23 tbr, 11776 tbn, 23 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
auxiliary info offset 8 greater than auxiliary info size 0d=   0 aq=    0KB vq=    0KB sq=    0B f=0/0
auxiliary info offset 16 greater than auxiliary info size 0
auxiliary info offset 24 greater than auxiliary info size 0
auxiliary info offset 32 greater than auxiliary info size 0
auxiliary info offset 40 greater than auxiliary info size 0
auxiliary info offset 48 greater than auxiliary info size 0
auxiliary info offset 56 greater than auxiliary info size 0
auxiliary info offset 64 greater than auxiliary info size 0
auxiliary info offset 72 greater than auxiliary info size 0
auxiliary info offset 80 greater than auxiliary info size 0
auxiliary info offset 88 greater than auxiliary info size 0
auxiliary info offset 96 greater than auxiliary info size 0
auxiliary info offset 104 greater than auxiliary info size 0
......
这里不明白为什么会 failed to read iv from the auxiliary info,之后auxiliary info就一直是报错状态。我在ffmpeg里打log,看了下movenccenc的处理流程,auxiliary info的alloc和write都没有报错Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/d/test_h265.mp4':
Metadata:
    major_brand   : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.29.100
Duration: 00:00:10.09, start: 0.000000, bitrate: 1219 kb/s
    Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 1920x1080 , 1081 kb/s, 23 fps, 23 tbr, 11776 tbn, 23 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
File '/mnt/d/test.mp4' already exists. Overwrite ? y
Stream mapping:
Stream #0:0 -> #0:0 (hevc (native) -> hevc (libx265))
Stream #0:1 -> #0:1 (copy)
Press to stop, [?] for help
x265 : HEVC encoder version 3.2
x265 : build info 8bit+10bit+12bit
x265 : using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 : Main profile, Level-4 (Main tier)
x265 : Thread pool created using 4 threads
x265 : Slices                              : 1
x265 : frame threads / pool features       : 2 / wpp(17 rows)
x265 : Coding QT: max CU size, min CU size : 64 / 8
x265 : Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 : ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 : Keyframe min / max / scenecut / bias: 23 / 250 / 40 / 5.00
x265 : Lookahead / bframes / badapt      : 20 / 4 / 2
x265 : b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 : References / ref-limitcu / depth: 3 / off / on
x265 : AQ: mode / str / qg-size / cu-tree: 2 / 1.0 / 32 / 1
x265 : Rate Control / qCompress            : CRF-28.0 / 0.60
x265 : tools: rd=3 psy-rd=2.00 early-skip rskip signhide tmvp b-intra
x265 : tools: strong-intra-smoothing lslices=6 deblock sao
----------->ff_mov_cenc_init
    Last message repeated 1 times
Output #0, mp4, to '/mnt/d/test.mp4':
Metadata:
    major_brand   : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.29.100
    Stream #0:0(und): Video: hevc (libx265) (hev1 / 0x31766568), yuv420p, 1920x1080 , q=2-31, 23 fps, 11776 tbn, 23 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.54.100 libx265
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 130 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
----------->ff_mov_cenc_write_packet
----------->mov_cenc_start_packet
----------->auxiliary_info_write
----------->auxiliary_info_add_subsample
----------->mov_cenc_write_encrypted
----------->mov_cenc_end_packet
----------->ff_mov_cenc_write_packet
----------->mov_cenc_start_packet
----------->auxiliary_info_write
----------->auxiliary_info_add_subsample
----------->mov_cenc_write_encrypted
----------->mov_cenc_end_packet
......
encryption_kid这个参数的意义不是太理解,看文档感觉是一个描述id么?我在libx264时改动这个参数并不影响解密播放,没有搞清楚是不我在编码和加密指令上用错了参数或是libx265的问题导致的解密播放失败,麻烦各位大佬给看看,谢谢







时光流逝 发表于 2020-10-19 10:50:05

更新了zeranoe发布的bin到4.3,提示的错误是
moov atom not found0
D:\test.mp4: Invalid data found when processing input
页: [1]
查看完整版本: 使用libx265转码和cenc加密的mp4,ffpay播放失败