Skip to content

Commit

Permalink
- [!] able to deal with 5.1 surround sound channels now
Browse files Browse the repository at this point in the history
  • Loading branch information
suntong committed Nov 12, 2019
1 parent 00e3697 commit e876b54
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions ffcvt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const _encodedExt = "_.mkv"
// Global variables definitions

var (
version = "1.5.01"
version = "1.5.02"
date = "2019-11-10"

sprintf = fmt.Sprintf
Expand Down Expand Up @@ -227,16 +227,18 @@ func transcodeFile(inputName string) {
}
debug(fsinfo, 4)
// if there are more than one audio stream
if len(regexp.MustCompile(`Stream #0:.+: Audio: `).
FindAllStringSubmatch(fsinfo, -1)) > 1 {
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: `).
MustCompile(`Stream #(.+)\(` + Opts.Lang + `\): Audio: (.+)`).
FindStringSubmatch(fsinfo)
if len(audioStreams) >= 1 {
// and use the 1st audio stream of the designated language
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)
Expand All @@ -248,8 +250,10 @@ func transcodeFile(inputName string) {
Opts.SEP += "-map " + subtitleStream[1]
}
}
// else: designated audio language not found, use `default` instead
} else {
debug(inputName+" has single audio stream", 2)
dealSurroundSound(allAudioStreams[0][1])
}
}

Expand All @@ -267,12 +271,15 @@ func transcodeFile(inputName string) {
fmt.Printf("%s: to execute -\n %s %s\n",
progname, Opts.FFMpeg, strings.Join(args, " "))
} else {
//fmt.Printf("] %#v\n", args)
cmd := exec.Command(Opts.FFMpeg, args...)
var out bytes.Buffer
var out, errOut bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &errOut
err := cmd.Run()
if err != nil {
log.Printf("%s: Exec error - %s", progname, err.Error())
log.Printf("%s: Exec error - %s\n\n%s", progname, err.Error(),
string(errOut.Bytes()))
}
fmt.Printf("%s\n", out.String())
timeTake := time.Since(startTime)
Expand Down Expand Up @@ -300,6 +307,14 @@ func transcodeFile(inputName string) {
return
}

// dealSurroundSound will append to Opts.AEP proper setting to encode
// 5.1 surround sound channels
func dealSurroundSound(channelFeatures string) {
if regexp.MustCompile(`, 5.1\(side\), `).MatchString(channelFeatures) {
Opts.AEP += " -mapping_family 1 -af channelmap=channel_layout=5.1"
}
}

func probeFile(inputName string) (string, error) {
out := &bytes.Buffer{}

Expand Down

0 comments on commit e876b54

Please sign in to comment.