mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-12-02 16:14:15 +01:00
postprocess: better handling when its separated tracks
This commit is contained in:
parent
b428bcc398
commit
32e54c773e
@ -115,9 +115,9 @@ class postprocess:
|
|||||||
tempfile = "{}.temp".format(orig_filename)
|
tempfile = "{}.temp".format(orig_filename)
|
||||||
arguments = []
|
arguments = []
|
||||||
if videotrack:
|
if videotrack:
|
||||||
arguments += ["-map", "0:{}".format(videotrack)]
|
arguments += ["-map", "{}".format(videotrack)]
|
||||||
if audiotrack:
|
if audiotrack:
|
||||||
arguments += ["-map", "0:{}".format(audiotrack)]
|
arguments += ["-map", "{}".format(audiotrack)]
|
||||||
arguments += ["-c", "copy", "-f", "mp4"]
|
arguments += ["-c", "copy", "-f", "mp4"]
|
||||||
if ext == ".ts" and "aac" in self._getcodec(streams, audiotrack):
|
if ext == ".ts" and "aac" in self._getcodec(streams, audiotrack):
|
||||||
arguments += ["-bsf:a", "aac_adtstoasc"]
|
arguments += ["-bsf:a", "aac_adtstoasc"]
|
||||||
@ -168,8 +168,9 @@ class postprocess:
|
|||||||
return
|
return
|
||||||
|
|
||||||
orig_filename = formatname(self.stream.output, self.config, self.stream.output_extention)
|
orig_filename = formatname(self.stream.output, self.config, self.stream.output_extention)
|
||||||
|
name, ext = os.path.splitext(orig_filename)
|
||||||
cmd = [self.detect, "-i", orig_filename]
|
audio_filename = "{}.audio.ts".format(name)
|
||||||
|
cmd = [self.detect, "-i", orig_filename, "-i", audio_filename]
|
||||||
_, stdout, stderr = run_program(cmd, False) # return 1 is good here.
|
_, stdout, stderr = run_program(cmd, False) # return 1 is good here.
|
||||||
streams = self._streams(stderr)
|
streams = self._streams(stderr)
|
||||||
videotrack, audiotrack = self._checktracks(streams)
|
videotrack, audiotrack = self._checktracks(streams)
|
||||||
@ -180,23 +181,21 @@ class postprocess:
|
|||||||
logging.info("Merge audio and video into {}".format(orig_filename))
|
logging.info("Merge audio and video into {}".format(orig_filename))
|
||||||
|
|
||||||
tempfile = "{}.temp".format(orig_filename)
|
tempfile = "{}.temp".format(orig_filename)
|
||||||
name, ext = os.path.splitext(orig_filename)
|
|
||||||
arguments = ["-c:v", "copy", "-c:a", "copy", "-f", "mp4"]
|
arguments = ["-c:v", "copy", "-c:a", "copy", "-f", "mp4"]
|
||||||
if ext == ".ts":
|
if ext == ".ts":
|
||||||
audio_filename = "{}.audio.ts".format(name)
|
|
||||||
if audiotrack and "aac" in self._getcodec(streams, audiotrack):
|
if audiotrack and "aac" in self._getcodec(streams, audiotrack):
|
||||||
arguments += ["-bsf:a", "aac_adtstoasc"]
|
arguments += ["-bsf:a", "aac_adtstoasc"]
|
||||||
else:
|
else:
|
||||||
audio_filename = "{}.m4a".format(name)
|
audio_filename = "{}.m4a".format(name)
|
||||||
cmd = [self.detect, "-i", orig_filename, "-i", audio_filename]
|
cmd = [self.detect, "-i", orig_filename, "-i", audio_filename]
|
||||||
|
|
||||||
if videotrack:
|
if videotrack:
|
||||||
arguments += ["-map", "0:{}".format(videotrack)]
|
arguments += ["-map", "{}".format(videotrack)]
|
||||||
if audiotrack:
|
if audiotrack:
|
||||||
arguments += ["-map", "0:{}".format(audiotrack)]
|
arguments += ["-map", "{}".format(audiotrack)]
|
||||||
if self.config.get("merge_subtitle"):
|
if self.config.get("merge_subtitle"):
|
||||||
langs = self.sublanguage()
|
langs = self.sublanguage()
|
||||||
for stream_num, language in enumerate(langs, start=audiotrack + 1):
|
tracks = [x for x in [videotrack, audiotrack] if x]
|
||||||
|
for stream_num, language in enumerate(langs, start=len(tracks)):
|
||||||
arguments += [
|
arguments += [
|
||||||
"-map",
|
"-map",
|
||||||
str(stream_num),
|
str(stream_num),
|
||||||
@ -232,7 +231,7 @@ class postprocess:
|
|||||||
os.rename(tempfile, orig_filename)
|
os.rename(tempfile, orig_filename)
|
||||||
|
|
||||||
def _streams(self, output):
|
def _streams(self, output):
|
||||||
return re.findall(r"Stream \#\d:(\d)[\[\(][^\[]+[\]\)]([\(\)\w]+)?: (Video|Audio): (.*)", output)
|
return re.findall(r"Stream \#(\d:\d)([\[\(][^\[]+[\]\)])?([\(\)\w]+)?: (Video|Audio): (.*)", output)
|
||||||
|
|
||||||
def _getcodec(self, streams, number):
|
def _getcodec(self, streams, number):
|
||||||
for stream in streams:
|
for stream in streams:
|
||||||
@ -243,10 +242,10 @@ class postprocess:
|
|||||||
videotrack = None
|
videotrack = None
|
||||||
audiotrack = None
|
audiotrack = None
|
||||||
for stream in streams:
|
for stream in streams:
|
||||||
if stream[2] == "Video":
|
if stream[3] == "Video":
|
||||||
videotrack = stream[0]
|
videotrack = stream[0]
|
||||||
if stream[2] == "Audio":
|
if stream[3] == "Audio":
|
||||||
if stream[3] == "mp3, 0 channels":
|
if stream[4] == "mp3, 0 channels":
|
||||||
continue
|
continue
|
||||||
audiotrack = stream[0]
|
audiotrack = stream[0]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user