예제 #1
0
// Execute processes a command instruction.
func (c *SpriteCommand) Execute(inFile, outFile string) {
	defer func() {
		(*c.chanFinished) <- true
	}()

	f := ffmpeg.New(inFile)
	f.SkipSeconds = core.Opts.SkipSeconds

	len := int(f.Length())
	interval := 0
	if len < core.Opts.Count {
		interval = len
	} else {
		interval = len / core.Opts.Count
	}

	width := 180
	if core.Opts.Width != 0 {
		width = core.Opts.Width
	}

	err := f.CreateThumbnailSprite(interval, width, outFile)
	if err != nil {
		(*c.chanError) <- err
		return
	}

	core.VPrintf("Sprite thumbnail for video %q written to %q.", inFile, outFile)
}
예제 #2
0
// ServeHTTP implements http.Handler.ServeHTTP.
func (h *SimpleHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	file := getFile(w, r)
	if file == nil {
		return
	}

	width := DefaultSimpleWidth
	skip := core.Opts.SkipSeconds

	query := r.URL.Query()
	if w, ok := query["width"]; ok {
		width = atoi(w[0])
	}
	if s, ok := query["skip"]; ok {
		skip = atoi(s[0])
	}

	temp := getTempFile()
	ff := ffmpeg.New(file.Temp)
	ff.SkipSeconds = skip

	err := ff.CreateThumbnail(width, temp)
	if err != nil {
		numErrors++
		w.WriteHeader(500)
		w.Write([]byte(err.Error()))
		return
	}

	numRequests++
	w.Header().Set("Content-Disposition", "attachment; filename=thumbnail.jpg")
	w.Header().Set("Content-Type", "image/jpeg")
	writeFileToResponse(temp, w)
}
예제 #3
0
// Execute processes a command instruction.
func (c *SimpleCommand) Execute(inFile, outFile string) {
	defer func() {
		(*c.chanFinished) <- true
	}()

	f := ffmpeg.New(inFile)
	f.SkipSeconds = core.Opts.SkipSeconds

	err := f.CreateThumbnail(core.Opts.Width, outFile)
	if err != nil {
		(*c.chanError) <- err
		return
	}

	core.VPrintf("Simple thumbnail for video %q written to %q.", inFile, outFile)
}