public void SaveAvi(string input_wav_filename, string output_avi_filename, double start_time, double end_time, int dest_width, int dest_height, bool is_compress, RunningDelegate dlg) { int f_rate = frame_rate_ / 256; VfwAviWriter avi_writer = new VfwAviWriter(output_avi_filename, frame_rate_ / 256, 1); bool is_success = false; try { int start_frame = (start_time >= 0.0 ? (int)(start_time * f_rate) : 0); int end_frame = (end_time >= 0.0 ? (int)(Math.Ceiling(end_time * f_rate)) : frame_count_) - 1; if (end_frame >= frame_count_) { end_frame = frame_count_ - 1; } for (int i = start_frame; i <= end_frame; ++i) { Bitmap bitmap = GetFrame(i, dest_width, dest_height); avi_writer.AddFrame(bitmap); bitmap.Dispose(); } if (input_wav_filename != "") { avi_writer.AddWave(input_wav_filename); } is_success = true; } finally { avi_writer.Close(); if (!is_success) { if (File.Exists(output_avi_filename)) { try { File.Delete(output_avi_filename); } catch (Exception) { } } } } }