mayaのプレイブラストをffmpegでmp4にしてみる2


mayaのプレイブラストをffmpegでmp4にしてみる
https://qiita.com/9boz/private/60c0aba7d92f14622a44

の続き

playblastの結果を取る
-
リファレンス曰く
https://help.autodesk.com/cloudhelp/2022/JPN/Maya-Tech-Docs/CommandsPython/playblast.html

>戻り値
>string	作成される moviefile の名前。

んじゃぁこれをそのまま渡せば・・・・

とりあえずプレイブラストを流すスクリプトを書く。

```python
import maya.cmds as cmds
import maya.api.OpenMayaUI as omui
import maya.OpenMayaUI as OpenMayaUI

def getCurViewPanel():
    curView = omui.M3dView.active3dView()
    return OpenMayaUI.MQtUtil.fullName(int(omui.M3dView.active3dView().widget())).split("|")[-2]
    
outputPath = "C:/Users/kubo/Desktop/hoge.avi"
start = cmds.playbackOptions(q =True, minTime=True)
end = cmds.playbackOptions(q =True, maxTime=True)
resolution = [
                cmds.getAttr("defaultResolution.width"),
                cmds.getAttr("defaultResolution.height")
            ]
            
panel = getCurViewPanel()           
result = cmds.playblast(
                        filename =outputPath,
                        forceOverwrite =True,
                        format = "movie",
                        compression = "none",
                        sequenceTime = False,
                        clearCache = 1,
                        viewer = False,
                        showOrnaments =  True,
                        offScreen = True,
                        fp = 4, 
                        percent = 100,
                        quality = 100,                        
                        startTime = start,
                        endTime = end,
                        widthHeight = resolution,
                        editorPanelName = panel                        
                    )

print(result)

## C:\Users\kubo\Desktop\hoge.avi

```

これを前回のやつと合体させて

```python
import sys
import os

ffmpegPath = "C:/Users/kubo/Documents/ffmpeg/bin"

if ffmpegPath not in os.environ["PATH"]:
    os.environ["PATH"] += ffmpegPath + ";"

ffmpegPyPath = "C:/Users/kubo/Documents/ffmpeg-python"

if ffmpegPyPath not in sys.path:
    sys.path.append(ffmpegPyPath)

import ffmpeg
import maya.cmds as cmds
import maya.api.OpenMayaUI as omui
import maya.OpenMayaUI as OpenMayaUI

def inputMovie(inputFilePath,fileType,codec):    
    inputVideoInfo = ffmpeg.probe(inputFilePath)["streams"][0]    
    outFilePath = os.path.splitext(inputFilePath)[0] + "." + fileType
    
    width = int(inputVideoInfo["width"])
    height = int(inputVideoInfo["height"])
    
    stream = ffmpeg.input(inputFilePath)
    stream = ffmpeg.filter(stream,'scale', -1, height)
    stream = ffmpeg.output(stream, outFilePath,vcodec=codec, pix_fmt= "yuv420p")    
    ffmpeg.run(stream,overwrite_output =True)

def getCurViewPanel():
    curView = omui.M3dView.active3dView()
    return OpenMayaUI.MQtUtil.fullName(int(omui.M3dView.active3dView().widget())).split("|")[-2]
    
def applyPlayblast(outputPath):
    start = cmds.playbackOptions(q =True, minTime=True)
    end = cmds.playbackOptions(q =True, maxTime=True)
    resolution = [
                    cmds.getAttr("defaultResolution.width"),
                    cmds.getAttr("defaultResolution.height")
                ]
                
    panel = getCurViewPanel()           
    result = cmds.playblast(
                            filename =outputPath,
                            forceOverwrite =True,
                            format = "movie",
                            compression = "none",
                            sequenceTime = False,
                            clearCache = 1,
                            viewer = False,
                            showOrnaments =  True,
                            offScreen = True,
                            fp = 4, 
                            percent = 100,
                            quality = 100,                        
                            startTime = start,
                            endTime = end,
                            widthHeight = resolution,
                            editorPanelName = panel                        
                        )

    fileType = "mp4"
    codec = "h264"
    inputMovie(result,fileType,codec)

outputPath = "C:/Users/kubo/Desktop/hoge.avi"
applyPlayblast(outputPath)

```

お　できましたわ！

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1484234/b2683280-9935-54e0-3603-c94e6f0f32d8.png)



連番だと何が返ってくる？
-
playblastを画像連番で出すと戻り値はなんじゃろか？

```python
import maya.cmds as cmds
import maya.api.OpenMayaUI as omui
import maya.OpenMayaUI as OpenMayaUI

def getCurViewPanel():
    curView = omui.M3dView.active3dView()
    return OpenMayaUI.MQtUtil.fullName(int(omui.M3dView.active3dView().widget())).split("|")[-2]
    
outputPath = "C:/Users/kubo/Desktop/hoge"
start = cmds.playbackOptions(q =True, minTime=True)
end = cmds.playbackOptions(q =True, maxTime=True)
resolution = [
                cmds.getAttr("defaultResolution.width"),
                cmds.getAttr("defaultResolution.height")
            ]
            
panel = getCurViewPanel()           
result = cmds.playblast(
                        filename =outputPath,
                        forceOverwrite =True,
                        format = "image",
                        compression = "png",
                        sequenceTime = False,
                        clearCache = 1,
                        viewer = False,
                        showOrnaments =  True,
                        offScreen = True,
                        fp = 4, 
                        percent = 100,
                        quality = 100,                        
                        startTime = start,
                        endTime = end,
                        widthHeight = resolution,
                        editorPanelName = panel                        
                    )

print(result)

#C:\Users\kubo\Desktop\hoge.####.png
```

なるほど連番・・・・・
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1484234/e9fca0d6-f153-503a-1ed9-6a143b9207de.png)
デスクトップに書き出すのはやめておこう

まだ次回へ続きます。