feat(ffmpeg): select frame by duration and float position
|
|
@ -243,9 +243,7 @@ func incrementDuration(av *AVContext, frame *C.AVFrame, i C.int) {
|
||||||
ptsToNano := C.int64_t(1000000000 * av.stream.time_base.num / av.stream.time_base.den)
|
ptsToNano := C.int64_t(1000000000 * av.stream.time_base.num / av.stream.time_base.den)
|
||||||
newDuration := time.Duration(frame.pts * ptsToNano)
|
newDuration := time.Duration(frame.pts * ptsToNano)
|
||||||
av.availableDuration = newDuration
|
av.availableDuration = newDuration
|
||||||
if av.selectedDuration > 0 && i > 0 && newDuration <= av.selectedDuration {
|
|
||||||
av.selectedIndex = i
|
|
||||||
}
|
|
||||||
if !av.durationInFormat && newDuration > av.duration {
|
if !av.durationInFormat && newDuration > av.duration {
|
||||||
av.duration = newDuration
|
av.duration = newDuration
|
||||||
}
|
}
|
||||||
|
|
@ -325,6 +323,13 @@ func populateThumbContext(av *AVContext, frames chan *C.AVFrame, n C.int, done <
|
||||||
incrementDuration(av, frame, i)
|
incrementDuration(av, frame, i)
|
||||||
frames <- frame
|
frames <- frame
|
||||||
frame = nil
|
frame = nil
|
||||||
|
if av.selectedDuration > 0 {
|
||||||
|
if av.availableDuration <= av.selectedDuration {
|
||||||
|
av.selectedIndex = i
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if av.selectedIndex > av.availableIndex {
|
if av.selectedIndex > av.availableIndex {
|
||||||
av.selectedIndex = av.availableIndex
|
av.selectedIndex = av.availableIndex
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ func TestAVContext(t *testing.T) {
|
||||||
if n == 10 {
|
if n == 10 {
|
||||||
require.NoError(t, av.ProcessFrames(n))
|
require.NoError(t, av.ProcessFrames(n))
|
||||||
} else if n == 99999 {
|
} else if n == 99999 {
|
||||||
require.NoError(t, av.SelectDuration(time.Millisecond*500))
|
require.NoError(t, av.SelectDuration(time.Second))
|
||||||
} else if n == 9999 {
|
} else if n == 9999 {
|
||||||
require.NoError(t, av.SelectPosition(0.7))
|
require.NoError(t, av.SelectPosition(0.7))
|
||||||
} else if n > -1 {
|
} else if n > -1 {
|
||||||
|
|
|
||||||
BIN
testdata/golden/export/alpha-webm.webm-99999.jpg
vendored
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 22 KiB |
BIN
testdata/golden/export/macabre.mp4-99999.jpg
vendored
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
BIN
testdata/golden/export/schizo.flv-99999.jpg
vendored
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
BIN
testdata/golden/export/schizo_0.mp4-99999.jpg
vendored
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
BIN
testdata/golden/export/schizo_180.mp4-99999.jpg
vendored
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
BIN
testdata/golden/export/schizo_270.mp4-99999.jpg
vendored
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
BIN
testdata/golden/export/schizo_90.mp4-99999.jpg
vendored
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
|
@ -1 +1 @@
|
||||||
{"orientation":1,"duration":12040,"width":720,"height":576,"fps":10.9,"has_video":true,"has_audio":false}
|
{"orientation":1,"duration":12040,"width":720,"height":576,"fps":9.8,"has_video":true,"has_audio":false}
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"orientation":1,"duration":7407,"width":640,"height":480,"fps":9.3,"has_video":true,"has_audio":true}
|
{"orientation":1,"duration":7407,"width":640,"height":480,"fps":1.2,"has_video":true,"has_audio":true}
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"orientation":1,"duration":7407,"width":640,"height":480,"fps":26.3,"has_video":true,"has_audio":true}
|
{"orientation":1,"duration":7407,"width":640,"height":480,"fps":16,"has_video":true,"has_audio":true}
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"orientation":1,"duration":2560,"width":480,"height":360,"fps":29.7,"has_video":true,"has_audio":true}
|
{"orientation":1,"duration":2560,"width":480,"height":360,"fps":29.6,"has_video":true,"has_audio":true}
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"orientation":1,"duration":2560,"width":480,"height":360,"fps":29.7,"has_video":true,"has_audio":true}
|
{"orientation":1,"duration":2560,"width":480,"height":360,"fps":29.3,"has_video":true,"has_audio":true}
|
||||||