Re: [LINUX] Remove unwanted audio+subs
Posted: February 14th, 2015, 1:28 pm
Works perfect !!! Thanks !
Code: Select all
Step 1
Directory is /media/4fb18d2a-662b-4868-bc60-c0d6e5001b25/DATA/_DOWNLOAD/serien/tv/The.Walking.Dead.S03E01.Seed.GERMAN.DUBBED.720p.WebHD.h264-euHD
Step 2
Language ger to be kept
Searching: /media/4fb18d2a-662b-4868-bc60-c0d6e5001b25/DATA/_DOWNLOAD/serien/tv/The.Walking.Dead.S03E01.Seed.GERMAN.DUBBED.720p.WebHD.h264-euHD
/media/4fb18d2a-662b-4868-bc60-c0d6e5001b25/DATA/_DOWNLOAD/serien/tv/The.Walking.Dead.S03E01.Seed.GERMAN.DUBBED.720p.WebHD.h264-euHD/euhd-walking-s03e01-720p.mkv
cmd is ffmpeg -i "/media/4fb18d2a-662b-4868-bc60-c0d6e5001b25/DATA/_DOWNLOAD/serien/tv/The.Walking.Dead.S03E01.Seed.GERMAN.DUBBED.720p.WebHD.h264-euHD/euhd-walking-s03e01-720p.mkv" 2>&1 | grep -i -e Audio:
Stream #0.1(ger): Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s (default)
Language found in stream Audio
Go on
cleanmoviename /media/4fb18d2a-662b-4868-bc60-c0d6e5001b25/DATA/_DOWNLOAD/serien/tv/The.Walking.Dead.S03E01.Seed.GERMAN.DUBBED.720p.WebHD.h264-euHD/cleanedmovie.mkv
command is mkvmerge -o "/media/4fb18d2a-662b-4868-bc60-c0d6e5001b25/DATA/_DOWNLOAD/serien/tv/The.Walking.Dead.S03E01.Seed.GERMAN.DUBBED.720p.WebHD.h264-euHD/cleanedmovie.mkv" -a Audio --nosubs "/media/4fb18d2a-662b-4868-bc60-c0d6e5001b25/DATA/_DOWNLOAD/serien/tv/The.Walking.Dead.S03E01.Seed.GERMAN.DUBBED.720p.WebHD.h264-euHD/euhd-walking-s03e01-720p.mkv"
mkvmerge v7.5.0 ('Glass Culture') 64bit built on Jan 4 2015 17:21:29
Error: Invalid track ID in '-a Audio'.
Cleaning up
Traceback (most recent call last):
File "/home/sabnzbd/.sabnzbd/scripts/mkv-process-audio-and-subs.py", line 60, in <module>
handlemkv(fullname)
File "/home/sabnzbd/.sabnzbd/scripts/mkv-process-audio-and-subs.py", line 43, in handlemkv
os.rename(cleanmoviename, mkvfilename)
OSError: [Errno 2] No such file or directory
Code: Select all
Stream #0.1(ger): Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s (default)
Language found in stream Audio
Code: Select all
Stream #0:1(ger): Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s (default)
Code: Select all
Stream #0.1(ger): Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s (default)
Code: Select all
re.findall(r"[\w']+", thisline)[2]
Code: Select all
>>> re.findall(r"[\w']+", 'Stream #0:1(ger): Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s (default)' )[2]
'1'
>>> re.findall(r"[\w']+", 'Stream #0.1(ger): Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s (default)' )[2]
'1'
>>>
Code: Select all
# Delete original mkv, rename new one to original name and chmod it
print "Cleaning up"
os.remove(mkvfilename)
os.rename(cleanmoviename, mkvfilename)
os.chmod(mkvfilename, 0777)
Code: Select all
languageName - codec channels
Nice. Which ones?
You can try on the CLI with ffmpeg. If that works, you can put it in the script.schmitty wrote: ↑May 9th, 2019, 12:16 am One thing I would like to know is, if it is possible to set the audio track name toeg. English - Dolby Digital 2.0Code: Select all
languageName - codec channels
and also set the container title to the movie title or episode number and title
Code: Select all
#!/usr/bin/env python
### NZBGET POST-PROCESSING SCRIPT
import os
import sys
import re
## Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
language = 'eng' # 3 letters, lower case!
languageName = 'English' # Use in track titles
def handlemkv(mkvfilename):
print mkvfilename
# find Audio streams
# ffmpeg -i *.mkv 2>&1 | grep -i -e Audio:
# Example output:
# Stream #0:1(ger): Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s (default)
# Stream #0:2(jpn): Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s
cmd = 'ffmpeg -i "' + mkvfilename + '" 2>&1 | grep -i -e Audio:'
print "cmd is", cmd
streamnumber = -1
for thisline in os.popen(cmd).readlines():
print thisline.rstrip()
if thisline.find(language)>=0:
try:
# streamnumber = thisline.split(':')[1].split('(')[0]
streamnumber = re.findall(r"[\w']+", thisline)[2]
print "Stream number", streamnumber
streamnumber = int(streamnumber) # force it to be an integer so we know we found correct info
except:
print "Something went wrong with find the stream number. Please report with logfile"
sys.exit(0)
break
if streamnumber >= 0:
print "Language found in stream", streamnumber
else:
print("Language %s not found" % (language))
return()
print "Go on"
# leave only one audio stream, remove all subs
# mkvmerge -o new2.mkv -a 1 --nosubs movie-Ger-Jap-Dub.mkv
directory, filename = os.path.split(mkvfilename)
cleanmoviename = os.path.join(directory, "cleanedmovie.mkv")
print "cleanmoviename", cleanmoviename
cmd = 'mkvmerge -o "' + cleanmoviename + '" --edit track:v1 + ' --delete name + ' -a ' + str(streamnumber) + ' --edit track:a1 + ' --delete name + ' --edit track:s1 + ' --delete name + ' --track-name=languageName + ' --no-global-tags + ' --no-attachments ' "' + mkvfilename + '"'
print "command is", cmd
for thisline in os.popen(cmd).readlines():
print thisline.rstrip()
# Delete original mkv, rename new one to original name and chmod it
print "Cleaning up"
os.remove(mkvfilename)
os.rename(cleanmoviename, mkvfilename)
os.chmod(mkvfilename, 0775)
try:
root = sys.argv[1]
except:
print "Define directory on the commandline"
sys.exit(1)
print("Language %s to be kept" % (language))
print "Searching:", root
for path, subdirs, files in os.walk(root):
for name in files:
fullname = os.path.join(path, name)
if os.path.splitext(fullname)[1].lower() == '.mkv':
print "Found mkv", fullname
handlemkv(fullname)
Stream #0:1(eng): Audio: dts (DTS-HD MA), 48000 Hz, 5.1(side), s32p (24 bit) (default)
Metadata:
title : English - DTS-HD MA 5.1
BPS-eng : 3963126
DURATION-eng : 01:34:41.686000000
NUMBER_OF_FRAMES-eng: 532658
NUMBER_OF_BYTES-eng: 2814655180
_STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2019-03-30 03:15:58
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES