Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf8 -*-
- # This script converts all DTS streams inside an MKV to AC3 and adds them to the MKV file
- # The newly generated MKV is stored in the target directory
- # Import module OS
- import os, sys
- param_count = len(sys.argv)
- # Print commandline if not enough parameters are given
- if param_count < 2:
- print "mkvdts@ac3 - The DTS / DTS-HD to AC3 converter"
- print
- print "Usage: mkvdts@ac3 /path/to/my.movie.mkv /path/to/output/"
- quit()
- # Get source MKV from MKV
- source_mkv = sys.argv[1]
- # Get target directory from CLI
- target_dir = sys.argv[2]
- # Get track information of source MKV
- tracks = os.popen ("mkvmerge -i " + source_mkv )
- # Check for existence of DTS streams
- check_DTS = os.popen ("mkvmerge -i " + source_mkv + " \| grep DTS")
- print check_DTS
- quit()
- track_count = 1
- ac3_tracks = []
- # Loop through all tracks
- for track in tracks:
- # Only process strings with "Track ID" in them
- if track.find ('Track ID') <> -1:
- # Remove whitespaces
- track = track.strip()
- if track.find ('A_DTS') <> -1:
- extension = 'dts'
- # Extract DTS / DTS-HD stream from MKV
- extract_command = "nice -n 19 ionice -c3 mkvextract tracks " + source_mkv + " " + str (track_count) +":/tmp/Track_" + str (track_count) + "." + extension
- print extract_command
- os.popen ( extract_command )
- # Convert DTS / DTS-HD stream to 6 channel AC3
- convert_command = "nice -n 19 ionice -c3 ffmpeg -i " + "/tmp/Track_" + str (track_count) + "." + extension + " -acodec ac3 -ac 6 -ab 448k -y /tmp/Track_" + str (track_count) + ".ac3"
- print convert_command
- os.popen ( convert_command )
- # Remember generated AC3 stream for later remuxing
- ac3_tracks.append ("/tmp/Track_" + str (track_count) + ".ac3")
- # Clean up converted DTS / DTS-HD stream
- os.remove ("/tmp/Track_" + str (track_count) + "." + extension)
- # Increase track count
- track_count = track_count + 1
- cl = ""
- # Generate list of all available AC3 files for remux
- for ac3_track in ac3_tracks:
- cl = cl + " " + ac3_track
- # Target MKV = source MKV filename plus output path
- target_mkv = target_dir + os.path.basename(source_mkv)
- # Merge generated AC3 streams with old MKV to new MKV
- command = "mkvmerge -o " + target_mkv + " " + source_mkv + " " + cl
- print command
- os.popen (command)
- # Clean up temporary generated AC3 tracks
- for ac3_track in ac3_tracks:
- os.remove (ac3_track)
Add Comment
Please, Sign In to add comment