예제 #1
0
파일: test_movie.py 프로젝트: mathbou/zou
    def concat_testing(self, method, test_name):
        videos = []
        width, height = movie.get_movie_size(self.video_only_path)
        for i in range(0, 2):
            filename = "%s-%s.m4v" % (i, test_name)
            video = str(Path(self.tmpdir) / filename)
            shutil.copyfile(self.video_only_path, video)
            normalized, _, _ = movie.normalize_movie(video, 5, width, height)
            # 2nd item isn't used by build_playlist_movie
            videos.append((normalized, None))

        out = "out-%s.mp4" % test_name
        out = str(Path(self.tmpdir) / out)

        result = movie.build_playlist_movie(method,
                                            videos,
                                            out,
                                            width,
                                            height,
                                            fps=5)
        self.assertTrue(result.get("success"))
        self.assertFalse(result.get("message"))

        width_playlist, height_playlist = movie.get_movie_size(out)
        self.assertEqual(width, width_playlist)
        self.assertEqual(height, height_playlist)
예제 #2
0
    def test_normalize_width_unspecified(self):
        filename = "%s.m4v" % inspect.currentframe().f_code.co_name
        video = str(Path(self.tmpdir) / filename)
        shutil.copyfile(self.video_only_path, video)

        width, height = movie.get_movie_size(video)
        normalized, _, _ = movie.normalize_movie(video, 5, None, int(height/2))
        width_norm, height_norm = movie.get_movie_size(normalized)
        self.assertEqual(width/2, width_norm)
        self.assertEqual(height/2, height_norm)
예제 #3
0
파일: test_movie.py 프로젝트: mathbou/zou
    def test_normalize(self):
        filename = "test_normalize.m4v"
        video = str(Path(self.tmpdir) / filename)
        shutil.copyfile(self.video_only_path, video)

        self.assertFalse(movie.has_soundtrack(video))
        width, height = movie.get_movie_size(video)
        normalized, _, _ = movie.normalize_movie(video, 5, width, height)

        # normalization adds an audio stream
        self.assertTrue(movie.has_soundtrack(normalized))

        # dimensions are unchanged
        width_norm, height_norm = movie.get_movie_size(normalized)
        self.assertEqual(width, width_norm)
        self.assertEqual(height, height_norm)
예제 #4
0
def prepare_and_store_movie(preview_file_id, uploaded_movie_path):
    """
    Prepare movie preview, normalize the movie as a .mp4, build the thumbnails
    and store the files.
    """
    from zou.app import app as current_app
    with current_app.app_context():
        project = get_project_from_preview_file(preview_file_id)
        fps = get_preview_file_fps(project)
        (width, height) = get_preview_file_dimensions(project)

        # Build movie
        current_app.logger.info("start normalization")
        try:
            (normalized_movie_path, normalized_movie_low_path,
             err) = movie.normalize_movie(uploaded_movie_path,
                                          fps=fps,
                                          width=width,
                                          height=height)

            if err:
                current_app.logger.error(
                    "Fail to add silent audiotrack to: %s" %
                    uploaded_movie_path)
                current_app.logger.error(err)

            current_app.logger.info("file normalized %s" %
                                    normalized_movie_path)
            file_store.add_movie("previews", preview_file_id,
                                 normalized_movie_path)
            file_store.add_movie("lowdef", preview_file_id,
                                 normalized_movie_low_path)
            current_app.logger.info("file stored")
        except Exception as exc:
            if isinstance(exc, ffmpeg.Error):
                current_app.logger.error(exc.stderr)
            current_app.logger.error("failed", exc_info=1)
            preview_file = set_preview_file_as_broken(preview_file_id)
            return preview_file

        # Build thumbnails
        size = movie.get_movie_size(normalized_movie_path)
        original_picture_path = \
            movie.generate_thumbnail(normalized_movie_path)
        tile_picture_path = \
            movie.generate_tile(normalized_movie_path)
        thumbnail_utils.resize(original_picture_path, size)
        save_variants(preview_file_id, original_picture_path)
        file_size = os.path.getsize(normalized_movie_path)
        current_app.logger.info("thumbnail created %s" % original_picture_path)

        # Remove files and update status
        os.remove(uploaded_movie_path)
        os.remove(normalized_movie_path)
        preview_file = update_preview_file(preview_file_id, {
            "status": "ready",
            "file_size": file_size
        })
        return preview_file
예제 #5
0
def prepare_and_store_movie(preview_file_id, uploaded_movie_path):
    """
    Prepare movie preview, normalize the movie as a .mp4, build the thumbnails
    and store the files.
    """
    from zou.app import app as current_app

    with current_app.app_context():
        try:
            project = get_project_from_preview_file(preview_file_id)
        except PreviewFileNotFoundException:
            time.sleep(2)
            try:
                project = get_project_from_preview_file(preview_file_id)
            except PreviewFileNotFoundException:
                current_app.logger.error(
                    "Data is missing from database", exc_info=1
                )
                time.sleep(2)
                preview_file = set_preview_file_as_broken(preview_file_id)
                return preview_file

        fps = get_preview_file_fps(project)
        (width, height) = get_preview_file_dimensions(project)

        # Build movie
        current_app.logger.info("start normalization")
        try:
            if (
                config.ENABLE_JOB_QUEUE_REMOTE
                and len(config.JOB_QUEUE_NOMAD_NORMALIZE_JOB) > 0
            ):
                file_store.add_movie(
                    "source", preview_file_id, uploaded_movie_path
                )
                result = _run_remote_normalize_movie(
                    current_app, preview_file_id, fps, width, height
                )
                if result is True:
                    err = None
                else:
                    err = result

                normalized_movie_path = fs.get_file_path_and_file(
                    config,
                    file_store.get_local_movie_path,
                    file_store.open_movie,
                    "previews",
                    preview_file_id,
                    ".mp4",
                )
            else:
                (
                    normalized_movie_path,
                    normalized_movie_low_path,
                    err,
                ) = movie.normalize_movie(
                    uploaded_movie_path, fps=fps, width=width, height=height
                )
                file_store.add_movie(
                    "previews", preview_file_id, normalized_movie_path
                )
                file_store.add_movie(
                    "lowdef", preview_file_id, normalized_movie_low_path
                )
            if err:
                current_app.logger.error(
                    "Fail to normalize: %s" % uploaded_movie_path
                )
                current_app.logger.error(err)

            current_app.logger.info(
                "file normalized %s" % normalized_movie_path
            )
            current_app.logger.info("file stored")
        except Exception as exc:
            if isinstance(exc, ffmpeg.Error):
                current_app.logger.error(exc.stderr)
            current_app.logger.error("failed", exc_info=1)
            preview_file = set_preview_file_as_broken(preview_file_id)
            return preview_file

        # Build thumbnails
        size = movie.get_movie_size(normalized_movie_path)
        original_picture_path = movie.generate_thumbnail(normalized_movie_path)
        thumbnail_utils.resize(original_picture_path, size)
        save_variants(preview_file_id, original_picture_path)
        file_size = os.path.getsize(normalized_movie_path)
        current_app.logger.info("thumbnail created %s" % original_picture_path)

        # Remove files and update status
        os.remove(uploaded_movie_path)
        os.remove(normalized_movie_path)
        preview_file = update_preview_file(
            preview_file_id, {"status": "ready", "file_size": file_size}
        )
        return preview_file
예제 #6
0
파일: test_movie.py 프로젝트: mathbou/zou
 def test_get_movie_size(self):
     width, height = movie.get_movie_size(self.video_only_path)
     self.assertEqual(width, 320)
     self.assertEqual(height, 240)