Skip to content

Instantly share code, notes, and snippets.

@gardenunez
Created December 9, 2017 18:03
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 gardenunez/41c85479f603bbd46007a750e86511d9 to your computer and use it in GitHub Desktop.
Save gardenunez/41c85479f603bbd46007a750e86511d9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import sys
walk_dir = os.getcwd()
count = 0
def from_ts_to_mp4(source_file, dest_file):
os.system("ffmpeg -i {} -c:v copy -c:a copy {}".format(source_file, dest_file))
def walk_and_convert(root_dir, convert):
count = 0
for root, subdirs, files in os.walk(root_dir):
for file in files:
if (file.split(".")[-1].lower() == 'ts'):
source_file = os.path.join(root, file)
dest_file = os.path.join(root, os.path.splitext(source_file)[0] + ".mp4")
convert(source_file, dest_file)
count = count + 1
print("{} --> {}".format(source_file, dest_file))
print("total number of file converted: {}".format(count))
if __name__ == '__main__':
walk_and_convert(sys.argv[1], convert=from_ts_to_mp4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment