Export mp4 from maya using ffmpeg

** Preparation **

** 1. Download ffmpeg. ** **

[Windows] Procedure to install FFmpeg https://fukatsu.tech/windows-ffmpeg

Download ffmpeg referring to the above page and set environment variables.

** 2. Install ffmpeg-python **

pip install ffmpeg-python

Use pip to install ffmpeg-python, a library of ffmpeg for python.

Package management in Maya-try putting pip in mayapy https://qiita.com/it_ks/items/664f56d5e203ec005ca4

See above for how to install pip

** Run **

When you execute the following code in maya, playblast will be exported as uncompressed AVI and the AVI will be converted to mp4 immediately. AVI will be deleted automatically after conversion to mp4.

# -*- coding: utf-8 -*-

import maya.cmds as cmds
import ffmpeg
import os

#Specifying the export destination
mp4 = "D:/test.mp4"
avi = mp4.replace("mp4", "avi")
#Export play blast
cmds.playblast(fp=4, offScreen=1,
               clearCache=1, format='avi', sequenceTime=0,
               showOrnaments=0, percent=100,
               filename=avi, viewer=0,
               compression="None", quality=100, widthHeight=(500, 500),
               fo=1)
#Convert AVI to mp4 using ffmpeg
stream = ffmpeg.input(avi)
stream = ffmpeg.output(stream, mp4, pix_fmt='yuv420p', vcodec='libx264')
stream = ffmpeg.overwrite_output(stream)
ffmpeg.run(stream)
#Delete AVI
os.remove(avi)

error

In my environment, I got the following error when reading ffmpeg. 2019-11-08_17h39_29.png Apparently, the cause is that the file under lib2to3 of python27.zip cannot be opened (cannot be decompressed?). It seems that you can download lib2to3 from python github, so download it C: \ Program Files \ Autodesk \ Maya version \ Python \ Lib \ site-packages After moving to, it started to work.

Recommended Posts

Export mp4 from maya using ffmpeg
Maya FBX Export command
Convert pixiv to mp4 and download from pixiv using python's pixivpy
Flatten using Python yield from
Export 3D data from QGIS
Get clipboard from Maya settings
Operate Maya from an external Python interpreter using the rpyc module