win32com error when exporting pptx to mp4

26 Views Asked by At

I am trying to export the powerpoint presentation in mp4 format but getting the file or path not exist error (details below):

When I am giving the relative paths (PPT file exists on the path):

  • input file path as "../Uploads/20240229_16945_PersonalityPPT_en.pptx"
  • output file path as "../Uploads/20240229_16945_PersonalityVideo_en.mp4"

Error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024893), None)

I checked the error code (-2147024893):

import win32api
win32api.FormatMessage(-2147024893)

and it says "The system cannot find the path specified.".


When I am giving the absolute paths (PPT file exists on the path):

  • input file path as "D:/Repos/Takhti20/TakhtiPipeline/Uploads/20240229_16945_PersonalityPPT_en.pptx"
  • output file path as "D:/Repos/Takhti20/TakhtiPipeline/Uploads/20240229_16945_PersonalityVideo_en.mp4"

Error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024894), None)

I checked the error code (-2147024894):

import win32api
win32api.FormatMessage(-2147024894)

and it says "The system cannot find the file specified."


This is the function that I wrote to export pptx to mp4 file:

def export_pptx_to_video(self, input_pptx, output_video):
        ppt_app = win32com.client.Dispatch("PowerPoint.Application")
        try:
            presentation = ppt_app.Presentations.Open(FileName=input_pptx, WithWindow=False)

            print('exporting video')
            # Export the presentation as a video
            export_path = output_video
            presentation.CreateVideo(FileName=export_path)
            
            # Wait for the video export to finish
            while presentation.CreateVideoStatus == 1:
                time.sleep(1)

            # Close the presentation and PowerPoint application
            presentation.Close()
            ppt_app.Quit()
            ppt_app = None
            del ppt_app
            print(export_path)
        except Exception as ex:
            print(ex)
            ppt_app.Quit()
            ppt_app = None
            del ppt_app

I saw this "com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024809), None)" post on stackoverflow and implemented the solution of assigning None and deleting variable from the memory but I got no luck in solving the error.

0

There are 0 best solutions below