Skip to content

Instantly share code, notes, and snippets.

@afcajamarcar
Created October 21, 2021 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afcajamarcar/31086f7ef7e6383a496ff388a20a7d01 to your computer and use it in GitHub Desktop.
Save afcajamarcar/31086f7ef7e6383a496ff388a20a7d01 to your computer and use it in GitHub Desktop.
Very simple python script which helps with the renaming and merging process of video parts with the same codec by using ffmpeg
import os # input/output library
import re # regular expressions library
import time # Terminator library
output_file_name = input('Enter output file name FXX_VXX_DD_MM_AAAA: ')
if output_file_name:
print(f'output file will be named {output_file_name}.MP4')
shortened_file_names = []
files_extension = "MTS"
file_name_regex = r"(\d\.)+MTS"
output_list_name = f'{str(int(time.time()))}_input.txt'
f = open(output_list_name, 'w')
for file_in_folder in os.listdir():
match = re.search(file_name_regex, file_in_folder)
if match:
renamed = match.group(0)
numeric_value = re.sub(f".{files_extension}", "", renamed)
double_to_sort = float(numeric_value)
shortened_file_names.append(double_to_sort)
os.rename(file_in_folder, f'{str(double_to_sort)}.{files_extension}')
shortened_file_names.sort()
for renamed_file in shortened_file_names:
f.write(f'file \'{str(renamed_file)}.{files_extension}\'\n')
f.close()
# Here I went lazy as fuck and created the merger in the renamer
merge_files = f'ffmpeg -f concat -i {output_list_name} -codec copy {output_file_name}.mp4'
os.system(merge_files)
else:
print('please provide a filename')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment