Skip to content

Commit 4ea19fa

Browse files
authored
Merge pull request #13 from suntong/fix/12
Fix/12
2 parents cacb683 + defc5df commit 4ea19fa

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Options struct {
3232
VSS bool // video: same size
3333
Cut mFlags // Cut segment(s) out to keep. Specify in the form of start-[end],\n\tstrictly in the format of hh:mm:ss, and may repeat
3434
Lang string // language selection for audio stream extraction
35+
SEL mFlags // subtitle encoding language (language picked for reencoded video)
3536
OptExtra string // more options that will pass to ffmpeg program
3637
A2Opus bool // audio encode to opus, using -abr
3738
V2X265 bool // video video encode to x265, using -crf
@@ -109,6 +110,8 @@ func init() {
109110
"Cut segment(s) out to keep. Specify in the form of start-[end],\n\tstrictly in the format of hh:mm:ss, and may repeat")
110111
flag.StringVar(&Opts.Lang, "lang", "eng",
111112
"language selection for audio stream extraction")
113+
flag.Var(&Opts.SEL, "sel",
114+
"subtitle encoding language (language picked for reencoded video)")
112115
flag.StringVar(&Opts.OptExtra, "o", "",
113116
"more options that will pass to ffmpeg program")
114117
flag.BoolVar(&Opts.A2Opus, "ato-opus", false,
@@ -266,7 +269,7 @@ func init() {
266269

267270
}
268271

269-
const usageSummary = " -t\ttarget type: webm/x265-opus/x264-mp3/wx/youtube (FFCVT_T)\n -ves\tvideo encoding method set (FFCVT_VES)\n -aes\taudio encoding method set (FFCVT_AES)\n -ses\tsubtitle encoding method set (FFCVT_SES)\n -vep\tvideo encoding method prepend (FFCVT_VEP)\n -aep\taudio encoding method prepend (FFCVT_AEP)\n -sep\tsubtitle encoding method prepend (FFCVT_SEP)\n -vea\tvideo encoding method append (FFCVT_VEA)\n -aea\taudio encoding method append (FFCVT_AEA)\n -abr\taudio bitrate (64k for opus, 256k for mp3) (FFCVT_ABR)\n -crf\tthe CRF value: 0-51. Higher CRF gives lower quality\n\t (28 for x265, ~ 23 for x264) (FFCVT_CRF)\n\n -d\tdirectory that hold input files (FFCVT_D)\n -f\tinput file name (either -d or -f must be specified) (FFCVT_F)\n -sym\tsymlinks will be processed as well (FFCVT_SYM)\n -exts\textension list for all the files to be queued (FFCVT_EXTS)\n -suf\tsuffix to the output file names (FFCVT_SUF)\n -ext\textension for the output file (FFCVT_EXT)\n -w\twork directory that hold output files (FFCVT_W)\n\n -ac\tcopy audio codec (FFCVT_AC)\n -vc\tcopy video codec (FFCVT_VC)\n -an\tno audio, output video only (FFCVT_AN)\n -vn\tno video, output audio only (FFCVT_VN)\n -vss\tvideo: same size (FFCVT_VSS)\n -C\tCut segment(s) out to keep. Specify in the form of start-[end],\n\tstrictly in the format of hh:mm:ss, and may repeat (FFCVT_C)\n -lang\tlanguage selection for audio stream extraction (FFCVT_LANG)\n -o\tmore options that will pass to ffmpeg program (FFCVT_O)\n -ato-opus\taudio encode to opus, using -abr (FFCVT_ATO_OPUS)\n -vto-x265\tvideo video encode to x265, using -crf (FFCVT_VTO_X265)\n\n -p\tpar2create, create par2 files (in work directory) (FFCVT_P)\n -nc\tno clobber, do not queue those already been converted (FFCVT_NC)\n -n\tno exec, dry run (FFCVT_N)\n\n -force\toverwrite any existing none-empty file (FFCVT_FORCE)\n -debug\tdebugging level (FFCVT_DEBUG)\n -ffmpeg\tffmpeg program executable name (FFCVT_FFMPEG)\n -ffprobe\tffprobe program execution (FFCVT_FFPROBE)\n -version\tprint version then exit (FFCVT_VERSION)\n\nDetails:\n\n"
272+
const usageSummary = " -t\ttarget type: webm/x265-opus/x264-mp3/wx/youtube (FFCVT_T)\n -ves\tvideo encoding method set (FFCVT_VES)\n -aes\taudio encoding method set (FFCVT_AES)\n -ses\tsubtitle encoding method set (FFCVT_SES)\n -vep\tvideo encoding method prepend (FFCVT_VEP)\n -aep\taudio encoding method prepend (FFCVT_AEP)\n -sep\tsubtitle encoding method prepend (FFCVT_SEP)\n -vea\tvideo encoding method append (FFCVT_VEA)\n -aea\taudio encoding method append (FFCVT_AEA)\n -abr\taudio bitrate (64k for opus, 256k for mp3) (FFCVT_ABR)\n -crf\tthe CRF value: 0-51. Higher CRF gives lower quality\n\t (28 for x265, ~ 23 for x264) (FFCVT_CRF)\n\n -d\tdirectory that hold input files (FFCVT_D)\n -f\tinput file name (either -d or -f must be specified) (FFCVT_F)\n -sym\tsymlinks will be processed as well (FFCVT_SYM)\n -exts\textension list for all the files to be queued (FFCVT_EXTS)\n -suf\tsuffix to the output file names (FFCVT_SUF)\n -ext\textension for the output file (FFCVT_EXT)\n -w\twork directory that hold output files (FFCVT_W)\n\n -ac\tcopy audio codec (FFCVT_AC)\n -vc\tcopy video codec (FFCVT_VC)\n -an\tno audio, output video only (FFCVT_AN)\n -vn\tno video, output audio only (FFCVT_VN)\n -vss\tvideo: same size (FFCVT_VSS)\n -C\tCut segment(s) out to keep. Specify in the form of start-[end],\n\tstrictly in the format of hh:mm:ss, and may repeat (FFCVT_C)\n -lang\tlanguage selection for audio stream extraction (FFCVT_LANG)\n -sel\tsubtitle encoding language (language picked for reencoded video) (FFCVT_SEL)\n -o\tmore options that will pass to ffmpeg program (FFCVT_O)\n -ato-opus\taudio encode to opus, using -abr (FFCVT_ATO_OPUS)\n -vto-x265\tvideo video encode to x265, using -crf (FFCVT_VTO_X265)\n\n -p\tpar2create, create par2 files (in work directory) (FFCVT_P)\n -nc\tno clobber, do not queue those already been converted (FFCVT_NC)\n -n\tno exec, dry run (FFCVT_N)\n\n -force\toverwrite any existing none-empty file (FFCVT_FORCE)\n -debug\tdebugging level (FFCVT_DEBUG)\n -ffmpeg\tffmpeg program executable name (FFCVT_FFMPEG)\n -ffprobe\tffprobe program execution (FFCVT_FFPROBE)\n -version\tprint version then exit (FFCVT_VERSION)\n\nDetails:\n\n"
270273

271274
// Usage function shows help on commandline usage
272275
func Usage() {

ffcvt.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,16 @@ func transcodeFile(inputName string) {
278278
return
279279
}
280280
debug(fsinfo, 4)
281-
// if there are more than one audio or subtitle stream
281+
/*
282+
283+
Cases when `-map`s are necessary
284+
285+
- more than one audio stream, and we pick eng stream only
286+
- more than one subtitle stream, and
287+
* output all subtitle streams (default, no -sel), or
288+
* pick specific subtitle stream(s) via -sel
289+
290+
*/
282291
allAudioStreams := regexp.MustCompile(`Stream #0:.+: Audio: (.+)`).
283292
FindAllStringSubmatch(fsinfo, -1)
284293
if len(allAudioStreams) > 1 ||
@@ -290,7 +299,14 @@ func transcodeFile(inputName string) {
290299
oldEPUsed = true
291300
Opts.VEP += " -map 0:v"
292301
Opts.AEP += " -map 0:a:m:language:" + Opts.Lang
293-
Opts.SEP += " -map 0:s"
302+
//log.Printf("%s: Opts.SEL - %#v", progname, Opts.SEL)
303+
if len(Opts.SEL) == 0 {
304+
Opts.SEP += " -map 0:s"
305+
} else {
306+
for _, val := range Opts.SEL {
307+
Opts.SEP += " -map 0:s:m:language:" + val
308+
}
309+
}
294310
} else {
295311
debug(inputName+" has single audio stream", 2)
296312
dealSurroundSound(allAudioStreams[0][1])

ffcvt_cli.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ templateFile=$GOPATH/src/github.com/go-easygen/easygen/test/commandlineFlag
66
exit 1
77
}
88

9-
easygen $templateFile ffcvt_cli | sed '/\tVES\t\tstring/{ N; N; N; N; N; N; N; N; N; s|^.*$|\tEncoding\t// anonymous field to hold encoding values|; }; /\tExt\t\tstring/d; /flag.MFlagsVar/{s/flag.MFlagsVar/flag.Var/; s/, "",/,/; } ' | gofmt > config.go
9+
easygen $templateFile ffcvt_cli | tee /tmp/ffcvt_cli.go | sed '/\tVES\t\tstring/{ N; N; N; N; N; N; N; N; N; s|^.*$|\tEncoding\t// anonymous field to hold encoding values|; }; /\tExt\t\tstring/d; /flag.MFlagsVar/{s/flag.MFlagsVar/flag.Var/; s/, "",/,/; } ' | gofmt > config.go

ffcvt_cli.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ Options:
192192
Value: '"eng"'
193193
Usage: "language selection for audio stream extraction"
194194

195+
- Name: SEL
196+
Type: mFlags
197+
Flag: sel
198+
Value: '""'
199+
Usage: "subtitle encoding language (language picked for reencoded video)"
200+
195201
- Name: OptExtra
196202
Type: string
197203
Flag: o

0 commit comments

Comments
 (0)