[LINUX] Remove unwanted audio+subs
Re: [LINUX] Remove unwanted audio+subs
Works perfect !!! Thanks !
Re: [LINUX] Remove unwanted audio+subs
I discovered and fixed a bug. Please update.
Re: [LINUX] Remove unwanted audio+subs
Okay, thanks
Re: [LINUX] Remove unwanted audio+subs
That change you made (streamnumber) doesnt work
I switched back to the "cmd = 'mkvmerge -o "' + cleanmoviename + '" -a 1 --nosubs "' + mkvfilename + '"'" method and it works fine ?
This is my sab script log:
I switched back to the "cmd = 'mkvmerge -o "' + cleanmoviename + '" -a 1 --nosubs "' + mkvfilename + '"'" method and it works fine ?
This is my sab script log:
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
Re: [LINUX] Remove unwanted audio+subs
The problem is seen here in the log you posted:
That should be a number.
The ffmpeg output line that works in my code:
Your line with ffmpeg output, that does not work in my code:
... so the difference is the #0:1 versus #0.1 ... the : versus .
Solution: a regular expression
Proof that that works:
I'll put that in the code
Code: Select all
Stream #0.1(ger): Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s (default)
Language found in stream Audio
The ffmpeg output line that works in my code:
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)
Solution: a regular expression
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'
>>>
I'll put that in the code
Re: [LINUX] Remove unwanted audio+subs
Code tested and published: https://raw.githubusercontent.com/sande ... nd-subs.py
Re: [LINUX] Remove unwanted audio+subs
Wonderfull, thanks !
Re: [LINUX] Remove unwanted audio+subs
Got some problems with permissions after mkv got finaly renamed back to original name. (OMV System with aufs pool)
So i added a chmod option, works fine:
Maybe others can also need it.
Have no experience with github, so no idea how to add something like that, sorry
*EDIT*
I think i got pulled on your fork
So i added a chmod option, works fine:
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)
Have no experience with github, so no idea how to add something like that, sorry
*EDIT*
I think i got pulled on your fork
Re: [LINUX] Remove unwanted audio+subs
Hi,
I have made a few alterations to the script. One thing I would like to know is, if it is possible to set the audio track name to
eg. English - Dolby Digital 2.0
and also set the container title to the movie title or episode number and title
I have made a few alterations to the script. One thing I would like to know is, if it is possible to set the audio track name to
Code: Select all
languageName - codec channels
and also set the container title to the movie title or episode number and title
Re: [LINUX] Remove unwanted audio+subs
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
In other words: show how you do that with ffmpeg. Then I can help with the script
Re: [LINUX] Remove unwanted audio+subs
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)
Re: [LINUX] Remove unwanted audio+subs
ffprobe "/gdrive/movies/Despicable Me (2010)/Despicable Me (2010) - 2D.AVC.h264.DTS-HD MA [5.1].Bluray-1080p.mkv"
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
Re: [LINUX] Remove unwanted audio+subs
Hi @sander, can you offer any assistance with this script?