Last active
June 5, 2025 09:15
-
-
Save anandadake/27d3e802b48b1b038977b560150d70df to your computer and use it in GitHub Desktop.
Convert .avi video file to .mp4 video file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| python -m pip install moviepy | |
| """ | |
| import os | |
| from time import time | |
| import moviepy.editor as moviepy | |
| def convert_avi_to_mp4(avi_file_path): | |
| # function guard | |
| if not os.path.exists(avi_file_path): | |
| raise FileNotFoundError(avi_file_path) | |
| t0 = time() | |
| clip = moviepy.VideoFileClip(avi_file_path) | |
| path, file_name = os.path.split(avi_file_path) | |
| output_name = os.path.join(path, os.path.splitext(file_name)[0] + '.mp4') | |
| clip.write_videofile(output_name) | |
| print('Finished conversion in %is' % (time() - t0)) | |
| if __name__ == '__main__': | |
| filename = "/home/aadake/videos/out_video.avi" | |
| convert_avi_to_mp4(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment