Spaces:
				
			
			
	
			
			
		Paused
		
	
	
	
			
			
	
	
	
	
		
		
		Paused
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -37,15 +37,32 @@ def get_video_dimension(filepath): | |
| 37 | 
             
                video.release()
         | 
| 38 | 
             
                return width, height, fps
         | 
| 39 |  | 
| 40 | 
            -
            def  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 41 | 
             
                # Load the video clip
         | 
| 42 | 
             
                video = VideoFileClip(input_path)
         | 
| 43 |  | 
| 44 | 
            -
                # Calculate the new  | 
| 45 | 
            -
                 | 
| 46 |  | 
| 47 | 
             
                # Resize the video
         | 
| 48 | 
            -
                resized_video = video.resize(width= | 
| 49 |  | 
| 50 | 
             
                # Write the resized video to the output path
         | 
| 51 | 
             
                resized_video.write_videofile(output_path, codec='libx264')
         | 
|  | |
| 37 | 
             
                video.release()
         | 
| 38 | 
             
                return width, height, fps
         | 
| 39 |  | 
| 40 | 
            +
            def get_new_dimensions(width, height):
         | 
| 41 | 
            +
                new_width = width
         | 
| 42 | 
            +
                new_height = height
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                # Adjust width to be a multiple of 32
         | 
| 45 | 
            +
                while new_width % 32 != 0:
         | 
| 46 | 
            +
                    new_width += 1
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                # Adjust height to maintain the aspect ratio
         | 
| 49 | 
            +
                new_height = int(new_width * (height / width))
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                # Adjust height to be a multiple of 32
         | 
| 52 | 
            +
                while new_height % 32 != 0:
         | 
| 53 | 
            +
                    new_height += 1
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                return new_width, new_height
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            def resize_video(input_path, output_path, target_width):
         | 
| 58 | 
             
                # Load the video clip
         | 
| 59 | 
             
                video = VideoFileClip(input_path)
         | 
| 60 |  | 
| 61 | 
            +
                # Calculate the new dimensions while maintaining the aspect ratio and multiples of 32
         | 
| 62 | 
            +
                new_width, new_height = get_new_dimensions(video.size[0], video.size[1])
         | 
| 63 |  | 
| 64 | 
             
                # Resize the video
         | 
| 65 | 
            +
                resized_video = video.resize(width=new_width, height=new_height)
         | 
| 66 |  | 
| 67 | 
             
                # Write the resized video to the output path
         | 
| 68 | 
             
                resized_video.write_videofile(output_path, codec='libx264')
         | 
