Advertisement
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)
- if param_count == 1:
- print "mkvdts2ac3 - The DTS / DTS-HD to AC3 converter"
- print
- print "Usage: mkvdts2ac3 /path/to/my.movie.mkv"
- quit()
- # Get source MKV from MKV
- source_mkv = sys.argv[1]
- # Target MKV = source MKV filename plus output path
- target_mkv = source_mkv[:-3] + "AC3.mkv"
- # Get FPS of source MKV
- mkvinfo = os.popen ("mkvinfo " + source_mkv)
- fps = ""
- video_track = 0
- for info in mkvinfo:
- if info.find ("Tracktyp: video") <> -1:
- video_track = 1
- if video_track and info.find ("Standarddauer:") <> -1:
- fps = info
- video_track = 0
- fps = fps.split("(")[1].split(" ")[0].strip()
- # Get track information of source MKV
- tracks = os.popen ("mkvmerge -i " + source_mkv )
- 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()
- # Extract AC3 streams
- if track.find ('A_AC3') <> -1:
- extension = 'ac3'
- 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 )
- # Remember generated AC3 stream for later remuxing
- ac3_tracks.append ("/tmp/Track_" + str (track_count) + ".ac3")
- # Extract DTS / DTS-HD and convert to AC3
- 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 /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
- # Merge generated AC3 streams with old MKV (without any audio) to new MKV
- command = "mkvmerge -o " + target_mkv + " --no-audio " + source_mkv + " " + cl
- print command
- os.popen (command)
- # Clean up temporary generated AC3 tracks
- for ac3_track in ac3_tracks:
- os.remove (ac3_track)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement