refactor(ffmpeg): skip histogram if frame selected
* use availableIndex * refactor(ffmpeg): skip histogram if frame selected
This commit is contained in:
parent
da15744b3d
commit
17b50dea3c
3 changed files with 21 additions and 8 deletions
|
|
@ -351,6 +351,10 @@ static double root_mean_square_error(const int *hist, const double *median, size
|
||||||
return sum_sq_err;
|
return sum_sq_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void populate_frame(ThumbContext *thumb_ctx, int n, AVFrame *frame) {
|
||||||
|
thumb_ctx->frames[n].frame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
void populate_histogram(ThumbContext *thumb_ctx, int n, AVFrame *frame) {
|
void populate_histogram(ThumbContext *thumb_ctx, int n, AVFrame *frame) {
|
||||||
const AVPixFmtDescriptor *desc = thumb_ctx->desc;
|
const AVPixFmtDescriptor *desc = thumb_ctx->desc;
|
||||||
thumb_ctx->frames[n].frame = frame;
|
thumb_ctx->frames[n].frame = frame;
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,8 @@ func (av *AVContext) ProcessFrames(maxFrames int) (err error) {
|
||||||
|
|
||||||
func (av *AVContext) SelectFrame(n int) (err error) {
|
func (av *AVContext) SelectFrame(n int) (err error) {
|
||||||
nn := C.int(n)
|
nn := C.int(n)
|
||||||
if av.thumbContext != nil && nn >= av.thumbContext.n {
|
if av.thumbContext != nil && nn > av.availableIndex {
|
||||||
nn = av.thumbContext.n - 1
|
nn = av.availableIndex
|
||||||
}
|
}
|
||||||
av.selectedIndex = nn
|
av.selectedIndex = nn
|
||||||
if err = av.ProcessFrames(-1); err != nil {
|
if err = av.ProcessFrames(-1); err != nil {
|
||||||
|
|
@ -233,16 +233,23 @@ func incrementDuration(av *AVContext, frame *C.AVFrame, i C.int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateHistogram(av *AVContext, frames <-chan *C.AVFrame) <-chan struct{} {
|
func populateFrames(av *AVContext, frames <-chan *C.AVFrame) <-chan struct{} {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
var isSelected = av.selectedIndex > -1
|
||||||
go func() {
|
go func() {
|
||||||
var n C.int
|
var n C.int
|
||||||
for frame := range frames {
|
if !isSelected {
|
||||||
C.populate_histogram(av.thumbContext, n, frame)
|
for frame := range frames {
|
||||||
n++
|
C.populate_histogram(av.thumbContext, n, frame)
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for frame := range frames {
|
||||||
|
C.populate_frame(av.thumbContext, n, frame)
|
||||||
|
n++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
av.thumbContext.n = n
|
av.thumbContext.n = n
|
||||||
done <- struct{}{}
|
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
return done
|
return done
|
||||||
|
|
@ -276,7 +283,7 @@ func createThumbContext(av *AVContext, maxFrames C.int) error {
|
||||||
n = av.selectedIndex + 1
|
n = av.selectedIndex + 1
|
||||||
}
|
}
|
||||||
frames := make(chan *C.AVFrame, n)
|
frames := make(chan *C.AVFrame, n)
|
||||||
done := populateHistogram(av, frames)
|
done := populateFrames(av, frames)
|
||||||
frames <- frame
|
frames <- frame
|
||||||
if pkt.buf != nil {
|
if pkt.buf != nil {
|
||||||
C.av_packet_unref(&pkt)
|
C.av_packet_unref(&pkt)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ int find_best_frame_index(ThumbContext *thumb_ctx);
|
||||||
|
|
||||||
AVFrame *select_frame(ThumbContext *thumb_ctx, int i);
|
AVFrame *select_frame(ThumbContext *thumb_ctx, int i);
|
||||||
|
|
||||||
|
void populate_frame(ThumbContext *thumb_ctx, int n, AVFrame *frame);
|
||||||
|
|
||||||
void populate_histogram(ThumbContext *thumb_ctx, int n, AVFrame *frame);
|
void populate_histogram(ThumbContext *thumb_ctx, int n, AVFrame *frame);
|
||||||
|
|
||||||
extern int goPacketRead(void *opaque, uint8_t *buf, int buf_size);
|
extern int goPacketRead(void *opaque, uint8_t *buf, int buf_size);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue