Skip to content

Commit

Permalink
- [#] Choose streams by language, instead of streams index. Closes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
suntong committed Oct 9, 2021
1 parent 7c9d95a commit f649609
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions ffcvt.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,31 +282,13 @@ func transcodeFile(inputName string) {
allAudioStreams := regexp.MustCompile(`Stream #0:.+: Audio: (.+)`).
FindAllStringSubmatch(fsinfo, -1)
if len(allAudioStreams) > 1 {
// then find the designated audio stream language
audioStreams := regexp.
MustCompile(`Stream #(.+)\(` + Opts.Lang + `\): Audio: (.+)`).
FindStringSubmatch(fsinfo)
if len(audioStreams) >= 1 {
// and use the 1st audio stream of the designated language
// via *temporarily* tweaking AEP/VEP/SEP setting
oldAEP, oldVEP, oldSEP = Opts.AEP, Opts.VEP, Opts.SEP
oldEPUsed = true
debug(audioStreams[1], 3)

Opts.AEP += " -map " + audioStreams[1]
dealSurroundSound(audioStreams[2])
// when `-map` is used (for audio), then all else need mapping as well
videoStreams := regexp.MustCompile(`Stream #(.+?)(\(.+\))*: Video: `).
FindStringSubmatch(fsinfo)
Opts.VEP += " -map " + videoStreams[1]
subtitleStreams := regexp.MustCompile(`Stream #(.+)\(.+\): Subtitle: `).
FindAllStringSubmatch(fsinfo, -1)
// keep all subtitle streams
for _, subtitleStream := range subtitleStreams {
Opts.SEP += " -map " + subtitleStream[1]
}
}
// else: designated audio language not found, use `default` instead
// then use the designated audio stream language
// via *temporarily* using the AEP/VEP/SEP setting
oldAEP, oldVEP, oldSEP = Opts.AEP, Opts.VEP, Opts.SEP
oldEPUsed = true
Opts.VEP += " -map 0:v"
Opts.AEP += " -map 0:a:m:language:" + Opts.Lang
Opts.SEP += " -map 0:s"
} else {
debug(inputName+" has single audio stream", 2)
dealSurroundSound(allAudioStreams[0][1])
Expand Down

0 comments on commit f649609

Please sign in to comment.