@@ -41,7 +41,7 @@ const _encodedExt = "_.mkv"
4141// Global variables definitions
4242
4343var (
44- version = "1.5.01 "
44+ version = "1.5.02 "
4545 date = "2019-11-10"
4646
4747 sprintf = fmt .Sprintf
@@ -227,16 +227,18 @@ func transcodeFile(inputName string) {
227227 }
228228 debug (fsinfo , 4 )
229229 // if there are more than one audio stream
230- if len (regexp .MustCompile (`Stream #0:.+: Audio: ` ).
231- FindAllStringSubmatch (fsinfo , - 1 )) > 1 {
230+ allAudioStreams := regexp .MustCompile (`Stream #0:.+: Audio: (.+)` ).
231+ FindAllStringSubmatch (fsinfo , - 1 )
232+ if len (allAudioStreams ) > 1 {
232233 // then find the designated audio stream language
233234 audioStreams := regexp .
234- MustCompile (`Stream #(.* )\(` + Opts .Lang + `\): Audio: ` ).
235+ MustCompile (`Stream #(.+ )\(` + Opts .Lang + `\): Audio: (.+) ` ).
235236 FindStringSubmatch (fsinfo )
236237 if len (audioStreams ) >= 1 {
237238 // and use the 1st audio stream of the designated language
238239 debug (audioStreams [1 ], 3 )
239240 Opts .AEP += "-map " + audioStreams [1 ]
241+ dealSurroundSound (audioStreams [2 ])
240242 // when `-map` is used (for audio), then all else need mapping as well
241243 videoStreams := regexp .MustCompile (`Stream #(.+): Video: ` ).
242244 FindStringSubmatch (fsinfo )
@@ -248,8 +250,10 @@ func transcodeFile(inputName string) {
248250 Opts .SEP += "-map " + subtitleStream [1 ]
249251 }
250252 }
253+ // else: designated audio language not found, use `default` instead
251254 } else {
252255 debug (inputName + " has single audio stream" , 2 )
256+ dealSurroundSound (allAudioStreams [0 ][1 ])
253257 }
254258 }
255259
@@ -267,12 +271,15 @@ func transcodeFile(inputName string) {
267271 fmt .Printf ("%s: to execute -\n %s %s\n " ,
268272 progname , Opts .FFMpeg , strings .Join (args , " " ))
269273 } else {
274+ //fmt.Printf("] %#v\n", args)
270275 cmd := exec .Command (Opts .FFMpeg , args ... )
271- var out bytes.Buffer
276+ var out , errOut bytes.Buffer
272277 cmd .Stdout = & out
278+ cmd .Stderr = & errOut
273279 err := cmd .Run ()
274280 if err != nil {
275- log .Printf ("%s: Exec error - %s" , progname , err .Error ())
281+ log .Printf ("%s: Exec error - %s\n \n %s" , progname , err .Error (),
282+ string (errOut .Bytes ()))
276283 }
277284 fmt .Printf ("%s\n " , out .String ())
278285 timeTake := time .Since (startTime )
@@ -300,6 +307,14 @@ func transcodeFile(inputName string) {
300307 return
301308}
302309
310+ // dealSurroundSound will append to Opts.AEP proper setting to encode
311+ // 5.1 surround sound channels
312+ func dealSurroundSound (channelFeatures string ) {
313+ if regexp .MustCompile (`, 5.1\(side\), ` ).MatchString (channelFeatures ) {
314+ Opts .AEP += " -mapping_family 1 -af channelmap=channel_layout=5.1"
315+ }
316+ }
317+
303318func probeFile (inputName string ) (string , error ) {
304319 out := & bytes.Buffer {}
305320
0 commit comments