Skip to content

Commit f09abc0

Browse files
committed
fix: video normal speed uniform sample & check videoInfo valid
1 parent d5b832d commit f09abc0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tools/mtmd/mtmd-video.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ static bool decode_video_ffmpeg_to_rgba(const std::string & file,
191191
std::vector<DecodedFrameRGBA> & frames,
192192
int max_frames,
193193
int stride) {
194+
if(stride <= 0 || max_frames <= 0) return false;
194195
AVFormatContext * fmt = nullptr;
195196
if (avformat_open_input(&fmt, file.c_str(), nullptr, nullptr) < 0) return false;
196197
std::unique_ptr<AVFormatContext, void(*)(AVFormatContext*)> fmt_guard(fmt, [](AVFormatContext *f){ if (f) avformat_close_input(&f); });
@@ -219,7 +220,7 @@ static bool decode_video_ffmpeg_to_rgba(const std::string & file,
219220
if (avcodec_send_packet(ctx, pkt) < 0) { av_packet_unref(pkt); break; }
220221
av_packet_unref(pkt);
221222
while (avcodec_receive_frame(ctx, frame) == 0) {
222-
if (stride > 1 && (idx++ % stride != 0)) continue;
223+
if (idx++ % stride != stride/2) continue;
223224
if (!sws) {
224225
sws = sws_getContext(frame->width, frame->height, (AVPixelFormat)frame->format,
225226
frame->width, frame->height, AV_PIX_FMT_RGBA,
@@ -235,9 +236,9 @@ static bool decode_video_ffmpeg_to_rgba(const std::string & file,
235236
sws_scale(sws, frame->data, frame->linesize, 0, frame->height, dst_data, dst_linesize);
236237
frames.push_back(std::move(out));
237238
taken++;
238-
if (max_frames > 0 && taken >= max_frames) break;
239+
if (taken >= max_frames) break;
239240
}
240-
if (max_frames > 0 && taken >= max_frames) break;
241+
if (taken >= max_frames) break;
241242
}
242243
if (sws) sws_freeContext(sws);
243244
return taken > 0;
@@ -298,7 +299,9 @@ size_t append_frames_from_path(mtmd_context * ctx,
298299
list_files(path, files, opts.recursive);
299300
info.total_frames = files.size();
300301
} else {
301-
mtmd_video::get_video_info_ffmpeg(path, info);
302+
if(!mtmd_video::get_video_info_ffmpeg(path, info)) {
303+
return 0;
304+
}
302305
}
303306

304307
// minicpm normal speed

0 commit comments

Comments
 (0)