<jupyter_start><jupyter_text>Prerequesties **Important to run this code** One time required when you run the file **NOTE - While Converting The Video or Folder , That video or folder should be present in your drive**<jupyter_code>#@title Click Run Button {run:"auto"}
!apt install ffmpeg
from google.colab import drive
drive.mount('/content/drive')
!mkdir /content/drive/MyDrive/SV_ProgrammingGFG
#SV - single video<jupyter_output>Reading package lists... Done
Building dependency tree       
Reading state information... Done
ffmpeg is already the newest version (7:3.4.8-0ubuntu0.2).
The following package was automatically installed and is no longer required:
  libnvidia-common-460
Use 'apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 34 not upgraded.
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
mkdir: cannot create directory ‘/content/drive/MyDrive/SV_ProgrammingGFG’: File exists<jupyter_text>Convert Single File !- Copy your VideoFile Full Path from the **Show File Browser > drive > MyDrive** in menu of Google Colab- Enter It.- Enter the output Filename- Wait and Drink Coffee **Output File is present in SV_ProgrammingGFG in your drive**<jupyter_code>#@title Convert Single File {display-mode:"form"}
FilePath = ''  #@param {type:"string"}
OutFileName = ''  #@param {type:"string"}
filename = Filename
outfile = OutFileName
!rm -r fileconvert.sh
import os
print("Hi , Sanheen Here !")
print()
f = open("fileconvert.sh","w")
f.write(f"ffmpeg -i '{filename}' -c:v libx264 -c:a aac '/content/drive/MyDrive/SV_ProgrammingGFG/con_{outfile}.mp4'")
print(f"Converting ({filename}) => ({outfile}.mp4)")
print("*******************")
print()
!sh fileconvert.sh
print()
print("*******************")
print()
print(f"File : {filename} -> {outfile}.mp4 Converted Successfully !")
print()
print("Output file is in your drive Folder name : SV_ProgrammingGFG")
print("Thankyou ! 😋")<jupyter_output><empty_output><jupyter_text>Convert The Whole Folder ! - Enter your Folder Full Path from the **Show File Browser > drive > MyDrive** in menu of Google Colab- Just Wait Now ! Drink Coffee ...- **Make Sure, You have Space in your Drive - otherwise Converting Single File is the best option**<jupyter_code>#@title Convert Directory {display-mode:"form",run:"auto"} 
DirectoryPath = ''  #@param {type:"string"}
 
 
print('Hi, Sanheen Here !')
print()
!rm -rvf ProgrammingGFG
!mkdir ProgrammingGFG
!mkdir /content/drive/MyDrive/GFGMP4
!rm -r convert.sh
 
print()
print("I will Copy Files in your drive in GFGMP4 folder")
print()
print("******* START *******")
import os
 
def getListOfFiles(dirName):
    # create a list of file and sub directories 
    # names in the given directory 
    listOfFile = os.listdir(dirName)
    allFiles = list()
    # Iterate over all the entries
    for entry in listOfFile:
        # Create full path
        fullPath = os.path.join(dirName, entry)
        # If entry is a directory then get the list of files in this directory 
        if os.path.isdir(fullPath):
            allFiles = allFiles + getListOfFiles(fullPath)
        else:
            allFiles.append(fullPath)
                
    return allFiles        
def main():
    
    dirName = DirectoryPath
    
    # Get the list of all files in directory tree at given path
    listOfFiles = list()
    filename = list()
    for (dirpath, dirnames, filenames) in os.walk(dirName):
        listOfFiles += [os.path.join(dirpath, file) for file in filenames if '.ts' in file]
        filename += [file for file in filenames if '.ts' in file]
        
 
    c = 1
    f = open("convert.sh","a+")
    i = 0
    for elem in listOfFiles:
        print(f"Reading File {c}")
        s = f"ffmpeg -i '{elem}' -c:v libx264 -c:a aac '/content/drive/MyDrive/GFGMP4/out_{filename[i]}.mp4'"
        #v = f"cp -vf 'ProgrammingGFG/output{c}.mp4' '/content/drive/MyDrive/GFGMP4/{filename[i]}.mp4'"
        f.write(s+"\n")
        #f.write(v+"\n")
        print(s)
        #print(v)
        c=c+1
        i = i+1
    f.close()
 
 
if __name__ == '__main__':
    print("Converting All Files ... It will Take Time !")
    print("*************")
    main()
 
!sh convert.sh
print()
print("******* END *******")
print("Files are in your drive Folder Name - GFGMP4")
print()
print("Thankyou ! 😋")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13795454545454544, 'fraction_numerical': 0.008181818181818182, 'mean_word_length': 3.691897654584222, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '91665', 'license': 'MIT', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1373, 'n_words': 458, 'path': 'Convert_TS_to_MP4.ipynb', 'repo_name': 'sanheensethi/TS-to-MP4', 'size': '4400'}