I have a video file and want to generate 10 different thumbnails for the whole video. I use video_thumbnail
package and VideoThumbnail.fromFile()
constructor. This constructor has an argument called timeMs
and is for, as the documentation states: generates the thumbnail from the frame around the specified millisecond
. My code is as follows:
List<String> recordingThumbnailsPaths =
List<String>.generate(10, (int index) => '');
Future<void> getRecordingThumbnailsPaths() async {
final int totalMilliSecs =
(await FlutterVideoInfo().getVideoInfo(videoFile!.path))!
.duration!
.toInt();
// For debug purpose
print('Total (ms): $totalMilliSecs');
for (int i = 0; i < 10; i++) {
int ms = totalMilliSecs ~/ 10 * i;
recordingThumbnailsPaths[i] = (await VideoThumbnail.thumbnailFile(
video: videoFile!.path, timeMs: ms))!;
// For debug purpose
print('Iteration $i\nCurrent (ms): $ms');
}
}
And here is the log output for each iteration:
Total (ms): 17480
Iteration 0
Current (ms): 0
Iteration 1
Current (ms): 1748
Iteration 2
Current (ms): 3496
Iteration 3
Current (ms): 5244
...
Iteration 9
Current (ms): 15732
But it generates the same first thumbnail for each time frame. So what is the solution? Thanks in advance for your help!