Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viewer=False removes file extension #51

Open
mottosso opened this issue Mar 16, 2016 · 8 comments
Open

viewer=False removes file extension #51

mottosso opened this issue Mar 16, 2016 · 8 comments
Labels

Comments

@mottosso
Copy link
Member

This bug is present in cmds.playblast too.

# On Windows, Maya 2015
fname = capture.capture()
print fname
# blast1.mov

fname = capture.capture(viewer=False)
print fname
# blast1
@mottosso mottosso added the bug label Mar 16, 2016
@BigRoy
Copy link
Collaborator

BigRoy commented May 13, 2016

Do you have any idea for a good solution to this? It's kind of holding me back on something and I want to avoid just "guessing" the extension?

@mottosso
Copy link
Member Author

Not directly, if you think of anything, PR's are welcome!

@BigRoy
Copy link
Collaborator

BigRoy commented May 13, 2016

It's a really tricky one, because there seems to be no way to really know the extension.

A way I'm thinking of is doing something like files = glob.glob(filename + ".*"). Then you could even filter further to those files that were created after the initial call of cmds.playblast(), but the "time" on the file's location could possibly differ if it's on a network storage than the local system time. And it feels so nasty! :D

@mottosso
Copy link
Member Author

I think there are only two options on output, film or image, where each have their own number of compressions.

Maybe we could build a dictionary of each combination and take control over that extension ourselves?

{
  "mov": {
    "h264": ".mov",
    "avi": ".avi"
  },
  "image": {
    "png": ".png",
    "tiff": ".tiff"
  }
}

@BigRoy
Copy link
Collaborator

BigRoy commented May 13, 2016

Could do yes, but there's quite a list of available options. Plus that it depends on the codecs that are installed on a system. So you might miss some that others might have but you don't.

To have a list of available options:

import maya.cmds as mc

def list_formats():
    import maya.cmds

    # Workaround for Maya playblast bug where undo would
    # move the currentTime to frame one.
    maya.cmds.currentTime(maya.cmds.currentTime(q=1))

    return maya.cmds.playblast(query=True, format=True)


def list_compressions(format):
    import maya.mel

    # Workaround for Maya playblast bug where undo would
    # move the currentTime to frame one.
    maya.cmds.currentTime(maya.cmds.currentTime(q=1))

    cmd = 'playblast -format "{0}" -query -compression'.format(format)
    return maya.mel.eval(cmd)


for format in list_formats():
    for compression in list_compressions(format):
        print format, compression

Another trick could be to instead of disabling the viewer argument you'd temporarily override the default applications that maya uses to open a playblasted file (you can set the image and sequence viewing applications in Maya). It's in Settings/Preferences > Preferences > Applications. Maybe you could point it to a fake viewer or none existing path so it doesn't actually open a viewer.

@BigRoy
Copy link
Collaborator

BigRoy commented Sep 12, 2016

A workaround we have put in place in production (even though it's quite a hack!) was the following:

import os
import glob
import logging

log = logging.getLogger(__name__)


def _fix_playblast_output_path(filepath):
    """Workaround a bug in maya.cmds.playblast to return correct filepath.

    When the `viewer` argument is set to False and maya.cmds.playblast does not
    automatically open the playblasted file the returned filepath does not have
    the file's extension added correctly.

    To workaround this we just glob.glob() for any file extensions and assume
    the latest modified file is the correct file and return it.

    """
    # Catch cancelled playblast
    if filepath is None:
        log.warning("Playblast did not result in output path. "
                    "Playblast is probably interrupted.")
        return

    # Fix: playblast not returning correct filename (with extension)
    # Lets assume the most recently modified file is the correct one.
    if not os.path.exists(filepath):
        files = glob.glob(filepath + ".*")
        if not files:
            raise RuntimeError("Couldn't find playblast from: "
                               "{0}".format(filepath))
        filepath = max(files, key=os.path.getmtime)

    return filepath

This has worked for video files perfectly. Haven't tested it with image sequences yet.
We needed this because we wanted to apply an overlay (through FFMPEG) just before the viewer would open. Posting this here as it could be of use to others if they need a current hack for this.

Unfortunately I still haven't found a way to have the maya.cmds.playblast command return the full path correctly when viewer is set to False.

@BigRoy
Copy link
Collaborator

BigRoy commented Sep 13, 2016

I have submitted this as a bug to Autodesk. The support ticket id is 12162349

@BigRoy
Copy link
Collaborator

BigRoy commented Sep 20, 2016

The Autodesk Support team was able to reproduce this issue on their end and they've submitted a change request to the dev team. Once there's any new information on that end I'll follow up here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants