Exemplo n.º 1
0
class TestInspector(unittest.TestCase):

    def setUp(self):
        self._inspector = VideoInspector("input.mp4")

    def testContainer(self):
        self.assertEquals(
            self._inspector.container(),
            "mov,mp4,m4a,3gp,3g2,mj2"
        )

    def testRawDuration(self):
        self.assertEquals(self._inspector.raw_duration(), "00:02:22.70")

    def testDuration(self):
        self.assertEquals(self._inspector.duration(), 142700)

    def testFPS(self):
        self.assertEquals(self._inspector.fps(), '24')
Exemplo n.º 2
0
class TestInspector(unittest.TestCase):
    def setUp(self):
        self._inspector = VideoInspector()
        self._inspector.setUp("input.mp4")

    def testContainer(self):
        self.assertEquals(self._inspector.container(),
                          "mov,mp4,m4a,3gp,3g2,mj2")

    def testWidth(self):
        self.assertTrue(self._inspector.width() > 0)

    def testHeight(self):
        self.assertTrue(self._inspector.height() > 0)

    def testVideoCodec(self):
        codec = None
        try:
            codec = self._inspector.video_codec()
        except:
            None
        self.assertTrue(codec is not None)

    def testAudioCodec(self):
        codec = None
        try:
            codec = self._inspector.audio_codec()
        except:
            None
        self.assertTrue(codec is not None)

    def testRawDuration(self):
        self.assertEquals(self._inspector.raw_duration(), "00:00:10.08")

    def testDuration(self):
        self.assertEquals(self._inspector.duration(), 10080)

    def testFPS(self):
        self.assertEquals(self._inspector.fps_round(), 30)
Exemplo n.º 3
0
 def __init__(self, video_source, ffmpeg_bin="ffmpeg"):
     self._ffmpeg_bin = ffmpeg_bin
     if not isinstance(video_source, VideoInspector):
         self.original_file = VideoInspector(video_source, ffmpeg_bin)
     else:
         self.original_file = video_source
Exemplo n.º 4
0
class VideoEncoder(object):
    def __init__(self, video_source, ffmpeg_bin="ffmpeg"):
        self._ffmpeg_bin = ffmpeg_bin
        if not isinstance(video_source, VideoInspector):
            self.original_file = VideoInspector()
            self.original_file.setUp(video_source, ffmpeg_bin)
        else:
            self.original_file = video_source

    # %(ffmpeg_bin)s -i %(input_file)s %(output_file)s
    def execute(self,
                cmd,
                video_output,
                progress_callback=None,
                complete_callback=None):
        if os.path.exists(video_output) and " -y " not in cmd:
            raise CantOverwrite()

        cmd = cmd % {
            "ffmpeg_bin": self._ffmpeg_bin,
            "input_file": self.original_file.full_filename,
            "output_file": video_output
        }
        if progress_callback:
            cmd = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
            if sys.platform <> "win32":
                fcntl.fcntl(
                    cmd.stderr.fileno(),
                    fcntl.F_SETFL,
                    fcntl.fcntl(cmd.stderr.fileno(), fcntl.F_GETFL)
                    | os.O_NONBLOCK,
                )

            duration = None
            header = ""
            progress_regex = re.compile("frame=.*time=([0-9\:\.]+)",
                                        flags=re.IGNORECASE)
            header_received = False

            while True:
                progressline = select.select([cmd.stderr.fileno()], [], [])[0]
                if progressline:
                    line = cmd.stderr.read()
                    if line == "":
                        if complete_callback:
                            complete_callback()
                        break
                    progress_match = progress_regex.match(line)
                    if progress_match:
                        if not header_received:
                            header_received = True

                            if re.search(".*command\snot\sfound",
                                         header,
                                         flags=re.IGNORECASE):
                                raise CommandError()

                            if re.search("Unknown format",
                                         header,
                                         flags=re.IGNORECASE):
                                raise UnknownFormat()

                            if re.search("Duration: N\/A",
                                         header,
                                         flags=re.IGNORECASE | re.MULTILINE):
                                raise UnreadableFile()

                            raw_duration = re.search(
                                "Duration:\s*([0-9\:\.]+),", header)
                            if raw_duration:
                                units = raw_duration.group(1).split(":")
                                duration = (int(units[0]) * 60 * 60 * 1000) + \
                                    (int(units[1]) * 60 * 1000) + \
                                    int(float(units[2]) * 1000)

                        if duration and progress_callback:
                            progress_callback(
                                float(progress_match.group(1)) * 1000,
                                duration)

                    else:
                        header += line
        else:
            cmd = subprocess.call(cmd, shell=True, stderr=subprocess.PIPE)
Exemplo n.º 5
0
from moviepy.editor import VideoFileClip, concatenate_videoclips, vfx
from boundary_marker import BoundaryMarker
from video_inspector import VideoInspector
from video_cut import VidoeCut

if __name__ == "__main__":
    from_path = "../video/from.mp4"
    to_path = "../video/to.mp4"

    video = VideoFileClip(from_path)
    video = video.fx(vfx.rotate, 90)  # 旋转90度,(横屏变竖屏)

    bm = BoundaryMarker(video)
    vi = VideoInspector(video, bm.boundary_marker, bm.back_color)
    cut_time_li = vi.cut_time_round_li
    print(cut_time_li)
    # vc = VidoeCut(video, vi.cut_time_round_li, to_path)
Exemplo n.º 6
0
 def setUp(self):
     self._inspector = VideoInspector("input.mp4")
Exemplo n.º 7
0
 def setUp(self):
     self._inspector = VideoInspector()
     self._inspector.setUp("input.mp4")