Exemplo n.º 1
0
 def _execute(
     self,
     cli: List[str],
     program: str = "ffmpeg",
     ignore_error_if_data: bool = False,
     get_logs: bool = False,
 ) -> bytes:
     extension = mime.get_extension(mime.get_mime_type(self.content))
     assert extension
     with util.create_temp_file(suffix="." + extension) as handle:
         handle.write(self.content)
         handle.flush()
         cli = [program, "-loglevel", "32" if get_logs else "24"] + cli
         cli = [part.format(path=handle.name) for part in cli]
         proc = subprocess.Popen(
             cli,
             stdout=subprocess.PIPE,
             stdin=subprocess.PIPE,
             stderr=subprocess.PIPE,
         )
         out, err = proc.communicate(input=self.content)
         if proc.returncode != 0:
             logger.warning(
                 "Failed to execute ffmpeg command (cli=%r, err=%r)",
                 " ".join(shlex.quote(arg) for arg in cli),
                 err,
             )
             if (len(out) > 0
                     and not ignore_error_if_data) or len(out) == 0:
                 raise errors.ProcessingError(
                     "Error while processing image.\n" +
                     err.decode("utf-8"))
         return err if get_logs else out
Exemplo n.º 2
0
 def _execute(
         self,
         cli: List[str],
         program: str = 'ffmpeg',
         ignore_error_if_data: bool = False) -> bytes:
     extension = mime.get_extension(mime.get_mime_type(self.content))
     assert extension
     with util.create_temp_file(suffix='.' + extension) as handle:
         handle.write(self.content)
         handle.flush()
         cli = [program, '-loglevel', '24'] + cli
         cli = [part.format(path=handle.name) for part in cli]
         proc = subprocess.Popen(
             cli,
             stdout=subprocess.PIPE,
             stdin=subprocess.PIPE,
             stderr=subprocess.PIPE)
         out, err = proc.communicate(input=self.content)
         if proc.returncode != 0:
             logger.warning(
                 'ffmpeg 명령어 실행 실패 (cli=%r, err=%r)',
                 ' '.join(shlex.quote(arg) for arg in cli),
                 err)
             if ((len(out) > 0 and not ignore_error_if_data)
                     or len(out) == 0):
                 raise errors.ProcessingError(
                     '이미지 처리 중 오류.\n'
                     + err.decode('utf-8'))
         return out
Exemplo n.º 3
0
 def _execute(
         self,
         cli: List[str],
         program: str = 'ffmpeg',
         ignore_error_if_data: bool = False,
         get_logs: bool = False) -> bytes:
     extension = mime.get_extension(mime.get_mime_type(self.content))
     assert extension
     with util.create_temp_file(suffix='.' + extension) as handle:
         handle.write(self.content)
         handle.flush()
         cli = [program, '-loglevel', '32' if get_logs else '24'] + cli
         cli = [part.format(path=handle.name) for part in cli]
         proc = subprocess.Popen(
             cli,
             stdout=subprocess.PIPE,
             stdin=subprocess.PIPE,
             stderr=subprocess.PIPE)
         out, err = proc.communicate(input=self.content)
         if proc.returncode != 0:
             logger.warning(
                 'Failed to execute ffmpeg command (cli=%r, err=%r)',
                 ' '.join(shlex.quote(arg) for arg in cli),
                 err)
             if ((len(out) > 0 and not ignore_error_if_data)
                     or len(out) == 0):
                 raise errors.ProcessingError(
                     'Error while processing image.\n'
                     + err.decode('utf-8'))
         return err if get_logs else out
Exemplo n.º 4
0
 def _execute(self, cli, program='ffmpeg'):
     with util.create_temp_file() as handle:
         handle.write(self.content)
         handle.flush()
         cli = [program, '-loglevel', '24'] + cli
         cli = [part.format(path=handle.name) for part in cli]
         proc = subprocess.Popen(cli,
                                 stdout=subprocess.PIPE,
                                 stdin=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
         out, err = proc.communicate(input=self.content)
         if proc.returncode != 0:
             raise errors.ProcessingError(
                 'Error while processing image.\n' + err.decode('utf-8'))
         return out
Exemplo n.º 5
0
 def _execute(self, cli, program='ffmpeg'):
     with util.create_temp_file() as handle:
         handle.write(self.content)
         handle.flush()
         cli = [program, '-loglevel', '24'] + cli
         cli = [part.format(path=handle.name) for part in cli]
         proc = subprocess.Popen(
             cli,
             stdout=subprocess.PIPE,
             stdin=subprocess.PIPE,
             stderr=subprocess.PIPE)
         out, err = proc.communicate(input=self.content)
         if proc.returncode != 0:
             raise errors.ProcessingError(
                 'Error while processing image.\n' + err.decode('utf-8'))
         return out
Exemplo n.º 6
0
 def _execute(self, cli: List[str], program: str = 'ffmpeg') -> bytes:
     extension = mime.get_extension(mime.get_mime_type(self.content))
     assert extension
     with util.create_temp_file(suffix='.' + extension) as handle:
         handle.write(self.content)
         handle.flush()
         cli = [program, '-loglevel', '24'] + cli
         cli = [part.format(path=handle.name) for part in cli]
         proc = subprocess.Popen(cli,
                                 stdout=subprocess.PIPE,
                                 stdin=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
         out, err = proc.communicate(input=self.content)
         if proc.returncode != 0:
             logger.warning(
                 'Failed to execute ffmpeg command (cli=%r, err=%r)',
                 ' '.join(shlex.quote(arg) for arg in cli), err)
             raise errors.ProcessingError(
                 'Error while processing image.\n' + err.decode('utf-8'))
         return out
Exemplo n.º 7
0
 def _execute(self, cli, program='ffmpeg'):
     extension = mime.get_extension(mime.get_mime_type(self.content))
     assert extension
     with util.create_temp_file(suffix='.' + extension) as handle:
         handle.write(self.content)
         handle.flush()
         cli = [program, '-loglevel', '24'] + cli
         cli = [part.format(path=handle.name) for part in cli]
         proc = subprocess.Popen(
             cli,
             stdout=subprocess.PIPE,
             stdin=subprocess.PIPE,
             stderr=subprocess.PIPE)
         out, err = proc.communicate(input=self.content)
         if proc.returncode != 0:
             logger.warning(
                 'Failed to execute ffmpeg command (cli=%r, err=%r)',
                 ' '.join(shlex.quote(arg) for arg in cli),
                 err)
             raise errors.ProcessingError(
                 'Error while processing image.\n' + err.decode('utf-8'))
         return out