4
0

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

Last updated at Posted at 2023-12-10

mayaのプレイブラスト mov標準でサポートされなくなったので、
とりあえず非圧縮aviで書き出す事が多いんですが

おっもーいので、色々不便。

追記
Qtコーデックを別途インストールすれば書き出せるようになるそうです
https://3dcg.comaroku.com/maya-playblast-mov/#toc2

mp4にしたい

何でもいいっちゃいいのですが、一旦mp4で。
色々調べると ffmepgっていうので変換できるらしい
https://ffmpeg.org/

昔からあるよなーって思ってたけど2000年からなのかー
2000年が23年前っていう事実のほうがビックリ
https://ja.wikipedia.org/wiki/FFmpeg

流れを考える

ffmepgさんは動画・連番ファイル両方に対応してるので

  • mayaでプレイブラストする
  • 出力された動画をffmepgさんにmp4化してもらう

雑に考えるとこんな感じですかね

動画を変換してもらう

まずはffmepg単体でテスト
古いだけあって、割と先人たちの知恵がいっぱいありますね。
ffmpeg-pythonも併用して

参考
https://qiita.com/studio_haneya/items/a2a6664c155cfa90ddcf

import ffmpeg

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)

inputFilePath = "C:/Users/kubo/Desktop/trail.avi"
fileType = "mp4"
codec = "h264"
inputMovie(inputFilePath,fileType,codec)

お、できましたわね。

image.png

mayaで使えるようにする

参考
https://qiita.com/lie_871221/items/367437a711ee0acb67ce

ffmepgのインストールがなぁ・・・
と色々と考えた結果
環境変数に一時的に足してしまえば行けんじゃねぇ?という雑頭の発想

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

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)

inputFilePath = "C:/Users/kubo/Desktop/trail.avi"
fileType = "mp4"
codec = "h264"
inputMovie(inputFilePath,fileType,codec)

うん できたけども、これはなんかモヤっとしたので、
mayaの起動batにて指定することにしました。

続きは次回へ

4
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
4
0