Skip to content

Commit

Permalink
fixes to video frames when all videos are corrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
dale-wahl committed Nov 19, 2024
1 parent 2d4d60f commit 176905a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
18 changes: 11 additions & 7 deletions processors/visualisation/video_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def process(self):
processed_videos = 0

self.dataset.update_status("Extracting video frames")
for path in self.iterate_archive_contents(self.source_file, staging_area):
for i, path in enumerate(self.iterate_archive_contents(self.source_file, staging_area)):
if self.interrupted:
raise ProcessorInterruptedException("Interrupted while determining image wall order")

Expand Down Expand Up @@ -138,17 +138,21 @@ def process(self):
outfile.write(ffmpeg_error)

if result.returncode != 0:
error = 'Error Return Code with video %s: %s' % (vid_name, str(result.returncode))
self.dataset.log(error)
self.dataset.update_status(f"Unable to extract frames from video {vid_name} (see logs for details)")
self.dataset.log('Error Return Code (%s) with video %s: %s' % (str(result.returncode), vid_name, "\n".join(ffmpeg_error.split('\n')[-2:]) if ffmpeg_error else ''))
else:
processed_videos += 1
self.dataset.update_status("Created frames for %i of %i videos" % (processed_videos, total_possible_videos))

processed_videos += 1
self.dataset.update_status(
"Created frames for %i of %i videos" % (processed_videos, total_possible_videos))
self.dataset.update_progress(processed_videos / total_possible_videos)
self.dataset.update_progress(i / total_possible_videos)

# Finish up
# We've created a directory and folder structure here as opposed to a single folder with single files as
# expected by self.write_archive_and_finish() so we use make_archive instead
if not processed_videos:
self.dataset.finish_with_error("Unable to extract frames from any videos")
return

from shutil import make_archive
make_archive(self.dataset.get_results_path().with_suffix(''), "zip", output_directory)

Expand Down
13 changes: 9 additions & 4 deletions processors/visualisation/video_hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ def process(self):
self.dataset.update_status("FFmpeg software not found. Please contact 4CAT maintainers.", is_final=True)
self.dataset.finish(0)
return
except FileNotFoundError as e:
self.dataset.update_status(f"Unable to find file {str(path)}")
except FileNotFoundError:
self.dataset.update_status(f"Unable to find file {path.name}")
continue
except FFmpegFailedToExtractFrames as e:
self.dataset.update_status(f"Unable to extract frame for {str(path)}: {e}")
self.dataset.update_status(f"Unable to extract frame for {path.name} (see log for details)")
self.dataset.log(f"Unable to extract frame for {str(path)}: {e}")
continue

video_hashes[path.name] = {'videohash': videohash}
Expand All @@ -234,6 +235,10 @@ def process(self):
self.dataset.update_progress(processed_videos / total_possible_videos)
videohash.delete_storage_path()

if processed_videos == 0:
self.dataset.finish_with_error("Unable to create video hashes for any videos")
return

# Write hash file
# This file is held here and then copied as its own dataset via VideoHasherTwo
num_posts = 0
Expand Down Expand Up @@ -304,7 +309,7 @@ def process(self):

# Finish up
self.dataset.update_status(f'Created {num_posts} video hashes and stored video collages')
self.write_archive_and_finish(output_dir)
self.write_archive_and_finish(output_dir, num_items=processed_videos)

class VideoHashNetwork(BasicProcessor):
"""
Expand Down
7 changes: 7 additions & 0 deletions processors/visualisation/video_timelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def process(self):
if previous_video is not None or not looping:
# draw the video filename/label on top of the rendered
# frame thumbnails
if not previous_video:
# This likely means no frames were found for the video and this processor should not have run
continue
video_label = labels.get(previous_video, previous_video)
footersize = (fontsize * (len(video_label) + 2) * 0.5925, fontsize * 2)
footer_shape = SVG(insert=(0, base_height - footersize[1]), size=footersize)
Expand Down Expand Up @@ -165,6 +168,10 @@ def process(self):
timeline.add(frame_element)
timeline_widths[video] += frame_width

if not timeline_widths:
self.dataset.finish_with_error("No video frames found")
return

# now we know all dimensions we can instantiate the canvas too
canvas_width = max(timeline_widths.values())
fontsize = 12
Expand Down

0 comments on commit 176905a

Please sign in to comment.