my input file is zip file from Google drive and my output file is also zip file and a…
- User
my input file is zip file from Google drive and my output file is also zip file and a text file which contains all links. I have 3 script for media processing but I want make one script with more flexibility and choosing options and easy interface like app, can you give me some ideas how I can achieve these. here is my all 3 script. # @title ( zip marking each of the video) Video Cropping Tool for Google Drive
Install necessary packages
!pip install opencv-python-headless ffmpeg-python -q
import os import cv2 import ffmpeg import zipfile import shutil from google.colab import drive import ipywidgets as widgets from IPython.display import display, clear_output import matplotlib.pyplot as plt from matplotlib.patches import Rectangle
Mount Google Drive
drive.mount('/content/drive')
Function to browse directories and list ZIP files in Google Drive
def browse_zip_files(base_folder='/content/drive/My Drive'): """Returns a sorted list of ZIP file paths within the base folder and its subfolders.""" zip_files = [] for dirname, _, filenames in os.walk(base_folder): for filename in filenames: if filename.lower().endswith('.zip'): zip_files.append(os.path.join(dirname, filename)) zip_files_sorted = sorted(zip_files) return zip_files_sorted
Initialize global variables
zip_file_path = None extracted_videos_dir = '/content/extracted_videos' cropped_videos_dir = '/content/cropped_videos' files_list = [] current_file_index = 0 crop_settings = {} width_cache = {} height_cache = {} original_zip_dir = ''
Create directories if they don't exist
os.makedirs(extracted_videos_dir, exist_ok=True) os.makedirs(cropped_videos_dir, exist_ok=True)
Dropdown for ZIP file selection
zip_dropdown = widgets.Dropdown( options=browse_zip_files(), description='Select ZIP File:', layout=widgets.Layout(width='100%'), style={'description_width': 'initial'} )
Button to extract ZIP
extract_button = widgets.Button( description="Extract ZIP", button_style='primary', layout=widgets.Layout(width='100%') )
Sliders for crop settings (percentages)
x_start_slider = widgets.IntSlider( value=0, min=0, max=100, step=1, description="Start X (%)", continuous_update=False, layout=widgets.Layout(width='100%') ) y_start_slider = widgets.IntSlider( value=0, min=0, max=100, step=1, description="Start Y (%)", continuous_update=False, layout=widgets.Layout(width='100%') ) x_end_slider = widgets.IntSlider( value=100, min=0, max=100, step=1, description="End X (%)", continuous_update=False, layout=widgets.Layout(width='100%') ) y_end_slider = widgets.IntSlider( value=100, min=0, max=100, step=1, description="End Y (%)", continuous_update=False, layout=widgets.Layout(width='100%') )
Buttons for interactions
set_button = widgets.Button( description="Set Crop for Current Video", button_style='success', layout=widgets.Layout(width='100%') ) next_button = widgets.Button( description="Next Video", button_style='info', layout=widgets.Layout(width='100%') ) crop_all_button = widgets.Button( description="Start Cropping All Videos", button_style='danger', layout=widgets.Layout(width='100%') )
- Assistant