Skip to content

Commit

Permalink
[qa][previews] when extracting a tile/thumbnail/frame do that in TMP_…
Browse files Browse the repository at this point in the history
…DIR folder + remove tile when generated
  • Loading branch information
EvanBldy committed Sep 20, 2023
1 parent caace1b commit 39fe03d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions zou/app/services/preview_files_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ def generate_tiles_for_movie_previews():
try:
path = extract_tile_from_preview_file(preview_file.serialize())
file_store.add_picture("tiles", str(preview_file.id), path)
os.remove(path)
print(
f"Tile generated for preview file {preview_file.id}",
)
Expand Down Expand Up @@ -793,6 +794,7 @@ def generate_tiles_and_reset_preview_files_metadata():
file_store.add_picture(
"tiles", preview_file_id, extracted_tile_path
)
os.remove(extracted_tile_path)
print(
f"Tile generated for preview file {preview_file_id}",
)
Expand Down
16 changes: 7 additions & 9 deletions zou/utils/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import ffmpeg
import opentimelineio as otio

from zou.app import config

logger = logging.getLogger(__name__)
loghandler = logging.StreamHandler()
loghandler.setLevel(logging.INFO)
Expand Down Expand Up @@ -54,10 +56,9 @@ def generate_thumbnail(movie_path):
Generate a thumbnail to represent the movie given at movie path. It
takes a picture at the first frame of the movie.
"""
folder_path = os.path.dirname(movie_path)
file_source_name = os.path.basename(movie_path)
file_target_name = "%s.png" % file_source_name[:-4]
file_target_path = os.path.join(folder_path, file_target_name)
file_target_path = os.path.join(config.TMP_DIR, file_target_name)

try:
ffmpeg.input(movie_path, ss="00:00:00").output(
Expand All @@ -74,10 +75,9 @@ def extract_frame_from_movie(movie_path, frame_number, movie_fps):
Extract a frame from the movie given at movie path. It
takes a picture at the specified time of the movie.
"""
folder_path = os.path.dirname(movie_path)
file_source_name = os.path.basename(movie_path)
file_target_name = f"{file_source_name[:-4]}_{frame_number}.png"
file_target_path = os.path.join(folder_path, file_target_name)
file_target_path = os.path.join(config.TMP_DIR, file_target_name)

frame_time = otio.opentime.RationalTime(
frame_number - 1, float(movie_fps)
Expand All @@ -98,10 +98,9 @@ def generate_tile(movie_path, movie_fps):
"""
Generates a tile from a movie.
"""
folder_path = os.path.dirname(movie_path)
file_source_name = os.path.basename(movie_path)
file_target_name = f"{file_source_name[:-4]}_tile.png"
file_target_path = os.path.join(folder_path, file_target_name)
file_target_path = os.path.join(config.TMP_DIR, file_target_name)
probe = ffmpeg.probe(movie_path)
duration_in_seconds = float(probe["streams"][0]["duration"])
float_movie_fps = float(movie_fps)
Expand Down Expand Up @@ -190,12 +189,11 @@ def normalize_movie(movie_path, fps, width, height):
Normalize movie using resolution, width and height given in parameter.
Generates a high def movie and a low def movie.
"""
folder_path = os.path.dirname(movie_path)
file_source_name = os.path.basename(movie_path)
file_target_name = "%s.mp4" % file_source_name[:-8]
file_target_path = os.path.join(folder_path, file_target_name)
file_target_path = os.path.join(config.TMP_DIR, file_target_name)
low_file_target_name = "%s_low.mp4" % file_source_name[:-8]
low_file_target_path = os.path.join(folder_path, low_file_target_name)
low_file_target_path = os.path.join(config.TMP_DIR, low_file_target_name)

(w, h) = get_movie_size(movie_path)
resize_factor = w / h
Expand Down

0 comments on commit 39fe03d

Please sign in to comment.