Skip to content

Commit

Permalink
added options for interval and skip-credits
Browse files Browse the repository at this point in the history
  • Loading branch information
mutschler committed Feb 9, 2017
1 parent 981f5ee commit 412f5dd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
26 changes: 15 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
# Changelog

## develop
## 1.0.8 (09 Feb 2017)

### New
- option to specify an interval (in seconds) instead of numcaps (`--interval`)
- option which tries to skip ending credits by cuttin of 4 minutes of the movie (`--skip-credits`)

### Changes
- print errors when uploading fails

- with 1.0.8 the default behaviour of mt changed, `skip-credits` is now an opt-in and not the default anymore

## 1.0.7 (20 Nov 2016)

### New
- options for blur and blank threshold
- option to upload generated image to a given url (--upload and --upload-url)
- option to upload generated image to a given url (`--upload` and `--upload-url`)

### Changes
- improve usage of different skip functions when used in combination
- changed help message for some flags
- dont append {{Count}} to filename when useing --single-images with --numcap 1
- dont append `{{Count}}` to filename when useing `--single-images` with `--numcap 1`
- Fix an error where Resulution wasn't correctly added to header

## 1.0.6 (10 Jun 2016)

### New
- option to generate WEBVTT Files (--webvtt)
- option to generate WEBVTT Files (`--webvtt`)

## 1.0.5 (07 Jun 2016)

### New
- option to put a watermark on the bottom-left corner of each image (--watermark-all)
- option to append a comment to the header area (--comment)
- option to list used config values (--show-config)
- experimental function for blur detection (--skip-blurry)
- option to put a watermark on the bottom-left corner of each image (`--watermark-all`)
- option to append a comment to the header area (`--comment`)
- option to list used config values (`--show-config`)
- experimental function for blur detection (`--skip-blurry`)

### Changes
- fixed a typo in config for skip_existing option
- fixed a typo in config for `skip-existing` option
- compatible with go 1.6 and ffmpeg 3.0

## 1.0.4 (07 Jan 2016)
Expand All @@ -54,7 +58,7 @@
- option to save current settings to a settings file
- include default font and images in the binary
- added new filters
- added --to and --from options to use specific parts of the video file only
- added `--to` and `--from` options to use specific parts of the video file only
- option to provide a custom output path

## 1.0.2 (24 Aug 2015)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ and load a custom config on runtime:
| overwrite | false | by default mt will increment the filename by adding -01 if there is already a jpg use --overwrite to overwrite the image instead |
| fast | false | makes mt faster a lot, but seeking will be more inacurate and may produce duplicate screens |
| webvtt | false | create a webvtt file for use with html5 video players |
| interval | 0 | creates a screencap every interval seconds, this overwrites numcaps |
| skip_credits | false | try to skip movie credits by cutting of 4 minutes or 10% of the length |

please note that all those values are also available as runtime pflags just replace the `_` with an `-` ex: `single_images` will get `single-images`

Expand Down
48 changes: 33 additions & 15 deletions mt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ var blankPixels int
var allPixels int
var mpath string
var fontBytes []byte
var version string = "1.0.7-dev"
var version string = "1.0.8"
var timestamps []string
var numcaps int

//gets the timestamp value ("HH:MM:SS") and returns an image
//TODO: rework this to take any string and a bool for full width/centered text
Expand Down Expand Up @@ -96,12 +97,14 @@ func GenerateScreenshots(fn string) []image.Image {
end = stringToMS(viper.GetString("end"))
}

