0

I'm using the ffmpeg-python library.

I have an input file object in_, e.g:

import ffmpeg

in_ = ffmpeg.input('video.mp4')

How can I later (after adding filters, etc) extract the original name of the file used from in_? I don't see anything in their docs detailing an existing attribute where I can access it (e.g. in_.filename) - does such an attribute (or another alternative) exist, apart from explicitly declaring the filename in a separate variable?

pigeonburger
  • 715
  • 7
  • 24

1 Answers1

0

After looking more into their code and classes, I came up with a short function that will always return the filename. The while loop is to get past the arbitrary number of filter objects that may have been applied to the input:

def getInputFilename(stream):
    while stream.node._KwargReprNode__incoming_edge_map != {}:
        stream = stream.node._KwargReprNode__incoming_edge_map[None][0]
        if not hasattr(stream, 'node'):
            return stream.__dict__['kwargs']['filename']
    return stream.node.__dict__['kwargs']['filename']

In full:

import ffmpeg

in_ = ffmpeg.input('video.mp4')

// Filters added here etc etc

def getInputFilename(stream):
    while stream.node._KwargReprNode__incoming_edge_map != {}:
        stream = stream.node._KwargReprNode__incoming_edge_map[None][0]
        if not hasattr(stream, 'node'):
            return stream.__dict__['kwargs']['filename']
    return stream.node.__dict__['kwargs']['filename']

print(getInputFilename(in_))

Output:

video.mp4

I know there's probably better ways to do it, but I'm too tired to find them

pigeonburger
  • 715
  • 7
  • 24