Closed morganmcg1 closed 2 years ago
Yeah I experienced a similar broken pipe error, not sure what the deal is. video encoding stuff isn't my wheel house. I'm thinking of swapping out the ffmpeg cli invocation with a python binding that might make writing frames to video more stable and possibly use less memory. not sure if memory is even the issue here, but yeah: this broken pipe thing is a problem for sure.
It happened just now with another video, but hit at 2380/3204 frames. Thing is it worked yesterday without a hitch. I tried undoing the change made in this commit on the random chance that might help, not no joy.
Thanks for the great notebook anyways, really enjoying it
Spent a good chunk of the last 2 days fighting ffmpeg but I think I have a more stable version using the python bindings from ffmpeg-python. This seems to be stable for me, I've tested it with a few different videos, up to about 2.5k frames. Its not pretty but it works :D
@dmarx let me know if you'd like a PR :) , this colab here is the same with just the video compilation cell replaced if you'd like to test
Install the ffmpeg python bindings: https://github.com/kkroening/ffmpeg-python
pip install -qqq ffmpeg-python
Then compile your video and audio like so:
import os
import ffmpeg
fps = storyboard.params.fps
input_audio = storyboard.params.audio_fpath
output_filename = storyboard.params.output_filename
# Create a directory to save the frames to
frames_directory = 'my_frames'
if not os.path.exists(frames_directory):
os.makedirs(frames_directory)
# Save each PIL Image as a .png file to `frames_directory`
for i,f in enumerate(frames):
f.save(f"{frames_directory}/{i}.png", format='png')
# Rename all the frames in the frames directory so that filenames include leading zeros and are listed in order
!rename -e 's/\d+/sprintf("%06d",$&)/e' -- $frames_directory/*.png
# Create the video without audio from the saved .png frames
ffmpeg.input(f'{frames_directory}/*.png', pattern_type='glob', framerate=fps).output(output_filename).overwrite_output().run()
# Merge the video and audio files
v = ffmpeg.input(output_filename)
a = ffmpeg.input(input_audio)
v.output(a, "final.mp4", shortest=None, vcodec="libx264", framerate=fps, pix_fmt="yuv420p", preset="veryslow").overwrite_output().run()
I'd love a PR! Yes please, and thanks for finding a work around! :)
I think the issue here had to do with how the notebook was occupying memory, which has been fixed. Closing this for now even though I haven't integrated the ffmpeg-python suggestion, but I'll try that solution if users continue to report similar issues
got it, glad that its working better now
At the end of Step 7 I have 22k PIL images in the
frames
list. When Step 8 starts to iterate through them it consistently hits an error with the PIL saving,BrokenPipeError: [Errno 32] Broken pipe
, specifically after 4688 images - I've tested this 3 times, albeit with the same set of images. I also tested that the images in and around that index weren't corrupted (just by viewing them in colab), but then seem to be fine.This is only on 1 video so far, I'm going to restart the colab and pick another video with the same settings and see if I can reproduce or if its just a weird artifact of the image creation.
Stacktrace: