Skip to content

Instantly share code, notes, and snippets.

@cnbeining
Created March 7, 2014 10: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 cnbeining/9408839 to your computer and use it in GitHub Desktop.
Save cnbeining/9408839 to your computer and use it in GitHub Desktop.
Python bath to remux media files in a folder
#!/usr/bin/env python
#coding:utf-8
# Author: Beining@ACICFG Tech Team
# Purpose: Batch convert media file type with ffmpeg.
# Created: 03/07/14
# MIT License
import os
import glob
print('''
-----------------------------------------
Batch convert mediafile type with remux
V 0.01
Beining@ACICFG
www.cnbeining.com
-----------------------------------------
''')
ffmpeg_location = input("Type the real location of ffmpeg. If left blank, I will use the default one under /usr/bin/.\nMake sure you use the latest version of ffmpeg.")
if ffmpeg_location == '':
ffmpeg_location = 'ffmpeg'
format_from = str(input('Type the format you want to convert from, without ".":'))
format_to = str(input('Type the format you want to convert to, without ".":'))
if_delete_original = int(input("Type 0 for not deleting original file(s), 1 for delete."))
info=os.getcwd()
print('My working folder is '+str(info))
file_to_convert_type = '*.'+format_from
file_list = glob.glob(file_to_convert_type)
print('Files to be remuxed:')
for filename in file_list:
print(filename+'\n')
total_file_number = str(len(file_list))
print('Total file number: '+total_file_number)
flag = 0
for filename in file_list:
name = filename.split('.')
real_name = name[0]
print('Converting ' + str(flag+1) + ' of ' + total_file_number + ' files...')
os.system(ffmpeg_location + ' -i ' + filename + ' -c:a copy -c:v copy ' + real_name + '.'+format_to)
if if_delete_original == 1:
try:
os.remove(filename)
pass
except:
print('Cannot delete ' + str(filename) + ' ! Do it by yourself...')
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment