|
25 | 25 | import os
|
26 | 26 | from pathlib import Path
|
27 | 27 | import platform
|
| 28 | +import shutil |
28 | 29 | import subprocess
|
29 | 30 | import sys
|
30 | 31 | from tempfile import TemporaryDirectory
|
@@ -408,27 +409,9 @@ def bin_path(cls):
|
408 | 409 | @classmethod
|
409 | 410 | def isAvailable(cls):
|
410 | 411 | '''
|
411 |
| - Check to see if a MovieWriter subclass is actually available by |
412 |
| - running the commandline tool. |
| 412 | + Check to see if a MovieWriter subclass is actually available. |
413 | 413 | '''
|
414 |
| - bin_path = cls.bin_path() |
415 |
| - if not bin_path: |
416 |
| - return False |
417 |
| - try: |
418 |
| - p = subprocess.Popen( |
419 |
| - bin_path, |
420 |
| - shell=False, |
421 |
| - stdout=subprocess.PIPE, |
422 |
| - stderr=subprocess.PIPE, |
423 |
| - creationflags=subprocess_creation_flags) |
424 |
| - return cls._handle_subprocess(p) |
425 |
| - except OSError: |
426 |
| - return False |
427 |
| - |
428 |
| - @classmethod |
429 |
| - def _handle_subprocess(cls, process): |
430 |
| - process.communicate() |
431 |
| - return True |
| 414 | + return shutil.which(cls.bin_path()) is not None |
432 | 415 |
|
433 | 416 |
|
434 | 417 | class FileMovieWriter(MovieWriter):
|
@@ -633,13 +616,14 @@ def output_args(self):
|
633 | 616 | return args + ['-y', self.outfile]
|
634 | 617 |
|
635 | 618 | @classmethod
|
636 |
| - def _handle_subprocess(cls, process): |
637 |
| - _, err = process.communicate() |
638 |
| - # Ubuntu 12.04 ships a broken ffmpeg binary which we shouldn't use |
639 |
| - # NOTE : when removed, remove the same method in AVConvBase. |
640 |
| - if 'Libav' in err.decode(): |
641 |
| - return False |
642 |
| - return True |
| 619 | + def isAvailable(cls): |
| 620 | + return ( |
| 621 | + super().isAvailable() |
| 622 | + # Ubuntu 12.04 ships a broken ffmpeg binary which we shouldn't use. |
| 623 | + # NOTE: when removed, remove the same method in AVConvBase. |
| 624 | + and b'LibAv' not in subprocess.run( |
| 625 | + [cls.bin_path()], creationflags=subprocess_creation_flags, |
| 626 | + stdout=subprocess.DEVNULL, stderr=subprocess.PIPE).stderr) |
643 | 627 |
|
644 | 628 |
|
645 | 629 | # Combine FFMpeg options with pipe-based writing
|
@@ -697,9 +681,7 @@ class AVConvBase(FFMpegBase):
|
697 | 681 | args_key = 'animation.avconv_args'
|
698 | 682 |
|
699 | 683 | # NOTE : should be removed when the same method is removed in FFMpegBase.
|
700 |
| - @classmethod |
701 |
| - def _handle_subprocess(cls, process): |
702 |
| - return MovieWriter._handle_subprocess(process) |
| 684 | + isAvailable = classmethod(MovieWriter.isAvailable.__func__) |
703 | 685 |
|
704 | 686 |
|
705 | 687 | # Combine AVConv options with pipe-based writing
|
@@ -772,8 +754,6 @@ def isAvailable(cls):
|
772 | 754 | cls._init_from_registry()
|
773 | 755 | return super().isAvailable()
|
774 | 756 |
|
775 |
| -ImageMagickBase._init_from_registry() |
776 |
| - |
777 | 757 |
|
778 | 758 | # Note: the base classes need to be in that order to get
|
779 | 759 | # isAvailable() from ImageMagickBase called and not the
|
|
0 commit comments