Flow-Developers

Raspberry Pi, Raspbian, python, ROS, IoT, 電子工作, 機械学習, Deep learning, サッカー, スポーツ写真, ライフハック

FFmpegでRGBA-uint16をProRes4444で圧縮すると, DaVinci Resolve上ではfloat32(0.0-1.0[0-65535))の4chで扱える

FFmpegでRGBA-uint16をProRes4444で圧縮すると, DaVinci Resolve上ではfloat32(0.0-1.0[0-65535))の4chで扱える

f:id:flow-dev:20200628152954j:plain

内容

  • DaVinci Resolveで16bitのRGBA(4ch)を扱うためには, FFmpegでRGBA-uint16をProRes4444で圧縮する
  • FFmpegでRGBA-uint16をProRes4444で圧縮することで, DaVinci Resolve上ではfloat32(0.0-1.0[0-65535))の4chで扱える


sample code

  • ProRes4444の仕様は,RGB(12bit),A(最大16bit)ですが,DaVinci Resolveは以下のようにProRes4444を書き込むとDaVinci Resolve上ではfloat32(0.0-1.0[0-65535))の4chで扱えました
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import cv2
import numpy as np
import skvideo.io

if __name__ == '__main__':
    
    images = []

    # test frames(16bit gray png)  
    image_test_01 = cv2.imread("image_test_01.png",0) #16bit_gray_png
    image_test_02 = cv2.imread("image_test_02.png",0) #16bit_gray_png
    image_test_03 = cv2.imread("image_test_03.png",0) #16bit_gray_png

    # append array
    images.append(image_test_01)
    images.append(image_test_02)
    images.append(image_test_03)

    outputfile = "rgba_4ch_uint16.mov"
    
    # ffmpeg prores4444 rgba
        writer = skvideo.io.FFmpegWriter(outputfile, inputdict={}, outputdict={'-r': str(fps), '-codec:v': 'prores_ks', '-pix_fmt': 'rgba', '-profile:v': '4444', '-bits_per_mb': '8000', '-vendor': 'ap10', '-vf': 'scale=in_color_matrix=bt709:out_color_matrix=bt709'})
    
    # 1ch_16bit to 4ch_16bit
    for i in range(len(images)):
            tmp = np.full_like(images[i], 0).astype(np.uint8)
                rgba = cv2.cvtColor(tmp, cv2.COLOR_GRAY2RGBA) #1ch -> 4ch
                rgba = rgba.astype(np.uint16) #uint8 -> uint16
                rgba[:,:,0] = np.full_like(images[i], 65535).astype(np.uint16) # R(uint16)
                rgba[:,:,1] = np.full_like(images[i], 65535).astype(np.uint16) # G(uint16)
                rgba[:,:,2] = np.full_like(images[i], 65535).astype(np.uint16) # B(uint16)
                rgba[:,:,3] = images[i].astype(np.uint16)                      # A(uint16)
                frame = rgba
            writer.writeFrame(frame)
        writer.close()

参考リンク

Encode/VFX – FFmpeg

Video into ProRes

stackoverflow.com

ffmpegでAVC-Intraを作る

flow-developers.hatenablog.com

https://documents.blackmagicdesign.com/SupportNotes/DaVinci_Resolve_15_Supported_Codec_List.pdf