percentage := int64((float32(duration / 100)) * (5.5 * 2))
//cut of 2 minutes of video if video has at least 4 minutes else cut away (or at least 10.10%)
if duration > (120000*2) && 120000 > percentage {
duration = duration - 120000
} else {
duration = duration - percentage
if viper.GetBool("skip_credits") {
percentage := int64((float32(duration / 100)) * (5.5 * 2))
//cut of 2 minutes of video if video has at least 4 minutes else cut away (or at least 10.10%)
if duration > (120000*2) && 120000 > percentage {
duration = duration - 120000
} else {
duration = duration - percentage
}
}

if end > 0 {
Expand All @@ -112,10 +115,17 @@ func GenerateScreenshots(fn string) []image.Image {
duration = duration - from
}

inc := duration / (int64(viper.GetInt("numcaps")))
numcaps = viper.GetInt("numcaps")
if viper.GetInt("interval") > 0 {
numcaps = int((duration / 1000) / int64(viper.GetInt("interval")))
log.Debugf("interval option set, numcaps are set to %d", numcaps)
viper.Set("columns", int(math.Sqrt(float64(numcaps))))
}

inc := duration / (int64(numcaps))

if end > 0 && from > 0 {
inc = duration / (int64(viper.GetInt("numcaps")) - 1)
inc = duration / (int64(numcaps) - 1)
}

if inc <= 60000 {
Expand All @@ -134,7 +144,7 @@ func GenerateScreenshots(fn string) []image.Image {
timestamps = append(timestamps, "00:00:00")
}

for i := 0; i < viper.GetInt("numcaps"); i++ {
for i := 0; i < numcaps; i++ {
stamp := d
img, err := gen.Image(d)
if err != nil {
Expand All @@ -150,7 +160,7 @@ func GenerateScreenshots(fn string) []image.Image {
log.Warnf("[%d/%d] frame skipped based on settings at: %s retry at: %s", count, maxCount, fmt.Sprintf(time.Unix(stamp/1000, 0).UTC().Format("15:04:05")), fmt.Sprintf(time.Unix((stamp+10000)/1000, 0).UTC().Format("15:04:05")))
if stamp >= duration-inc {
log.Error("end of clip reached... no more blank frames can be skipped")
i = viper.GetInt("numcaps") - 1
i = numcaps - 1
break
}
stamp = d + (10000 * int64(count))
Expand All @@ -165,7 +175,7 @@ func GenerateScreenshots(fn string) []image.Image {
}

timestamp := fmt.Sprintf(time.Unix(stamp/1000, 0).UTC().Format("15:04:05"))
log.Infof("generating screenshot %02d/%02d at %s", i+1, viper.GetInt("numcaps"), timestamp)
log.Infof("generating screenshot %02d/%02d at %s", i+1, numcaps, timestamp)
if viper.GetBool("webvtt") {
timestamps = append(timestamps, timestamp)
}
Expand Down Expand Up @@ -230,7 +240,7 @@ func GenerateScreenshots(fn string) []image.Image {
}

//watermark middle image
if i == (viper.GetInt("numcaps")-1)/2 && viper.GetString("watermark") != "" && !viper.GetBool("single_images") {
if i == (numcaps-1)/2 && viper.GetString("watermark") != "" && !viper.GetBool("single_images") {
ov, err := imaging.Open(viper.GetString("watermark"))
if err == nil {
if ov.Bounds().Dx() > img.Bounds().Dx() {
Expand Down Expand Up @@ -276,7 +286,7 @@ func GenerateScreenshots(fn string) []image.Image {

if viper.GetBool("single_images") {
var fname string
if viper.GetInt("numcaps") == 1 {
if numcaps == 1 {
fname = getSavePath(mpath, 0)
} else {
fname = getSavePath(mpath, i+1)
Expand Down Expand Up @@ -514,7 +524,7 @@ func main() {
viper.SetDefault("header_image", "")
viper.SetDefault("header_meta", false)
viper.SetDefault("watermark", "")
viper.SetDefault("comment", "")
viper.SetDefault("comment", "contactsheet created with mt (https://github.com/mutschler/mt)")
viper.SetDefault("watermark-all", "")
viper.SetDefault("filter", "none")
viper.SetDefault("skip_blank", false)
Expand All @@ -529,6 +539,8 @@ func main() {
viper.SetDefault("blank_threshold", 85)
viper.SetDefault("upload", false)
viper.SetDefault("upload_url", "http://example.com/upload")
viper.SetDefault("skip_credits", false)
viper.SetDefault("interval", 0)

flag.IntP("numcaps", "n", viper.GetInt("numcaps"), "number of captures to make")
viper.BindPFlag("numcaps", flag.Lookup("numcaps"))
Expand Down Expand Up @@ -644,6 +656,12 @@ func main() {
flag.String("upload-url", viper.GetString("upload_url"), "url to use for --upload")
viper.BindPFlag("upload_url", flag.Lookup("upload-url"))

flag.IntP("interval", "i", viper.GetInt("interval"), "interval in seconds to take screencaps from, overwrites numcaps (defaults to 0)")
viper.BindPFlag("interval", flag.Lookup("interval"))

flag.Bool("skip-credits", viper.GetBool("skip_credits"), "tries to skip ending credits from screencap creation by cutting off 4 minutes or 10 percent of the clip (defaults to false)")
viper.BindPFlag("skip_credits", flag.Lookup("skip-credits"))

viper.AutomaticEnv()

viper.SetConfigType("json")
Expand Down
8 changes: 5 additions & 3 deletions mt.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
"watermark": "",
"fast": false,
"watermark_all": "",
"comment": "made with mt and some love...",
"comment": "contactsheet created with mt (https://github.com/mutschler/mt)",
"skip_blurry": false,
"blur_threshold": 62,
"blank_threshold": 85,
"webvtt": false
}
"webvtt": false,
"upload": false,
"upload_url": "http://example.com/upload"
}

0 comments on commit 412f5dd

Please sign in to comment.