Skip to content

Commit

Permalink
Merge pull request #534 from deuteronomy-works/master
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
amoh-godwin authored Oct 15, 2022
2 parents f5a09ce + dfc22d2 commit 020ee16
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pyffmpeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
fh.setLevel(logging.DEBUG)
ch.setLevel(logging.DEBUG)

formatter = logging.Formatter('%(asctime) - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)

Expand All @@ -49,6 +49,7 @@ def __init__(self, directory="."):
self.logger = logging.getLogger('pyffmpeg.FFmpeg')
self.logger.info('FFmpeg Initialising')
self.save_dir = directory
self.logger.info(f"Save directory: {self.save_dir}")
self.overwrite = True
self.loglevels = (
'quiet', 'panic', 'fatal', 'error', 'warning',
Expand All @@ -69,6 +70,7 @@ def __init__(self, directory="."):
# instances are store according to function names
self._ffmpeg_instances = {}
self._ffmpeg_file = Paths().load_ffmpeg_bin()
self.logger.info(f"FFmpeg file: {self._ffmpeg_file}")
self.error = ''

def convert(self, input_file, output_file):
Expand All @@ -77,14 +79,18 @@ def convert(self, input_file, output_file):
Converts and input file to the output file
"""

self.logger.info('Inside convert function')
if os.path.isabs(output_file):
# absolute file
out = output_file
else:
# not an absolute file
out = os.path.join(self.save_dir, output_file)

self.logger.info(f"Output file: {out}")

inf = input_file.replace("\\", "/")
self.logger.info(f"Input file: {inf}")

if self.loglevel not in self.loglevels:
msg = 'Warning: "{}" not an ffmpeg loglevel flag.' +\
Expand All @@ -96,6 +102,9 @@ def convert(self, input_file, output_file):
options = options.format(self._ffmpeg_file, self.loglevel)
options += '{} -i'
options = options.format(self._over_write)

self.logger.info(f"shell: {SHELL}")

if SHELL:
options += ' "{}" "{}"'.format(inf, out)
else:
Expand All @@ -114,6 +123,7 @@ def convert(self, input_file, output_file):
)
self._ffmpeg_instances['convert'] = outP
self.error = str(outP.stderr.read(), 'utf-8')
self.logger.info(f"error message length: {len(self.error)}")
return out

def get_ffmpeg_bin(self):
Expand All @@ -122,13 +132,15 @@ def get_ffmpeg_bin(self):
Get the ffmpeg executable file. This is the fullpath to the
binary distributed with pyffmpeg. There is only one at a time.
"""
self.logger.info("Inside get_ffmpeg_bin")

return self._ffmpeg_file

def get_fps(self, input_file):
"""
Returns the frame per second rate of an input file
"""
self.logger.info("Inside get_fps")
fprobe = FFprobe(input_file)
fps = fprobe.fps
return fps
Expand All @@ -139,6 +151,7 @@ def monitor(self, fn: str):
m_thread.start()

def _monitor(self, fn: str):
self.logger.info('Monitoring spirit started')
sleep(1)
dura = 0.0
while dura < self._in_duration:
Expand All @@ -159,8 +172,10 @@ def options(self, opts):
eg.: command line options of 'ffmpeg -i a.mp4 b.mp3'
will be passed by user as: opts: '-i a.mp4 b.mp3'
"""
self.logger.info("inside options")

if isinstance(opts, list):
self.logger.info('Options is a List')
options = fix_splashes(opts)

# Add ffmpeg and overwrite variable
Expand All @@ -175,6 +190,7 @@ def options(self, opts):
options = ' '.join(['-loglevel', self.loglevel, options])

else:
self.logger.info('Options is a String')
options = opts

# Add ffmpeg and overwrite variable
Expand All @@ -198,6 +214,8 @@ def options(self, opts):
# add ffmpeg
options = " ".join([self._ffmpeg_file, options])

self.logger.info(f"Shell: {SHELL}")

if not SHELL:
options = shlex.split(options, posix=False)

Expand All @@ -224,8 +242,10 @@ def quit(self, function: Optional[str] = ''):
Allows for any running process of ffmpeg started by pyffmpeg
to be terminated
"""
self.logger.info('Inside Quit')

if function:
self.logger.info('There is a function for Quit: {function}')
inst = self._ffmpeg_instances[function]
output = inst.communicate(b'q')
# Quit all instances
Expand Down

0 comments on commit 020ee16

Please sign in to comment.