0

I am trying to extract audio from a video uploaded using moviepy. The code works well during development but i keep getting error after deploying the django app.

def extract_audio(object_id): """This function extracts audio from video""" # Get the object translator_object = Translator.objects.get(pk=object_id) old_audio_file_path = '' if translator_object.source_audio: old_audio_file_path = translator_object.source_audio.path

# raise exceptions
if not translator_object:
    raise Exception("Object not found")
if not translator_object.source_video:
    raise Exception(
        "Video file not available, try again!")

if not os.path.isfile(translator_object.source_video.path):
    raise Exception(
        "Video file not available, try again!")

video_clip = VideoFileClip(translator_object.source_video.path)

new_audio_file_path = str(uuid4())+'.wav'
video_clip.audio.write_audiofile(new_audio_file_path)

translator_object.source_audio = File(open(new_audio_file_path, "rb"))
translator_object.save()

try:
    os.unlink(new_audio_file_path)
    if os.path.isfile(old_audio_file_path):
        os.unlink(old_audio_file_path)
except:
    print('Deleting error..')

error:

OSError at /admin/translator/translator/

[Errno 32] Broken pipe

MoviePy error: FFMPEG encountered the following error while writing file 162f5850-943b-483b-b97d-2440cc84a2ef.wav:

b'162f5850-943b-483b-b97d-2440cc84a2ef.wav: Permission denied\n'

In case it helps, make sure you are using a recent version of FFMPEG (the versions in the Ubuntu/Debian repos are deprecated). Request Method: POST Request URL: https://felix-projects.eastus.cloudapp.azure.com/admin/translator/translator/ Django Version: 3.2.10 Exception Type: OSError Exception Value:
[Errno 32] Broken pipe

MoviePy error: FFMPEG encountered the following error while writing file 162f5850-943b-483b-b97d-2440cc84a2ef.wav:

b'162f5850-943b-483b-b97d-2440cc84a2ef.wav: Permission denied\n'

In case it helps, make sure you are using a recent version of FFMPEG (the versions in the Ubuntu/Debian repos are deprecated). Exception Location: /home/felix/ai-video-translator/venv/lib/python3.8/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py, line 117, in write_frames Python Executable: /home/felix/ai-video-translator/venv/bin/python Python Version: 3.8.10

0 Answers0