-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There are still broken pipe errors #2337
Comments
Could you please provide code and medias to reproduce the problem ? |
My below error doesn't happen with source from I got the same error with 10 minutes tutorial, it happens when preview every time(on Mac15.3 (24D60)), but it works in notebook with display_in_notebook: Lets import moviepy, lets also import numpy we will use it a some pointfrom moviepy import * ################# VIDEO LOADING################# We load our videovideo = VideoFileClip("./resources/bbb.mp4") ##################### SCENES EXTRACTION##################### We extract the scenes we want to useFirst the charactersintro_clip = video.subclipped(1, 11) ##################### SCENES PREVIEWING##################### Now, lets have a first look at our clipsWarning: you need ffplay installed for preview to workWe set a low fps so our machine can render in real time without slowing downintro_clip.preview(fps=20) Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): |
I will also get occasional broken pipes: @shared_task(bind=True)
def process_video_moviepy(self, excavation_video_id):
self.update_state(state='PROGRESS', meta={'current': 1, 'total': 4, 'description': 'Start processing'})
try:
excavation_video = ExcavationVideo.objects.get(id=excavation_video_id)
excavation_video.error_message = None
excavation_video.save(update_fields=['error_message'])
target_fps = None
target_bitrate = None
if excavation_video.metadata['fps'] < 25 and excavation_video.metadata['bitrate'] < 1500000:
excavation_video.finished = True
self.update_state(state='PROGRESS', meta={'current': 4, 'total': 4, 'description': 'Saving file'})
excavation_video.save(update_fields=['video', 'finished'])
return {
"status": "success",
"output_video": {
"url": excavation_video.video.url,
"name": excavation_video.video.name,
"size": excavation_video.video.size
}
}
elif excavation_video.metadata['fps'] > 25:
target_fps = 25
elif excavation_video.metadata['bitrate'] > 1500000:
target_bitrate = 1500000
if not excavation_video.video:
raise ValueError("No source video attached")
storage = excavation_video.video.storage
self.update_state(state='PROGRESS', meta={'current': 2, 'total': 4, 'description': 'Loading file'})
with tempfile.TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir)
input_path = tmp_path / excavation_video.video.name.split('/')[-1]
output_filename = f"processed_{Path(excavation_video.video.name).stem}.mp4"
output_path = tmp_path / output_filename
# Download source video to temp location
with storage.open(excavation_video.video.name, 'rb') as source_file:
with open(input_path, 'wb') as temp_file:
temp_file.write(source_file.read())
# MoviePy processing
self.update_state(state='PROGRESS', meta={'current': 3, 'total': 4, 'description': 'Processing with MoviePy'})
clip = VideoFileClip(str(input_path))
# Calculate target resolution
original_width, original_height = clip.size
cheeky_width, cheeky_height = video_wh(str(input_path))
if cheeky_width != original_width or cheeky_height != original_height:
original_width, original_height = original_height, original_width
if original_width < original_height: # Portrait
if original_height >= 3840:
max_w, max_h = 720, 1280
else:
max_w, max_h = original_width, original_height
else: # Landscape
if original_width >= 3840:
max_w, max_h = 1280, 720
else:
max_w, max_h = original_width, original_height
ratio = min(max_w / original_width, max_h / original_height)
if ratio < 1: # Only apply scaling if needed
new_w = round(original_width * ratio)
new_h = round(original_height * ratio)
else: # Keep original but ensure even
new_w, new_h = original_width, original_height
# Ensure even dimensions
new_w = new_w // 2 * 2
new_h = new_h // 2 * 2
if original_width >= 3840:
processed = clip.resize(width = new_w)
elif original_height >= 3840:
processed = clip.resize(height = new_h)
else:
processed = clip
if target_fps is not None:
processed = processed.with_fps(25)
else:
pass
# Export with specified parameters
if target_bitrate is not None:
processed.write_videofile(
str(output_path),
codec='libx264',
bitrate='1500k',
preset='fast',
audio_codec='aac',
ffmpeg_params=[
'-movflags', '+faststart',
# '-pix_fmt', 'yuv420p',
],
threads = 1
)
else:
processed.write_videofile(
str(output_path),
codec='libx264', # Explicitly set codec to ensure compatibility
preset='fast',
audio_codec='aac', # Ensure audio is retained
ffmpeg_params=[
'-movflags', '+faststart',
# '-pix_fmt', 'yuv420p',
],
threads = 1
)
clip.close()
processed.close()
del clip, processed
gc.collect()
# if not output_path.exists():
# raise FileNotFoundError("Output video file was not generated")
# Save processed video
with open(output_path, 'rb') as processed_file:
excavation_video.video.save(
output_filename,
File(processed_file)
)
excavation_video.finished = True
self.update_state(state='PROGRESS', meta={'current': 4, 'total': 4, 'description': 'Saving file'})
excavation_video.save(update_fields=['video', 'finished'])
counter = 0
for proc in psutil.process_iter(attrs=['pid', 'name']):
if "ffmpeg" in proc.info['name']:
counter += 1
proc.kill() # Kill stale processes
return {
"status": "success",
"output_video": {
"url": excavation_video.video.url,
"name": excavation_video.video.name,
"size": excavation_video.video.size,
"counter": counter
}
} Tried to mitigate the error, by killing all ffmpeg processes after I do the conversion |
There should be no more broken pipes
There are still broken pipe errors
I come to rescue this FFMPEG error from the broken pipe, because I have noticed when I have been doing tests and deployments that the error occurs at a certain memory usage of the system, the initial system I have is 8GB of RAM and if I pass the 6.5GB of use it throws this same error:
And investigating a little more it turns out that the continuous use of final_video.write_videofile(
str(output_path),
fps=24,
threads=64,
codec='libx264',
audio_codec='aac',
)
The memory is not cleaned correctly to be able to make a continuous execution of my App, so I had to implement an automatic memory cleaning to avoid that, but sometimes I still get the same error because my cleaning functions are not sufficient.
-->
Used medias
Specifications
The text was updated successfully, but these errors were encountered: