3
0

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

Last updated at Posted at 2023-12-12

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 の名前。

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

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

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

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

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

連番だと何が返ってくる?

playblastを画像連番で出すと戻り値はなんじゃろか?

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
デスクトップに書き出すのはやめておこう

まだ次回へ続きます。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0